swiftlens
by swiftlens·★ 124·综合分 44
SwiftLens MCP 服务器通过 SourceKit-LSP 集成,让 AI 模型能以编译器级精度理解 Swift 代码库。
概述
SwiftLens 是一个专为 iOS/Swift 开发设计的专业 MCP 服务器。它通过直接集成 Apple 的 SourceKit-LSP,为 AI 代理和 Swift 代码库提供语义级分析,具有 Xcode 级别的精度。服务器提供 15 种不同的工具用于单文件和跨文件分析、符号导航和代码修改功能。它提供令牌优化的输出,以实现高效的 AI 交互,并能与标准 Swift 项目开箱即用,但需要索引存储进行跨文件分析。
试试问 AI
装完之后,这里有 3 个你可以让 AI 做的事:
什么时候选它
当您使用Swift代码库并需要AI辅助进行代码分析、重构或文档生成,且需要编译器级精度时,选择SwiftLens。
什么时候不要选它
如果不使用Swift或macOS,请避免使用,因为SourceKit-LSP集成完全需要Apple的开发工具。
此 server 暴露的工具
从 README 抽取出 12 个工具swift_analyze_fileAnalyze structure and symbols in a Swift file
swift_analyze_multiple_filesBatch analyze multiple Swift files
swift_summarize_fileGet symbol counts and file summary
swift_get_symbols_overviewExtract top-level type declarations
swift_get_declaration_contextGet fully-qualified symbol paths
swift_get_file_importsExtract import statements
swift_validate_fileValidate syntax and types with swiftc
swift_check_environmentVerify Swift development setup
swift_build_indexBuild index store for current project
swift_find_symbol_referencesFind all references to a symbol
swift_get_symbol_definitionJump to symbol definition
swift_get_hover_infoGet type info and documentation
可对比工具
安装
安装
前置条件
- macOS(SourceKit-LSP 需要)
- Python 3.10+
- Xcode(从 App Store 完整安装)
快速开始
为 Claude Code / Gemini CLI 配置
添加到您的 JSON 配置文件的 mcpServers 部分:
{
"mcpServers": {
"swiftlens": {
"command": "uvx",
"args": ["swiftlens"]
}
}
}构建 SourceKit LSP 索引
SwiftLens 需要索引存储进行跨文件分析。使用以下命令构建:
# 导航到您的 Swift 项目
cd /path/to/your/swift/project
# 使用索引构建
swift build -Xswiftc -index-store-path -Xswiftc .build/index/store**重要**:当您添加新的 Swift 文件、更改公共接口或发现缺少符号引用时,需要重新构建索引。
swiftlens 对比
最后更新于 · 由 README + GitHub 公开数据自动生成。