Swift Selena is an MCP (Model Context Protocol) server that provides Swift code analysis capabilities to Claude AI. It works even with build errors and strongly supports SwiftUI app development.
- Build-Free: Works even with build errors through SwiftSyntax-based static analysis
- LSP Integration: Enhances supported tools with SourceKit-LSP when available; SwiftSyntax remains the fallback
- Meta Tool Mode: Reduces context window usage with dynamic tool loading (v0.6.3+)
- Swift Testing Support: Detects both XCTest and Swift Testing (@Test, @Suite) test cases
- SwiftUI Support: Automatically detects Property Wrappers (@State, @Binding, etc.)
- Fast Search: Filesystem-based search for fast performance even on large projects
- Smart Caching: Caches analysis results for fast repeated queries
- Multi-Client Support: Use with Claude Code and Claude Desktop simultaneously
Swift-Selena uses a Meta Tool Mode that exposes only 4 tools to Claude, reducing context window usage. The actual analysis tools are loaded dynamically on demand.
Exposed Tools:
initialize_project- Initialize a project (must be called first)list_available_tools- List all available analysis tools with descriptionsget_tool_schema- Get the JSON schema for a specific toolexecute_tool- Execute any analysis tool by name
find_files- Search files by wildcard pattern (e.g.,*ViewModel.swift)search_code- Search code content using regex; supportsoutput_mode,limit,include_patterns, andexclude_patternssearch_files_without_pattern- Search files WITHOUT a pattern (grep -L equivalent); supportsinclude_patternsandexclude_patterns
list_symbols- List all symbols (Class, Struct, Function, etc.)find_symbol_definition- Find symbol definitions across the project; supportssymbol_kindsand scope information
list_property_wrappers- Detect SwiftUI Property Wrappers (@State, @Binding, etc.)list_protocol_conformances- Analyze protocol conformances and inheritance (UITableViewDelegate, ObservableObject, etc.)list_extensions- Analyze extensions (extended type, protocol conformance, members)
analyze_imports- Analyze import dependencies across the project (module usage statistics, cached)get_type_hierarchy- Get type inheritance hierarchy (superclass, subclasses, conforming types, cached)find_test_cases- Detect XCTest and Swift Testing (@Test, @Suite) test cases
search_codeoutput modes arematch_detail(default),file_list, andcount_onlysearch_codeacceptslimitfrom 1 to 10,000; values above 10,000 are clamped and reportedsearch_codeandsearch_files_without_patternuseinclude_patterns/exclude_patterns; the oldfile_patternparameter is intentionally removed and ignored if passedfind_symbol_definitionacceptssymbol_kinds:struct,class,enum,protocol,actor,function,variable,typealias,extensionsearch_codeandfind_symbol_definitionappend a--- structured ---JSON block after the human-readable text output- LSP enhancement is best-effort. Xcode project directories containing
.xcodeprojcurrently disable LSP, and SwiftSyntax analysis is used instead
- macOS 13.0 or later
- Swift 5.9 or later
- Claude Desktop or Claude Code
Tap and install (the explicit-URL brew tap form lets this repository serve as a tap directly — no separate homebrew-* repository is required):
brew tap blueeventhorizon/swift-selena https://github.com/BlueEventHorizon/Swift-Selena
brew install blueeventhorizon/swift-selena/swift-selena
# After tap, the short form also works:
# brew install swift-selenaAfter brew install, the swift-selena binary is on your PATH (typically $(brew --prefix)/bin/swift-selena).
Swift toolchain requirement: Building requires Swift 5.9+ on macOS 13.0+. Verified with full Xcode 15+ providing Swift 5.9+. The Command Line Tools-only path is plausible but was not verified at the time of this release; if you have only CLT installed and
brew installfails, install Xcode 15+ as a workaround.
The binary is on PATH, so no absolute path is required:
claude mcp add -s user swift-selena -- swift-selenaClaude Desktop is launched from the GUI and does not always inherit the interactive shell PATH. Use the absolute path returned by brew --prefix:
# Find the install prefix (typical: /opt/homebrew on Apple Silicon, /usr/local on Intel)
brew --prefixEdit ~/Library/Application Support/Claude/claude_desktop_config.json and paste the actual path (not a shell expression — JSON is not shell-expanded):
{
"mcpServers": {
"swift-selena": {
"command": "/opt/homebrew/bin/swift-selena",
"env": { "MCP_CLIENT_ID": "claude-desktop" }
}
}
}
⚠️ Do not write$(brew --prefix)literally inside the JSON — JSON is not shell-expanded. Runbrew --prefixfirst and paste the resulting absolute path.
Restart Claude Desktop after editing.
# Clone the repository
git clone https://github.com/BlueEventHorizon/Swift-Selena.git
cd Swift-Selena
# Build (release mode for production)
make build-release
# Or using swift directly:
# swift build -c release -Xswiftc -OsizeThe build artifact is generated at .build/release/Swift-Selena.
make help # Show all available commands| Command | Description |
|---|---|
make build |
Build debug version |
make build-release |
Build release version |
make clean |
Clean build artifacts |
| Command | Target | Description |
|---|---|---|
make connect_gemini |
Claude Code | Connect gemini-cli MCP server |
make disconnect_gemini |
Claude Code | Disconnect gemini-cli MCP server |
| Command | Target | Description |
|---|---|---|
make register-release |
Claude Code | Register RELEASE version (prompts for project path) |
make unregister-release |
Claude Code | Unregister RELEASE version (prompts for project path) |
make register-debug |
Claude Code | Build & register DEBUG version to Swift-Selena project |
make unregister-debug |
Claude Code | Unregister DEBUG version from Swift-Selena project |
make register-desktop |
Claude Desktop | Register to Claude Desktop |
make unregister-desktop |
Claude Desktop | Unregister from Claude Desktop |
Swift-Selena outputs logs to a file for debugging and troubleshooting:
Log file location:
~/.swift-selena/logs/server.log
Monitor logs in real-time:
tail -f ~/.swift-selena/logs/server.logWhat you can see:
- Server startup messages
- Tool execution logs
- LSP connection status (success/failure)
- Error messages and diagnostics
Example log output:
[17:29:24] ℹ️ [info] Starting Swift MCP Server...
[17:29:50] ℹ️ [info] Tool called: initialize_project
[17:29:50] ℹ️ [info] Attempting LSP connection...
[17:29:51] ℹ️ [info] ✅ LSP connected successfully
Tip: Keep tail -f running in a separate terminal while using Swift-Selena for real-time debugging.
Use make commands from the Swift-Selena project root:
make register-desktop# For production use (register to target project)
make register-release
# → Prompts: Enter the target project path
# For development/testing (register to Swift-Selena project itself)
make register-debug# Unregister from Claude Desktop
make unregister-desktop
# Unregister from target project
make unregister-release
# → Prompts: Enter the target project path (leave blank for current directory)
# Unregister debug version from this project
make unregister-debugIf you prefer manual configuration:
- Open the config file (create if it doesn't exist):
open ~/Library/Application\ Support/Claude/claude_desktop_config.json- Add the following content:
{
"mcpServers": {
"swift-selena": {
"command": "/path/to/Swift-Selena/.build/release/Swift-Selena",
"env": {
"MCP_CLIENT_ID": "claude-desktop"
}
}
},
"isUsingBuiltInNodeForMcp": true
}Important: Replace /path/to/Swift-Selena with the actual path.
- Restart Claude Desktop
In your target project directory:
cd /path/to/your/project
claude mcp add swift-selena -- /path/to/Swift-Selena/.build/release/Swift-SelenaThis creates a local configuration for that project only.
To use globally (all projects):
cd ~
claude mcp add -s user swift-selena -- /path/to/Swift-Selena/.build/release/Swift-SelenaRefer to Claude Code documentation for more MCP server configuration options.
- Initialize project
Ask Claude: "Analyze this Swift project"
→ initialize_project is automatically executed
- Search and analyze code
"Find ViewModels"
→ find_files searches for *ViewModel.swift
"Which files use @State?"
→ list_property_wrappers detects them
- Analyze code structure
"Show me the type hierarchy for ViewController"
→ get_type_hierarchy displays inheritance
You: Tell me what Property Wrappers are used in ContentView.swift
Claude: Executes list_property_wrappers
Result:
[@State] counter: Int (line 12)
[@ObservedObject] viewModel: ViewModel (line 13)
[@EnvironmentObject] appState: AppState (line 14)
You: Find where the fetchData function is defined
Claude: Executes find_symbol_definition
Result:
[Function] fetchData
File: /path/to/NetworkManager.swift
Line: 45
You: Tell me what protocols ViewController conforms to
Claude: Executes list_protocol_conformances
Result:
[Class] ViewController (line 25)
Inherits from: UIViewController
Conforms to: UITableViewDelegate, UITableViewDataSource
You: Find all do-catch blocks
Claude: Executes search_code (regex: do\s*\{)
Result: Found 15 do-catch blocks
Claude: Executes search_code
Params:
{
"pattern": "URLSession\\.shared",
"output_mode": "file_list",
"include_patterns": ["Sources/**/*.swift"],
"exclude_patterns": ["*Tests*"],
"limit": 100
}
Claude: Executes find_symbol_definition
Params:
{
"symbol_name": "Button",
"symbol_kinds": ["struct", "class"]
}
Result includes Scope lines and a structured JSON block.
Analysis cache is stored in the following directory:
~/.swift-selena/
└── clients/
├── default/ # Claude Code (default)
│ └── projects/
│ └── YourProject-abc12345/
│ └── memory.json
└── claude-desktop/ # Claude Desktop
└── projects/
└── YourProject-abc12345/
└── memory.json
- Projects are identified by SHA256 hash of project path
- Different projects are automatically separated
- Claude Code (
default) and Claude Desktop (claude-desktop) data is automatically separated byMCP_CLIENT_ID
Note: When the same MCP_CLIENT_ID (e.g., multiple Claude Code windows) opens the same project simultaneously, memory file write conflicts may occur. If working on the same project in multiple windows, set different MCP_CLIENT_ID values.
# Verify debug build
swift build
# Or verify release build
swift build -c release -Xswiftc -Osize
# Test release executable
.build/release/Swift-Selena
# "Starting Swift MCP Server..." should appear
# Press Ctrl+C to exit- Restart Claude Desktop/Code
- Verify config file paths are correct
- Check logs:
tail -f ~/Library/Logs/Claude/mcp*.logrm -rf ~/.swift-selena/Will be rebuilt on next initialize_project execution.
By default, Swift-Selena uses Meta Tool Mode (v0.6.3+). If you prefer to have 12 tools exposed directly without meta tool indirection, set the SWIFT_SELENA_LEGACY=1 environment variable:
{
"mcpServers": {
"swift-selena": {
"command": "/path/to/Swift-Selena/.build/release/Swift-Selena",
"env": {
"MCP_CLIENT_ID": "claude-desktop",
"SWIFT_SELENA_LEGACY": "1"
}
}
}
}claude mcp add swift-selena -e SWIFT_SELENA_LEGACY=1 -- /path/to/Swift-Selena/.build/release/Swift-SelenaIn legacy mode, the following 12 tools are exposed directly:
initialize_project, find_files, search_code, search_files_without_pattern, list_symbols, find_symbol_definition, list_property_wrappers, list_protocol_conformances, list_extensions, analyze_imports, get_type_hierarchy, find_test_cases
- FileSearcher: Fast filesystem-based search
- SwiftSyntaxAnalyzer: Symbol extraction via AST analysis
- ProjectMemory: Persists analysis results and manages cache
- MCP Swift SDK (0.12.0) - MCP protocol implementation
- SwiftSyntax (602.0.0) - Syntax parsing
- CryptoKit - Project path hashing
- swift-log (via MCP Swift SDK) - Logging
Issues and Pull Requests are welcome!
MIT License - See LICENSE file for details
- Model Context Protocol - MCP protocol specification
- SwiftSyntax - Swift syntax parsing library
- Anthropic - Claude AI
