A standalone stdio MCP server that exposes Swift project-analysis and SourceKit-LSP semantic tools.
This repository packages a standalone MCP server for Swift code understanding and editing.
Public v1 goal:
- Provide the same 6 LSP-style function tools described in the paper
- Provide the 2 project-analysis tools used to bootstrap agent understanding
- Prefer stable
module-rootsemantic routing for SwiftPM modules - Preserve fallback behavior and expose fallback status in responses
Public v1 non-goal:
- Guarantee that Xcode app-root semantic results are identical to ideal full-workspace indexing results
- Precompute repository-wide
hover/definition/referencesfor every symbol
Read-only tools:
get_directory_treeget_file_structuredefinitionhoverreferencesdiagnostics
Mutating tools:
edit_filerename_symbol
Stable in public v1:
get_directory_treeget_file_structurediagnosticsdefinitionwith LSP-first and structural fallback
Stable for Modules/* package roots:
hoverreferenceswhen SourceKit-LSP returns semantic resultsrename_symbolandedit_fileas execution tools
Best-effort for app-root / Xcode target files such as Wallet/*.swift:
hoverreferencesdefinitionwhen cross-module semantic context depends on full app-target indexing
Always inspect these response fields:
sourceroutinglsp_rootlimitations
Swift routing behavior:
- Files under
Modules/*route to the nearestPackage.swiftroot. - Each module root reuses its own SourceKit-LSP client.
- App files such as
Wallet/*.swiftstay on the app/build-server root. - Responses expose
source,routing,lsp_root, andlimitations. definitionnow prefers real LSP definition results and falls back to structural/text lookup when semantic resolution is unavailable.
- macOS with Xcode / Swift toolchain installed
sourcekit-lspavailable onPATHor passed viaSOURCEKIT_LSP- For Xcode app targets, a working
buildServer.jsonin the analyzed repository root
Best results today come from repositories that look like one of these:
- SwiftPM package roots with
Package.swift - Xcode app roots with
buildServer.json - Mixed app +
Modules/*repositories where package code can be routed module-by-module
Clone this repository anywhere on your machine:
git clone <your-repo-url> /path/to/mcp-sourcekit-analyzerNo Python package install step is required. The server uses only the Python standard library.
Analyze the current working directory:
SOURCEKIT_ANALYZER_ROOT=/path/to/swift/repo \
/path/to/mcp-sourcekit-analyzer/launch.shUse the real user HOME instead of a temporary sandbox-safe HOME:
SOURCEKIT_ANALYZER_LSP_HOME=system \
SOURCEKIT_ANALYZER_ROOT=/path/to/swift/repo \
/path/to/mcp-sourcekit-analyzer/launch.shThe process will stay running and wait for MCP stdio requests. That is expected.
Add an MCP server entry to your MCP-capable client configuration.
Example:
{
"mcpServers": {
"sourcekit-analyzer": {
"command": "/Users/gloria/huawei/mcp-sourcekit-analyzer/launch.sh",
"env": {
"SOURCEKIT_ANALYZER_ROOT": "/path/to/swift/repo",
"SOURCEKIT_ANALYZER_LSP_HOME": "system"
}
}
}
}After the client reloads, the server will expose:
get_directory_treeget_file_structuredefinitionhoverreferencesdiagnosticsedit_filerename_symbol
Use the tools in this order:
get_directory_treeget_file_structurehover/definition/referencesonly when neededdiagnosticsafter local edits or translation outputedit_file/rename_symbolonly for concrete changes
Recommended pattern:
- Do lightweight project analysis first
- Use semantic tools lazily, driven by the current symbol under work
- Do not precompute
hover/definition/referencesfor every symbol in a medium or large repository - For repository translation workflows, treat
get_directory_treeandget_file_structureas the planning/indexing tools, then callhover,definition,references, anddiagnosticsonly for the files and symbols being translated or validated. - This follows the ReCodeAgent-style tool pattern: project-analysis tools provide compact structure for planning, while LSP tools are used selectively for type information, navigation, and validation rather than as a mandatory full-repository scan.
- If a full structural inventory is needed, prefer
run_analysis.py --no-lspfirst, then run targeted LSP queries on high-value modules or symbols.
The server supports two Swift semantic routing modes.
module-root
- Used for files under
Modules/* - Routes to the nearest
Package.swiftroot - Best choice for SwiftPM package code and semantic-heavy workflows
- Usually provides the most stable
hover,definition, anddiagnosticsresults
app-root
- Used for app-target files such as
Wallet/*.swift - Routes to the repository / build-server root
- Use when you need app composition, app wiring, or Xcode-target context
- Semantic quality depends on the app build-server and indexing state
Agent guidance:
- Choose
module-rootwhen the task is about package code and a module file is available - Choose
app-rootwhen the task is specifically about app-target code or app-level composition - Always inspect
source,routing, andlimitationsin the response - If app-root semantic results are weak, empty, or unstable, prefer a module-root path when the same symbol can be analyzed from
Modules/*
The server is explicit about quality and routing:
source = swift-lsp- semantic result came from SourceKit-LSP
source = swift-lsp-empty- semantic request succeeded but returned no semantic payload
source = swift-lsp-empty+text-fallback- semantic request returned nothing, then fallback results were used
source = text-structure-fallbackorregex-fallback: ...- semantic path failed and the server returned a structural fallback
Public v1 release statement:
- This MCP server is suitable for agent-driven Swift repository exploration and targeted semantic queries.
Modules/*package code is the primary supported semantic path.- Xcode app-root semantic behavior is available on a best-effort basis and must not be advertised as equivalent to full IDE-quality workspace semantics.
- Fallback states are part of the public contract and should be surfaced to downstream agents.
If the server starts but no semantic results appear:
- verify
sourcekit-lspis onPATH - verify
SOURCEKIT_ANALYZER_ROOTpoints to the intended repository - for Xcode apps, verify
buildServer.jsonexists and matches your active build environment - try
SOURCEKIT_ANALYZER_LSP_HOME=systemoutside sandboxed environments - prefer
Modules/*package files to confirm SourceKit-LSP behavior first
If app-root behavior is weaker than module-root behavior:
- this is a known public v1 limitation
- keep using
module-rootfor semantic-heavy workflows
Observed on the EUDI iOS wallet repository (eudi-app-ios-wallet-ui, revision 4fce3dd6):
- The MCP stdio layer can initialize, list tools, and serve
tools/callrequests normally. sourcekit-lspwas available at/usr/bin/sourcekit-lsp.- Single-point semantic calls on
Modules/*files worked withsource = swift-lsp; verified tools includedget_file_structure,hover,diagnostics, anddefinition. - A
module-rootquery forModules/feature-common/Sources/Interactor/BiometryInteractor.swiftrouted toModules/feature-commonand returned stable Swift LSP results. - A limited batch run over 25 files with diagnostics and selected symbols completed successfully, but some batched
definition/document-symbol requests timed out and fell back to structural/text results. - A full structural run with LSP disabled completed quickly and produced a useful repository inventory, making it the better first step for translation planning.
- The repository root did not contain
buildServer.json, so app-root/Xcode-target semantic quality should be treated as best-effort unless a valid build server configuration is provided.
Practical guidance:
- Prefer
Modules/*paths when checking SwiftPM package code. - Inspect
source,routing,lsp_root, andlimitationson every semantic response before trusting it as LSP-backed. - Do not interpret fallback output as failure; it is useful for structure and snippets, but less authoritative than
source = swift-lspfor type-driven translation decisions. - Avoid full-repository
hover,definition, orreferencesprecomputation. Use them as on-demand tools for the symbol currently being translated, refactored, or validated. - Run
diagnosticsafter edits or generated translation output, not necessarily before every analysis step.
get_file_structurenow includes compatibility fields such asimports,globals, andskeletondefinitionprefers true LSP definition results and keeps the structural fallback path as backuphover,definition, andreferencesare intended for on-demand agent queries, not full-repository precomputation