An MCP (Model Context Protocol) server that provides Swift code intelligence to AI agents through SourceKit-LSP.
This MCP server exposes SourceKit-LSP functionality to AI agents, enabling them to:
- Navigate Swift code: Find definitions, references, and implementations
- Understand types: Get hover information with type details and documentation
- Search symbols: Find classes, methods, and properties across your project
- Check diagnostics: Access compiler errors and warnings
npm install -g @leftspin/mcp-sourcekit-lsp
npm install -g github:leftspin/mcp-sourcekit-lsp
git clone https://github.com/leftspin/mcp-sourcekit-lsp.git
cd mcp-sourcekit-lsp
npm install
npm run build
# Optional: Set up development notifications (see Development Environment below)
cp .env.example .env
# Edit .env with your notification credentials
Add this to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"sourcekit-lsp": {
"command": "npx",
"args": ["@leftspin/mcp-sourcekit-lsp"],
"env": {
"SOURCEKIT_LSP_PATH": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/sourcekit-lsp"
}
}
}
}
Add this server to Claude Code's MCP settings:
- Open Claude Code settings:
Cmd+,
(macOS) orCtrl+,
(Windows/Linux) - Search for "MCP" or navigate to the MCP section
- Add a new server configuration:
{
"name": "sourcekit-lsp",
"command": "npx",
"args": ["@leftspin/mcp-sourcekit-lsp"],
"env": {
"SOURCEKIT_LSP_PATH": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/sourcekit-lsp"
}
}
Or if installed globally:
{
"name": "sourcekit-lsp",
"command": "mcp-sourcekit-lsp",
"env": {
"SOURCEKIT_LSP_PATH": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/sourcekit-lsp"
}
}
SOURCEKIT_LSP_PATH
(optional): Path to sourcekit-lsp binary. Defaults tosourcekit-lsp
in PATH.SOURCEKIT_BUILD_ARGS
(optional): Additional arguments for sourcekit-lsp (e.g.,-Xswiftc -debug-info-format=dwarf
).
If you're working with Xcode projects, you may need to specify build arguments:
export SOURCEKIT_BUILD_ARGS="-Xswiftc -sdk -Xswiftc /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk"
Find where a symbol is defined.
{
"file": "/path/to/file.swift",
"line": 10,
"column": 5
}
Get type information and documentation for a symbol.
{
"file": "/path/to/file.swift",
"line": 10,
"column": 5
}
Find all references to a symbol.
{
"file": "/path/to/file.swift",
"line": 10,
"column": 5
}
Search for symbols in the workspace.
{
"query": "MyClass"
}
Get compiler diagnostics for a file.
{
"file": "/path/to/file.swift"
}
Provides an overview of the Swift project structure, including all Swift files and their organization.
Shows the current build configuration and compiler settings.
- Node.js 16 or later
- SourceKit-LSP (comes with Xcode or Swift toolchain)
- A Swift project (Swift Package Manager or Xcode project)
# Install dependencies
npm install
# Build TypeScript
npm run build
# Watch mode for development
npm run watch
# Run tests
npm test
# Test with MCP Inspector
npx @modelcontextprotocol/inspector
The project includes a notification system for development updates. To use it:
-
Create environment file:
cp .env.example .env
-
Add your credentials to
.env
:# Pushover credentials for development notifications (optional) PUSHOVER_TOKEN=your_pushover_app_token PUSHOVER_USER=your_pushover_user_key
-
Get Pushover credentials (optional):
- Sign up at pushover.net
- Create an application to get your app token
- Find your user key in your account settings
Note: The .env
file is automatically ignored by git to keep your credentials secure. The notification system is entirely optional and only used for development convenience.
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage
If the server can't find sourcekit-lsp, set the SOURCEKIT_LSP_PATH
environment variable:
Common locations:
- Xcode:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/sourcekit-lsp
- Swift toolchain:
/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/sourcekit-lsp
- Homebrew:
/opt/homebrew/bin/sourcekit-lsp
Check if sourcekit-lsp is available:
which sourcekit-lsp
# Or try running it directly
sourcekit-lsp --help
-
Build your project first: SourceKit-LSP requires compilation information
# For SPM projects swift build # For Xcode projects xcodebuild -project YourProject.xcodeproj -scheme YourScheme build
-
Check file paths: Ensure file paths are absolute and the files exist
-
Verify workspace: Run the MCP server from your project's root directory
- Diagnostics are sent asynchronously by SourceKit-LSP
- Files with no errors/warnings will return empty diagnostics
- Large projects may take longer to analyze
- SourceKit-LSP can be resource-intensive on large projects
- Consider using
SOURCEKIT_BUILD_ARGS
to limit scope if needed - Close unused Xcode projects to free up SourceKit-LSP resources
This MCP server acts as a bridge between AI agents and SourceKit-LSP:
AI Agent <--[MCP]--> This Server <--[LSP]--> SourceKit-LSP <--> Swift Code
- MCP Tools: Synchronous request/response for AI agents
- LSP Communication: Asynchronous notifications and requests
- Caching: Diagnostics and file state cached for immediate responses
MIT
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass (
npm test
) - Submit a pull request
See the engineering plan for implementation details.