Swift Intelligence
Workflow
- Pass the absolute repository root as
workspace_pathon every call. - At an Xcode root, call
swift_xcode_schemesfirst. IfselectionRequiredis true, presentschemesto the user, ask which one to use, and pass that answer asxcode_schemeon every semantic call. Do not choose an arbitrary scheme. - If only a symbol name is known, locate one source occurrence with repository search or
swift_workspace_symbols. - Convert the source location to zero-based
lineand UTF-16charactervalues. - Call the narrowest matching tool:
swift_definitionfor the declaration owning a use.swift_referencesfor symbol-accurate uses.swift_implementationsfor protocol or method implementations.swift_hoverfor compiler-resolved type and documentation.swift_symbolsfor declarations in one file.swift_workspace_symbolsfor indexed symbol discovery.swift_diagnosticsfor compiler diagnostics.- For exhaustive protocol-requirement results, combine its
swift_referencesandswift_implementations, then runswift_referenceson each implementation; these are separate semantic relations.
- Use text search as a fallback or cross-check and label lexical results as lexical.
Constraints
- Prefer a path relative to
workspace_pathforfile_path. - The MCP tools are read-only. Edit files only after reviewing their results.
- Build the relevant Xcode or SwiftPM target before relying on cross-file results.
- At an Xcode repository root, the server selects the sole
.xcworkspaceor.xcodeproj. It uses a same-named shared scheme automatically; otherwisexcode_schemeis required. Multiple containers are an explicit error. SWIFT_INTELLIGENCE_XCODE_SCHEMEremains a default for fixed automation. Per-callxcode_schemetakes precedence. Both accept a comma-separated list:-showBuildSettingsForIndexonly covers targets in a scheme's build action, so list the app scheme plus per-module schemes to reach framework sources. When a file is outside every selected scheme, a path component that names a shared scheme (for exampleProjects/TalkMediaKit/...→ schemeTalkMediaKit) is merged into the same session automatically; the first such call restarts sourcekit-lsp (about a minute). Files with no matching scheme still fail withbuild settings do not include. Each scheme costs about a minute once; index settings are cached under~/Library/Caches/swift-intelligence/and refresh when aproject.pbxprojin the workspace changes. The IndexStoreDB database also lives there, one per index store, so a restarted server reopens it incrementally instead of re-importing every unit; a second live server on the same store falls back to a temporary database. SetSWIFT_INTELLIGENCE_EXPLICIT_UNITS=1to restrict the index to units of the loaded targets' own files: this removes stale positions left by units of other configurations (Sandbox, SampleApp), but references inside modules that are not in the selected schemes disappear, so keep it off unless every module you query is listed.xcodebuild -showBuildSettingsForIndexignores-configuration, so if the emitted product paths name a configuration you never built, setSWIFT_INTELLIGENCE_XCODE_CONFIGURATIONto the one you did build and its<config>-<sdk>path components are rewritten.- An empty indexed result is inconclusive when build settings or the SourceKit index are unavailable.
- Do not claim exhaustive references after an error, timeout, or missing build settings.