Skip to content
Back to search

swiftlens

SwiftLens is a Model Context Protocol (MCP) server that provides deep, semantic-level analysis of Swift codebases to any AI models. By integrating directly with Apple's SourceKit-LSP, SwiftLens enables AI models to understand Swift code with compiler-grade accuracy.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/swiftlens--swiftlens/badge.svg)](/listings/swiftlens--swiftlens)

HTML

<a href="/listings/swiftlens--swiftlens"><img src="/api/listings/swiftlens--swiftlens/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

Configure for Claude Code / Gemini CLI

Add to your json configuration file mcpServers section:

{
  "mcpServers": {
    "swiftlens": {
      "command": "uvx",
      "args": ["swiftlens"]
    }
  }
}

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 235 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. [![MseeP.ai Security Assessment Badge](https://mseep.net/pr/swiftlens-swiftlens-badge.png)](https://mseep.ai/app/swiftlens-swiftlens)
  2. # SwiftLens: First MCP Server that provides Semantic-Lelvel Analysis for iOS/Swift Development
  3. **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.
  4. ## Features
  5. SwiftLens bridges AI models and Swift development through:
  6. ```
  7. AI Agent (Claude/GPT) → MCP Protocol → SwiftLens → SourceKit-LSP → Swift Code
  8. ```
  9. ### Core Capabilities
  10. - **LSP-Powered Semantic Analysis**: Leverages SourceKit-LSP for Xcode-grade accuracy
  11. - **Token-Optimized Output**: Minimizes token usage for AI interactions
  12. - **Real-time Code Understanding**: Analyzes Swift files with full language feature support
  13. - **Cross-file Navigation**: Symbol references, definitions, and project-wide analysis
  14. - **Code Modification Tools**: Safe, atomic file operations for AI-driven refactoring
  15. - **Zero Configuration**: Works out-of-the-box with standard Swift projects
  16. ### Supported Swift Features
  17. - Modern Swift syntax (actors, async/await, property wrappers, result builders)
  18. - Generic types and protocols
  19. - Swift Package Manager and Xcode projects
  20. - Unicode identifiers and symbols
  21. - Complex nested types and extensions
  22. ## Installation
  23. ### Prerequisites
  24. - **macOS** (required for SourceKit-LSP)
  25. - **Python 3.10+**
  26. - **Xcode** (full installation from App Store, not just Command Line Tools)
  27. ## Quick Start
  28. ### Configure for Claude Code / Gemini CLI
  29. Add to your json configuration file mcpServers section:
  30. ```json
  31. {
  32. "mcpServers": {
  33. "swiftlens": {
  34. "command": "uvx",
  35. "args": ["swiftlens"]
  36. }
  37. }
  38. }
  39. ```
  40. ## SourceKit LSP Index
  41. SwiftLens will need proper sourcekit-lsp index in order to work properly you can either
  42. ### Ask AI to build your index
  43. ```bash
  44. "hey claude, run swift_build_index tool"
  45. ```
  46. ### Building Your Project Index Manually
  47. SwiftLens requires an index store for cross-file analysis. Build it with:
  48. ```bash
  49. # Navigate to your Swift project
  50. cd /path/to/your/swift/project
  51. # Build with index store
  52. swift build -Xswiftc -index-store-path -Xswiftc .build/index/store
  53. ```
  54. **Important**: Rebuilding of the index is required when you:
  55. - Add new Swift files
  56. - Change public interfaces
  57. - Notice missing symbol references
  58. ### Available Tools
  59. SwiftLens provides 15 tools for Swift code analysis:
  60. #### Single-File Analysis (No Index Required)
  61. - `swift_analyze_file` - Analyze structure and symbols in a Swift file
  62. - `swift_analyze_multiple_files` - Batch analyze multiple files
  63. - `swift_summarize_file` - Get symbol counts and file summary
  64. - `swift_get_symbols_overview` - Extract top-level type declarations
  65. - `swift_get_declaration_context` - Get fully-qualified symbol paths
  66. - `swift_get_file_imports` - Extract import statements
  67. - `swift_validate_file` - Validate syntax and types with swiftc
  68. - `swift_check_environment` - Verify Swift development setup
  69. - `swift_build_index` - Build index store db of current project for sourcekit-lsp
  70. #### Cross-File Analysis (Requires Index)
  71. - `swift_find_symbol_references` - Find all references to a symbol
  72. - `swift_get_symbol_definition` - Jump to symbol definition
  73. - `swift_get_hover_info` - Get type info and documentation
  74. #### Code Modification
  75. - `swift_replace_symbol_body` - Replace function/type body
  76. #### Utilities
  77. - `swift_search_pattern` - Search with regex patterns
  78. - `get_tool_help` - Get help for any tool
  79. ### Example Usage
  80. Ask your AI agent:
  81. ```
  82. "Analyze the UserManager.swift file and find all references to the login() method"
  83. ```
  84. The AI will use SwiftLens tools to:
  85. 1. Analyze the file structure
  86. 2. Locate the login method
  87. 3. Find all project-wide references
  88. 4. Provide insights based on the analysis
  89. ## Real-time Dashboard (CURRENT NOT WORKING, REWORK IMPLEMENTATION PLANNED)
  90. SwiftLens includes a web dashboard for monitoring AI interactions:
  91. - **URL**: http://localhost:53729 (when server is running)
  92. - **Features**: Live tool execution logs, usage analytics, session tracking
  93. - **Security**: Localhost-only access, no external connections
  94. ## Troubleshooting
  95. ### "Symbol not found" or "No references found"
  96. Rebuild your index:
  97. ```bash
  98. swift build -Xswiftc -index-store-path -Xswiftc .build/index/store
  99. ```
  100. ### New files not recognized
  101. New files need to be indexed:
  102. ```bash
  103. swift build -Xswiftc -index-store-path -Xswiftc .build/index/store
  104. ```
  105. ### SourceKit-LSP not found
  106. Ensure Xcode is properly installed:
  107. ```bash
  108. xcode-select -p # Should show Xcode path
  109. xcrun sourcekit-lsp --help # Should show help text
  110. ```
  111. ## SourceKit-LSP Limitations
  112. ### Known SourceKit-LSP Limitations
  113. The SwiftLens MCP Server accurately reflects SourceKit-LSP's capabilities. The following are known limitations of SourceKit-LSP itself, not bugs in this tool:
  114. #### Hover Information
  115. - **Limited support for local variables**: Hover info may not be available for local variables within function bodies
  116. - **Property access issues**: Expressions like `object.property` often don't provide hover information when inside functions
  117. - **Method call limitations**: Hover on method calls with parameters may return incorrect or no information
  118. - **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
  119. These limitations exist because SourceKit-LSP:
  120. - Does not perform background indexing
  121. - May skip function body analysis in certain configurations
  122. - Is still in early development with acknowledged "rough edges"
  123. For the most up-to-date status, see the [SourceKit-LSP repository](https://github.com/swiftlang/sourcekit-lsp).
  124. ## Development
  125. ### Running Tests
  126. ```bash
  127. # All tests
  128. make test
  129. # Unit tests only (fast, no LSP required)
  130. make test-unit
  131. # LSP integration tests
  132. make test-lsp
  133. # Check environment
  134. make check-env
  135. ```
  136. ### Code Quality
  137. ```bash
  138. # Format code
  139. ./format.sh
  140. # Check formatting
  141. ./format.sh check
  142. ```
  143. ## License - FULLY AVAILABLE TO YOU FOR FREE (PERSONAL USE ONLY UNDER LICENSE)
  144. - ✅ Free for personal use and evaluation
  145. - ⚠️ Commercial use requires a license
  146. See [LICENSE.md](./LICENSE.md) for details.
  147. ## Contributing
  148. We welcome contributions! Areas where you can help:
  149. - 🐛 Bug reports and fixes
  150. - 📝 Documentation improvements
  151. - 🧪 Test coverage expansion
  152. - 🔧 New analysis capabilities
  153. ## Support
  154. - **Issues**: [GitHub Issues](https://github.com/swiftlens/swiftlens/issues)
  155. ---
  156. SwiftLens - Bringing compiler-grade Swift understanding to AI development

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.