### MCP Tool: lsp_info Request and Response Source: https://context7.com/jonrad/lsp-mcp/llms.txt Example of querying available LSP servers and their capabilities using the `lsp_info` MCP tool. The request is a standard MCP tool call, and the response provides detailed information about each started LSP server. ```javascript // Request via MCP { "method": "tools/call", "params": { "name": "lsp_info", "arguments": {} } } // Response [ { "id": "typescript", "languages": ["typescript", "javascript"], "extensions": ["ts", "tsx", "js", "jsx"], "started": true, "capabilities": { "textDocumentSync": 2, "completionProvider": { "resolveProvider": true, "triggerCharacters": [".", "\"", "'", "/", "@", "<"] }, "hoverProvider": true, "signatureHelpProvider": { "triggerCharacters": ["(", ",", "<"] }, "definitionProvider": true, "typeDefinitionProvider": true, "implementationProvider": true, "referencesProvider": true, "documentHighlightProvider": true, "documentSymbolProvider": true, "codeActionProvider": true, "codeLensProvider": { "resolveProvider": true }, "documentFormattingProvider": true, "documentRangeFormattingProvider": true, "renameProvider": { "prepareProvider": true }, "foldingRangeProvider": true, "executeCommandProvider": { "commands": ["_typescript.applyWorkspaceEdit"] }, "workspace": { "fileOperations": {} } } }, { "id": "python", "languages": ["python", "python2", "python3"], "extensions": ["py"], "started": "Not started. LSP will start automatically when needed, such as when analyzing a file with extensions py." } ] ``` -------------------------------- ### Start LSP MCP Server CLI Source: https://context7.com/jonrad/lsp-mcp/llms.txt Command-line interface for launching the LSP MCP server. Supports single or multiple LSP servers, workspace specification, method filtering, configuration files, and verbose logging. ```bash npx lsp-mcp --lsp "npx -y typescript-language-server --stdio" lsp-mcp --lsp "npx -y typescript-language-server --stdio" --workspace /path/to/project lsp-mcp --lsp "npx -y typescript-language-server --stdio" --methods textDocument/documentSymbol textDocument/definition lsp-mcp --config ./config.json lsp-mcp --lsp "npx -y typescript-language-server --stdio" --verbose ``` -------------------------------- ### Claude Desktop MCP Server Configuration (npx) Source: https://context7.com/jonrad/lsp-mcp/llms.txt Configuration for Claude Desktop to use LSP MCP via npx. This example specifically sets up a TypeScript LSP server, including specifying versions and the project workspace. ```json { "mcpServers": { "lsp-typescript": { "command": "npx", "args": [ "-y", "--silent", "git+https://github.com/jonrad/lsp-mcp", "--lsp", "npx -y --silent -p 'typescript@5.7.3' -p 'typescript-language-server@4.3.3' typescript-language-server --stdio", "--workspace", "/home/user/myproject" ] } } } ``` -------------------------------- ### Embedding LSP MCP in Node.js Application Source: https://context7.com/jonrad/lsp-mcp/llms.txt Provides a TypeScript example of how to import and use the LSP MCP library within a Node.js application. It covers configuration, initialization, and graceful shutdown handling. ```typescript import { App } from 'lsp-mcp/dist/app'; import { nullLogger, errorLogger } from 'lsp-mcp/dist/logger'; import { Config } from 'lsp-mcp/dist/config'; // Create configuration const config: Config = { lsps: [ { id: "typescript", extensions: ["ts", "js"], languages: ["typescript", "javascript"], command: "npx", args: ["-y", "typescript-language-server", "--stdio"] } ], workspace: "/path/to/project" }; // Initialize and start the MCP server const app = new App(config, errorLogger); try { await app.start(); // MCP server now listening on stdin/stdout // AI client can communicate via MCP protocol } catch (error) { console.error("Failed to start LSP MCP:", error); process.exit(1); } // Clean up on shutdown process.on('SIGINT', async () => { await app.dispose(); process.exit(0); }); ``` -------------------------------- ### Development Commands for LSP MCP CLI Source: https://github.com/jonrad/lsp-mcp/blob/main/README.md This snippet shows basic development commands for the LSP MCP CLI tool. It includes commands to install dependencies using yarn, launch the interactive MCP tool, and view CLI help information. These commands are essential for setting up and working with the project locally. ```bash yarn yarn mcp-cli # Interactive MCP tool to help with development yarn dev --help # Get the CLI help ``` -------------------------------- ### Configure Claude Desktop with LSP MCP using npx Source: https://github.com/jonrad/lsp-mcp/blob/main/README.md This JSON configuration allows Claude Desktop to launch the LSP MCP server using npx. It includes arguments to install and run the `typescript-language-server` and specifies how to modify the language server and its version. Note that Claude Desktop might sometimes report failures even when the tools function correctly. ```json { "mcpServers": { "lsp": { "command": "npx", "args": ["-y", "--silent", "git+https://github.com/jonrad/lsp-mcp", "--lsp", "npx -y --silent -p 'typescript@5.7.3' -p 'typescript-language-server@4.3.3' typescript-language-server --stdio"] } } } ``` -------------------------------- ### Claude Desktop MCP Server Configuration (Docker) Source: https://context7.com/jonrad/lsp-mcp/llms.txt Configuration for Claude Desktop to utilize LSP MCP via Docker. This setup involves mounting a local project directory to the container for the LSP MCP server to access. ```json { "mcpServers": { "lsp": { "command": "docker", "args": [ "run", "-i", "--rm", "-v", "/home/user/projects:/workspace", "docker.io/jonrad/lsp-mcp:0.3.1" ] } } } ``` -------------------------------- ### Configure Claude Desktop with LSP MCP using Docker Source: https://github.com/jonrad/lsp-mcp/blob/main/README.md This configuration snippet sets up Claude Desktop to use the LSP MCP server via Docker. It specifies the Docker image to run and provides an example of how to mount local directories into the container for file access. Ensure the version tag in the image name is updated as needed. ```json { "mcpServers": { "lsp": { "command": "docker", "args": ["run", "-i", "--rm", "docker.io/jonrad/lsp-mcp:0.3.1"] } } } ``` -------------------------------- ### Get Symbol Hover Information (LSP) Source: https://context7.com/jonrad/lsp-mcp/llms.txt The `textDocument_hover` LSP method provides type information and documentation for a symbol at a specific position in a document. It takes the document URI and position as arguments and returns a hover object, often containing markdown-formatted details. ```javascript // Request via MCP { "method": "tools/call", "params": { "name": "textDocument_hover", "arguments": { "textDocument": { "uri": "/workspace/src/app.ts" }, "position": { "line": 83, "character": 27 } } } } // Response { "contents": { "kind": "markdown", "value": "```typescript\n(method) App.buildConfig(options: OptionValues, logger: Logger): Promise\n```\n\nBuilds configuration from command line options or config file." }, "range": { "start": { "line": 83, "character": 22 }, "end": { "line": 83, "character": 33 } } } ``` -------------------------------- ### Get Document Symbol Outline (LSP) Source: https://context7.com/jonrad/lsp-mcp/llms.txt The `textDocument_documentSymbol` LSP method retrieves a hierarchical outline of symbols within a given document. It requires the document's URI as input and returns a list of symbols, including their names, kinds, ranges, and potential children. ```javascript // Request via MCP { "method": "tools/call", "params": { "name": "textDocument_documentSymbol", "arguments": { "textDocument": { "uri": "/workspace/src/app.ts" } } } } // Response [ { "name": "App", "kind": 5, // Class "range": { "start": { "line": 15, "character": 0 }, "end": { "line": 262, "character": 1 } }, "selectionRange": { "start": { "line": 15, "character": 13 }, "end": { "line": 15, "character": 16 } }, "children": [ { "name": "toolManager", "kind": 8, // Field "range": { "start": { "line": 16, "character": 2 }, "end": { "line": 16, "character": 46 } } }, { "name": "constructor", "kind": 6, // Constructor "range": { "start": { "line": 22, "character": 2 }, "end": { "line": 41, "character": 3 } } }, { "name": "start", "kind": 12, // Method "range": { "start": { "line": 199, "character": 2 }, "end": { "line": 204, "character": 3 } } } ] } ] ``` -------------------------------- ### Docker Deployment of LSP MCP Source: https://context7.com/jonrad/lsp-mcp/llms.txt Demonstrates how to deploy LSP MCP using Docker, including pulling the official image, running with volume mounts for workspaces, and building a custom image with additional language servers. ```bash # Pull the official image docker pull jonrad/lsp-mcp:0.3.1 # Run with mounted workspace docker run -i --rm \ -v /home/user/projects:/workspace \ jonrad/lsp-mcp:0.3.1 # Run with custom config file docker run -i --rm \ -v /home/user/projects:/workspace \ -v /home/user/lsp-config.json:/config.json \ jonrad/lsp-mcp:0.3.1 \ --config /config.json # Build custom image with additional language servers cat > Dockerfile << 'EOF' FROM jonrad/lsp-mcp:0.3.1 # Install additional language servers RUN npm install -g pyright rust-analyzer RUN apk add --no-cache go gopls # Copy custom configuration COPY lsp-config.json /app/config.json ENTRYPOINT ["node", "dist/index.js", "--config", "/app/config.json"] EOF docker build -t my-lsp-mcp . docker run -i --rm -v /home/user/projects:/workspace my-lsp-mcp ``` -------------------------------- ### Cursor IDE Configuration for LSP MCP Source: https://context7.com/jonrad/lsp-mcp/llms.txt This JSON configuration enables Cursor IDE to use the lsp-analysis server provided by LSP MCP. It specifies that the server is run as a Docker command, mounting the workspace and executing the lsp-mcp container with specific arguments for workspace analysis. This allows for AI-powered code understanding within the IDE. ```json { "mcpServers": { "lsp-analysis": { "type": "command", "command": "docker", "args": [ "run", "-i", "--rm", "-v", "${workspaceFolder}:/workspace", "jonrad/lsp-mcp:0.3.1", "--workspace", "/workspace" ] } } } ``` -------------------------------- ### Multi-LSP Configuration JSON Source: https://context7.com/jonrad/lsp-mcp/llms.txt JSON configuration file for managing multiple language servers simultaneously. Defines LSP server details including command, arguments, extensions, and associated languages, along with global method filters and workspace settings. ```json { "lsps": [ { "id": "typescript", "extensions": ["ts", "tsx", "js", "jsx"], "languages": ["typescript", "javascript"], "command": "npx", "args": ["-y", "typescript-language-server", "--stdio"] }, { "id": "python", "extensions": ["py"], "languages": ["python", "python2", "python3"], "command": "uvx", "args": ["--from", "python-lsp-server", "pylsp"] }, { "id": "rust", "extensions": ["rs"], "languages": ["rust"], "command": "rust-analyzer", "args": [] } ], "methods": ["textDocument/documentSymbol", "textDocument/definition", "textDocument/references"], "workspace": "/app/repos/myproject" } ``` -------------------------------- ### Create Temporary URI with file_contents_to_uri (MCP Tool) Source: https://context7.com/jonrad/lsp-mcp/llms.txt The `file_contents_to_uri` tool allows the creation of a temporary in-memory URI for code snippets, enabling analysis without saving files to disk. It takes file contents and programming language as arguments and returns a unique URI. This URI can then be used in subsequent LSP method calls. ```javascript // Request via MCP { "method": "tools/call", "params": { "name": "file_contents_to_uri", "arguments": { "file_contents": "function add(a: number, b: number): number {\n return a + b;\n}\n\nconst result = add(5, '10');", "programming_language": "typescript" } } } // Response "mem://abc123xyz789.typescript" // Use this URI in subsequent LSP method calls { "method": "tools/call", "params": { "name": "textDocument_diagnostics", "arguments": { "textDocument": { "uri": "mem://abc123xyz789.typescript" } } } } ``` -------------------------------- ### LSP textDocument_completion Request and Response Source: https://context7.com/jonrad/lsp-mcp/llms.txt Demonstrates how to request code completion suggestions at a specific position in a document and the structure of the expected response. This is typically used by IDEs to provide real-time code hints. ```javascript // Request via MCP { "method": "tools/call", "params": { "name": "textDocument_completion", "arguments": { "textDocument": { "uri": "/workspace/src/app.ts" }, "position": { "line": 30, "character": 10 }, "context": { "triggerKind": 1 // Invoked } } } } // Response { "isIncomplete": false, "items": [ { "label": "lspManager", "kind": 5, // Field "sortText": "0", "detail": "(property) App.lspManager: LspManager", "insertText": "lspManager" }, { "label": "toolManager", "kind": 5, "sortText": "0", "detail": "(property) App.toolManager: ToolManager", "insertText": "toolManager" }, { "label": "start", "kind": 2, // Method "sortText": "0", "detail": "(method) App.start(): Promise", "insertText": "start" }, { "label": "dispose", "kind": 2, "sortText": "0", "detail": "(method) App.dispose(): Promise", "insertText": "dispose" } ] } ``` -------------------------------- ### LSP textDocument_formatting Request and Response Source: https://context7.com/jonrad/lsp-mcp/llms.txt Illustrates how to request code formatting for a document and the structure of the response containing the formatted text. This ensures code adheres to style guidelines. ```javascript // Request via MCP { "method": "tools/call", "params": { "name": "textDocument_formatting", "arguments": { "textDocument": { "uri": "/workspace/src/messy.ts" }, "options": { "tabSize": 2, "insertSpaces": true, "trimTrailingWhitespace": true, "insertFinalNewline": true } } } } // Response [ { "range": { "start": { "line": 0, "character": 0 }, "end": { "line": 50, "character": 0 } }, "newText": "import { App } from './app';\nimport { Logger } from 'vscode-jsonrpc';\n\nexport class MyClass {\n private readonly app: App;\n\n constructor(logger: Logger) {\n this.app = new App({}, logger);\n }\n\n async start(): Promise {\n await this.app.start();\n }\n}\n" } ] ``` -------------------------------- ### LSP Method: textDocument_references Source: https://context7.com/jonrad/lsp-mcp/llms.txt Finds all references to a symbol across the project, given a document and a position. ```APIDOC ## LSP Method: textDocument_references ### Description Find all references to a symbol across the project. ### Method POST (via MCP `tools/call`) ### Endpoint `/tools/call` ### Parameters #### Request Body - **method** (string) - Required - The MCP method to call, "tools/call". - **params** (object) - Required - Parameters for the tool call. - **name** (string) - Required - The name of the LSP method, "textDocument_references". - **arguments** (object) - Required - Arguments for the LSP method. - **textDocument** (object) - Required - Information about the text document. - **uri** (string) - Required - The URI of the document. - **position** (object) - Required - The position within the document. - **line** (integer) - Required - The line number (0-based). - **character** (integer) - Required - The character offset (0-based). - **context** (object) - Optional - Context for finding references. - **includeDeclaration** (boolean) - Optional - Whether to include the declaration of the symbol in the results. ### Request Example ```json { "method": "tools/call", "params": { "name": "textDocument_references", "arguments": { "textDocument": { "uri": "/workspace/src/lsp.ts" }, "position": { "line": 8, "character": 17 }, "context": { "includeDeclaration": true } } } } ``` ### Response #### Success Response (200) - **array** - An array of location objects, each indicating a reference to the symbol. - **uri** (string) - The URI of the file where the reference is located. - **range** (object) - The range of the reference within the file. - **start** (object) - The starting position of the reference. - **line** (integer) - The line number. - **character** (integer) - The character offset. - **end** (object) - The ending position of the reference. - **line** (integer) - The line number. - **character** (integer) - The character offset. ### Response Example ```json [ { "uri": "file:///workspace/src/lsp.ts", "range": { "start": { "line": 8, "character": 17 }, "end": { "line": 8, "character": 26 } } }, { "uri": "file:///workspace/src/app.ts", "range": { "start": { "line": 1, "character": 9 }, "end": { "line": 1, "character": 18 } } } ] ``` ``` -------------------------------- ### LSP textDocument_diagnostics Request and Response Source: https://context7.com/jonrad/lsp-mcp/llms.txt Shows how to request diagnostic information (errors, warnings) for a document and the format of the diagnostic response. This helps in identifying and reporting code quality issues. ```javascript // Request via MCP { "method": "tools/call", "params": { "name": "textDocument_diagnostics", "arguments": { "textDocument": { "uri": "/workspace/src/broken.ts" } } } } // Response [ { "range": { "start": { "line": 4, "character": 26 }, "end": { "line": 4, "character": 30 } }, "message": "Argument of type 'string' is not assignable to parameter of type 'number'.", "severity": 1, // Error "code": 2345, "source": "typescript" }, { "range": { "start": { "line": 7, "character": 6 }, "end": { "line": 7, "character": 15 } }, "message": "'unusedVar' is declared but its value is never read.", "severity": 2, // Warning "code": 6133, "source": "typescript", "tags": [1] // Unnecessary } ] ``` -------------------------------- ### MCP Tool: file_contents_to_uri Source: https://context7.com/jonrad/lsp-mcp/llms.txt Creates a temporary URI for analyzing code snippets that are not saved to the filesystem. This URI can then be used in subsequent LSP method calls. ```APIDOC ## MCP Tool: file_contents_to_uri ### Description Creates a temporary URI for analyzing code snippets not saved to the filesystem. ### Method POST (via MCP `tools/call`) ### Endpoint `/tools/call` ### Parameters #### Request Body - **method** (string) - Required - The MCP method to call, "tools/call". - **params** (object) - Required - Parameters for the tool call. - **name** (string) - Required - The name of the tool, "file_contents_to_uri". - **arguments** (object) - Required - Arguments for the tool. - **file_contents** (string) - Required - The content of the file to be analyzed. - **programming_language** (string) - Required - The programming language of the code snippet. ### Request Example ```json { "method": "tools/call", "params": { "name": "file_contents_to_uri", "arguments": { "file_contents": "function add(a: number, b: number): number {\n return a + b;\n}\n\nconst result = add(5, '10');", "programming_language": "typescript" } } } ``` ### Response #### Success Response (200) - **string** - A temporary URI (e.g., `mem://abc123xyz789.typescript`) for the analyzed code snippet. ### Response Example ```json "mem://abc123xyz789.typescript" ``` ### Usage Example Use the returned URI in subsequent LSP method calls, such as `textDocument_diagnostics`. ``` -------------------------------- ### LSP Method: textDocument_hover Source: https://context7.com/jonrad/lsp-mcp/llms.txt Retrieves type information and documentation for a symbol at a specific position in a document. ```APIDOC ## LSP Method: textDocument_hover ### Description Get type information and documentation for a symbol. ### Method POST (via MCP `tools/call`) ### Endpoint `/tools/call` ### Parameters #### Request Body - **method** (string) - Required - The MCP method to call, "tools/call". - **params** (object) - Required - Parameters for the tool call. - **name** (string) - Required - The name of the LSP method, "textDocument_hover". - **arguments** (object) - Required - Arguments for the LSP method. - **textDocument** (object) - Required - Information about the text document. - **uri** (string) - Required - The URI of the document. - **position** (object) - Required - The position within the document. - **line** (integer) - Required - The line number (0-based). - **character** (integer) - Required - The character offset (0-based). ### Request Example ```json { "method": "tools/call", "params": { "name": "textDocument_hover", "arguments": { "textDocument": { "uri": "/workspace/src/app.ts" }, "position": { "line": 83, "character": 27 } } } } ``` ### Response #### Success Response (200) - **object** - An object containing hover information. - **contents** (object) - The content of the hover information, typically markdown. - **kind** (string) - The kind of content, e.g., "markdown". - **value** (string) - The actual content as a markdown string. - **range** (object) - The range in the document to which the hover applies. - **start** (object) - The starting position of the range. - **line** (integer) - The line number. - **character** (integer) - The character offset. - **end** (object) - The ending position of the range. - **line** (integer) - The line number. - **character** (integer) - The character offset. ### Response Example ```json { "contents": { "kind": "markdown", "value": "```typescript\n(method) App.buildConfig(options: OptionValues, logger: Logger): Promise\n```\n\nBuilds configuration from command line options or config file." }, "range": { "start": { "line": 83, "character": 22 }, "end": { "line": 83, "character": 33 } } } ``` ``` -------------------------------- ### Find Symbol References (LSP) Source: https://context7.com/jonrad/lsp-mcp/llms.txt The `textDocument_references` LSP method finds all occurrences of a symbol across the entire project. It requires the document URI and the symbol's position. An optional `context` object can include `includeDeclaration` to also find the declaration site. ```javascript // Request via MCP { "method": "tools/call", "params": { "name": "textDocument_references", "arguments": { "textDocument": { "uri": "/workspace/src/lsp.ts" }, "position": { "line": 8, "character": 17 }, "context": { "includeDeclaration": true } } } } // Response [ { "uri": "file:///workspace/src/lsp.ts", "range": { "start": { "line": 8, "character": 17 }, "end": { "line": 8, "character": 26 } } }, { "uri": "file:///workspace/src/lsp.ts", "range": { "start": { "line": 20, "character": 36 }, "end": { "line": 20, "character": 45 } } }, { "uri": "file:///workspace/src/app.ts", "range": { "start": { "line": 1, "character": 9 }, "end": { "line": 1, "character": 18 } } } ] ``` -------------------------------- ### Find Symbol Definition Location (LSP) Source: https://context7.com/jonrad/lsp-mcp/llms.txt The `textDocument_definition` LSP method is used to find the specific location where a symbol is defined within a project. It requires the document URI and the position of the symbol as input. An optional `lsp` argument can be provided to specify the language server for multi-LSP environments. ```javascript // Request via MCP { "method": "tools/call", "params": { "name": "textDocument_definition", "arguments": { "textDocument": { "uri": "/workspace/src/index.ts" }, "position": { "line": 83, "character": 22 } } } } // Response { "uri": "file:///workspace/src/config.ts", "range": { "start": { "line": 21, "character": 21 }, "end": { "line": 21, "character": 31 } } } // For multi-LSP setups, specify the LSP explicitly { "method": "tools/call", "params": { "name": "textDocument_definition", "arguments": { "lsp": "typescript", "textDocument": { "uri": "/workspace/src/index.ts" }, "position": { "line": 83, "character": 22 } } } } ``` -------------------------------- ### LSP Method: textDocument_diagnostics Source: https://context7.com/jonrad/lsp-mcp/llms.txt Retrieves diagnostic information (like errors and warnings) for a given document, identified by its URI. ```APIDOC ## LSP Method: textDocument_diagnostics ### Description Retrieves diagnostic information for a document. ### Method POST (via MCP `tools/call`) ### Endpoint `/tools/call` ### Parameters #### Request Body - **method** (string) - Required - The MCP method to call, "tools/call". - **params** (object) - Required - Parameters for the tool call. - **name** (string) - Required - The name of the LSP method, "textDocument_diagnostics". - **arguments** (object) - Required - Arguments for the LSP method. - **textDocument** (object) - Required - Information about the text document. - **uri** (string) - Required - The URI of the document to get diagnostics for (e.g., a `mem://` URI). ### Request Example ```json { "method": "tools/call", "params": { "name": "textDocument_diagnostics", "arguments": { "textDocument": { "uri": "mem://abc123xyz789.typescript" } } } } ``` ### Response #### Success Response (200) - **array** - An array of diagnostic objects, each containing details like message, severity, range, etc. ### Response Example ```json [ { "severity": 2, // Error "code": "2345", "message": "Argument of type 'string' is not assignable to parameter of type 'number'.", "source": "typescript", "range": { "start": { "line": 3, "character": 19 }, "end": { "line": 3, "character": 25 } } } ] ``` ``` -------------------------------- ### LSP Method: textDocument_documentSymbol Source: https://context7.com/jonrad/lsp-mcp/llms.txt Retrieves a hierarchical outline of symbols (like classes, functions, variables) within a given document. ```APIDOC ## LSP Method: textDocument_documentSymbol ### Description Get hierarchical symbol outline of a document. ### Method POST (via MCP `tools/call`) ### Endpoint `/tools/call` ### Parameters #### Request Body - **method** (string) - Required - The MCP method to call, "tools/call". - **params** (object) - Required - Parameters for the tool call. - **name** (string) - Required - The name of the LSP method, "textDocument_documentSymbol". - **arguments** (object) - Required - Arguments for the LSP method. - **textDocument** (object) - Required - Information about the text document. - **uri** (string) - Required - The URI of the document to get symbols from. ### Request Example ```json { "method": "tools/call", "params": { "name": "textDocument_documentSymbol", "arguments": { "textDocument": { "uri": "/workspace/src/app.ts" } } } } ``` ### Response #### Success Response (200) - **array** - An array of symbol information objects, representing the hierarchical structure of symbols in the document. ### Response Example ```json [ { "name": "App", "kind": 5, // Class "range": { "start": { "line": 15, "character": 0 }, "end": { "line": 262, "character": 1 } }, "selectionRange": { "start": { "line": 15, "character": 13 }, "end": { "line": 15, "character": 16 } }, "children": [ { "name": "toolManager", "kind": 8, // Field "range": { "start": { "line": 16, "character": 2 }, "end": { "line": 16, "character": 46 } } } ] } ] ``` ``` -------------------------------- ### LSP Method: textDocument_definition Source: https://context7.com/jonrad/lsp-mcp/llms.txt Finds the definition location of a symbol at a specific position in a document. ```APIDOC ## LSP Method: textDocument_definition ### Description Find the definition location of a symbol. ### Method POST (via MCP `tools/call`) ### Endpoint `/tools/call` ### Parameters #### Request Body - **method** (string) - Required - The MCP method to call, "tools/call". - **params** (object) - Required - Parameters for the tool call. - **name** (string) - Required - The name of the LSP method, "textDocument_definition". - **arguments** (object) - Required - Arguments for the LSP method. - **lsp** (string) - Optional - Specifies which LSP to use in multi-LSP setups. - **textDocument** (object) - Required - Information about the text document. - **uri** (string) - Required - The URI of the document. - **position** (object) - Required - The position within the document. - **line** (integer) - Required - The line number (0-based). - **character** (integer) - Required - The character offset (0-based). ### Request Example ```json { "method": "tools/call", "params": { "name": "textDocument_definition", "arguments": { "textDocument": { "uri": "/workspace/src/index.ts" }, "position": { "line": 83, "character": 22 } } } } ``` ### Response #### Success Response (200) - **object** - An object containing the definition location. - **uri** (string) - The URI of the file where the definition is located. - **range** (object) - The range of the definition within the file. - **start** (object) - The starting position of the definition. - **line** (integer) - The line number. - **character** (integer) - The character offset. - **end** (object) - The ending position of the definition. - **line** (integer) - The line number. - **character** (integer) - The character offset. ### Response Example ```json { "uri": "file:///workspace/src/config.ts", "range": { "start": { "line": 21, "character": 21 }, "end": { "line": 21, "character": 31 } } } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.