Find every reference to a Swift symbol
swiftFindSymbolReferencesLocates a Swift symbol's declaration in a file and uses SourceKit-LSP to find all references across the project, returning code snippets for each call site and capture.
Instructions
[mg.code] Locates the symbol's declaration in filePath, then asks SourceKit-LSP for textDocument/references. Returns every callsite + capture across the project, with a snippet of each line. Requires an IndexStoreDB at <projectRoot>/.build/index/store for cross-file references — build it with swift build -Xswiftc -index-store-path -Xswiftc <projectRoot>/.build/index/store. The result includes a needsIndex: true hint when the index is missing.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"symbolName": "<symbolName>",
"filePath": "<filePath>"
},
"name": "swiftFindSymbolReferences"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbolName | Yes | Name of the Swift symbol to find references for. | |
| filePath | Yes | Path to a Swift file where the symbol is declared. The LSP query needs a position; we locate it in this file via a regex pre-scan. | |
| projectRoot | No | Override the project root. Default discovers the nearest Package.swift / .xcodeproj / .xcworkspace. | |
| includeDeclaration | No | Include the declaration site itself in the result set. |