
mcp sourcekit lsp
MCP server for sourcekit-lsp
Repository Info
About This Server
MCP server for sourcekit-lsp
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
MCP SourceKit-LSP
An MCP (Model Context Protocol) server that provides Swift code intelligence to AI agents through SourceKit-LSP.
Features
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
Installation
From npm (once published)
npm install -g @leftspin/mcp-sourcekit-lsp
From GitHub
npm install -g github:leftspin/mcp-sourcekit-lsp
For Development
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
Configuration
Claude Desktop
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"
}
}
}
}
Claude Code
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"
}
}
Environment Variables
SOURCEKIT_LSP_PATH(optional): Path to sourcekit-lsp binary. Defaults tosourcekit-lspin PATH.SOURCEKIT_BUILD_ARGS(optional): Additional arguments for sourcekit-lsp (e.g.,-Xswiftc -debug-info-format=dwarf).
For Xcode Projects
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"
Available Tools
swift-definition
Find where a symbol is defined.
{
"file": "/path/to/file.swift",
"line": 10,
"column": 5
}
swift-hover
Get type information and documentation for a symbol.
{
"file": "/path/to/file.swift",
"line": 10,
"column": 5
}
swift-references
Find all references to a symbol.
{
"file": "/path/to/file.swift",
"line": 10,
"column": 5
}
swift-symbols
Search for symbols in the workspace.
{
"query": "MyClass"
}
swift-diagnostics
Get compiler diagnostics for a file.
{
"file": "/path/to/file.swift"
}
Resources
swift-project-structure
Provides an overview of the Swift project structure, including all Swift files and their organization.
swift-build-settings
Shows the current build configuration and compiler settings.
Requirements
- Node.js 16 or later
- SourceKit-LSP (comes with Xcode or Swift toolchain)
- A Swift project (Swift Package Manager or Xcode project)
Development
Setup
# 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
Development Environment
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.
Testing
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage
Troubleshooting
SourceKit-LSP not found
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
No results from tools
-
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 not appearing
- Diagnostics are sent asynchronously by SourceKit-LSP
- Files with no errors/warnings will return empty diagnostics
- Large projects may take longer to analyze
Performance issues
- SourceKit-LSP can be resource-intensive on large projects
- Consider using
SOURCEKIT_BUILD_ARGSto limit scope if needed - Close unused Xcode projects to free up SourceKit-LSP resources
Architecture
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
License
MIT
Contributing
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.
Quick Start
Clone the repository
git clone https://github.com/leftspin/mcp-sourcekit-lspInstall dependencies
cd mcp-sourcekit-lsp
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.