SwiftLens
MCP server that provides semantic-level analysis of Swift codebases to AI agents by integrating with Apple's SourceKit-LSP, enabling compiler-grade code understanding and cross-file navigation.
README
SwiftLens: First MCP Server that provides Semantic-Lelvel Analysis for iOS/Swift Development
SwiftLens is a Model Context Protocol (MCP) server that provides deep, semantic-level analysis of Swift codebases to AI agents. By integrating directly with Apple's SourceKit-LSP, SwiftLens enables AI models to understand Swift code with compiler-grade accuracy.
Features
SwiftLens bridges AI models and Swift development through:
AI Agent (Claude/GPT) → MCP Protocol → SwiftLens → SourceKit-LSP → Swift Code
Core Capabilities
- LSP-Powered Semantic Analysis: Leverages SourceKit-LSP for Xcode-grade accuracy
- Token-Optimized Output: Minimizes token usage for AI interactions
- Real-time Code Understanding: Analyzes Swift files with full language feature support
- Cross-file Navigation: Symbol references, definitions, and project-wide analysis
- Code Modification Tools: Safe, atomic file operations for AI-driven refactoring
- Zero Configuration: Works out-of-the-box with standard Swift projects
Supported Swift Features
- Modern Swift syntax (actors, async/await, property wrappers, result builders)
- Generic types and protocols
- Swift Package Manager and Xcode projects
- Unicode identifiers and symbols
- Complex nested types and extensions
Installation
Prerequisites
- macOS (required for SourceKit-LSP)
- Python 3.10+
- Xcode (full installation from App Store, not just Command Line Tools)
Quick Start
Configure for Claude Code / Gemini CLI
Add to your json configuration file mcpServers section:
{
"mcpServers": {
"swiftlens": {
"command": "uvx",
"args": ["swiftlens"]
}
}
}
SourceKit LSP Index
SwiftLens will need proper sourcekit-lsp index in order to work properly you can either
Ask AI to build your index
"hey claude, run swift_build_index tool"
Building Your Project Index Manually
SwiftLens requires an index store for cross-file analysis. Build it with:
# Navigate to your Swift project
cd /path/to/your/swift/project
# Build with index store
swift build -Xswiftc -index-store-path -Xswiftc .build/index/store
Important: Rebuilding of the index is required when you:
- Add new Swift files
- Change public interfaces
- Notice missing symbol references
Available Tools
SwiftLens provides 15 tools for Swift code analysis:
Single-File Analysis (No Index Required)
swift_analyze_file- Analyze structure and symbols in a Swift fileswift_analyze_multiple_files- Batch analyze multiple filesswift_summarize_file- Get symbol counts and file summaryswift_get_symbols_overview- Extract top-level type declarationsswift_get_declaration_context- Get fully-qualified symbol pathsswift_get_file_imports- Extract import statementsswift_validate_file- Validate syntax and types with swiftcswift_check_environment- Verify Swift development setupswift_build_index- Build index store db of current project for sourcekit-lsp
Cross-File Analysis (Requires Index)
swift_find_symbol_references- Find all references to a symbolswift_get_symbol_definition- Jump to symbol definitionswift_get_hover_info- Get type info and documentation
Code Modification
swift_replace_symbol_body- Replace function/type body
Utilities
swift_search_pattern- Search with regex patternsget_tool_help- Get help for any tool
Example Usage
Ask your AI agent:
"Analyze the UserManager.swift file and find all references to the login() method"
The AI will use SwiftLens tools to:
- Analyze the file structure
- Locate the login method
- Find all project-wide references
- Provide insights based on the analysis
Real-time Dashboard (CURRENT NOT WORKING, REWORK IMPLEMENTATION PLANNED)
SwiftLens includes a web dashboard for monitoring AI interactions:
- URL: http://localhost:53729 (when server is running)
- Features: Live tool execution logs, usage analytics, session tracking
- Security: Localhost-only access, no external connections
Troubleshooting
"Symbol not found" or "No references found"
Rebuild your index:
swift build -Xswiftc -index-store-path -Xswiftc .build/index/store
New files not recognized
New files need to be indexed:
swift build -Xswiftc -index-store-path -Xswiftc .build/index/store
SourceKit-LSP not found
Ensure Xcode is properly installed:
xcode-select -p # Should show Xcode path
xcrun sourcekit-lsp --help # Should show help text
SourceKit-LSP Limitations
Known SourceKit-LSP Limitations
The SwiftLens MCP Server accurately reflects SourceKit-LSP's capabilities. The following are known limitations of SourceKit-LSP itself, not bugs in this tool:
Hover Information
- Limited support for local variables: Hover info may not be available for local variables within function bodies
- Property access issues: Expressions like
object.propertyoften don't provide hover information when inside functions - Method call limitations: Hover on method calls with parameters may return incorrect or no information
- Success rate: Hover typically works well for type declarations, method signatures, and top-level symbols, but has approximately 44% success rate for expressions within function bodies
These limitations exist because SourceKit-LSP:
- Does not perform background indexing
- May skip function body analysis in certain configurations
- Is still in early development with acknowledged "rough edges"
For the most up-to-date status, see the SourceKit-LSP repository.
Development
Running Tests
# All tests
make test
# Unit tests only (fast, no LSP required)
make test-unit
# LSP integration tests
make test-lsp
# Check environment
make check-env
Code Quality
# Format code
./format.sh
# Check formatting
./format.sh check
License - FULLY AVAILABLE TO YOU FOR FREE (PERSONAL USE ONLY UNDER LICENSE)
- ✅ Free for personal use and evaluation
- ⚠️ Commercial use requires a license
See LICENSE.md for details.
Contributing
We welcome contributions! Areas where you can help:
- 🐛 Bug reports and fixes
- 📝 Documentation improvements
- 🧪 Test coverage expansion
- 🔧 New analysis capabilities
Support
- Issues: GitHub Issues
SwiftLens - Bringing compiler-grade Swift understanding to AI development
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。
