VSCode LSP MCP Server
A VSCode extension that exposes Language Server Protocol (LSP) functions as an MCP (Model Context Protocol) server for Claude Code.
How It Works
This extension runs an HTTP server (using StreamableHTTP transport) inside VSCode that exposes LSP capabilities to Claude Code. When VSCode starts, the extension automatically launches the MCP server on port 37140 by default (or the next available port if it's in use). Claude Code connects to this server via HTTP to access VSCode's language intelligence features.
Features
This extension provides the following LSP capabilities to Claude Code through MCP tools:
- workspace_symbols: Search for symbols across the entire workspace
- document_symbols: Get all symbols in a specific document
- find_references: Find all references/usages of a symbol
- rename_symbol: Rename a symbol across the workspace
- go_to_definition: Find the definition of a symbol
- go_to_type_definition: Find the type definition of a symbol
- go_to_implementation: Find the implementation of a symbol
Installation
1. Build the Extension
# Install dependencies
npm install
# Compile TypeScript
npm run compile
2. Install the Extension in VSCode
You have two options:
Option A: Install from VSIX (Recommended)
# Package the extension
npx vsce package
# Install the generated .vsix file in VSCode
code --install-extension vscode-lsp-mcp-0.1.0.vsix
Option B: Run in Development Mode
- Open this project in VSCode
- Press
F5 to launch a new VSCode window with the extension loaded
The extension runs an HTTP server (using StreamableHTTP transport) that starts automatically when VSCode launches. By default, it runs on port 37140 (configurable in VSCode settings).
Edit your Claude Code MCP configuration file:
- macOS/Linux:
~/.config/claude-code/mcp_settings.json
- Windows:
%APPDATA%\claude-code\mcp_settings.json
Add the following configuration:
{
"mcpServers": {
"vscode-lsp": {
"url": "http://localhost:37140"
}
}
}
Note: After installing the extension in VSCode, you'll see a notification showing which port the server started on. Update the port number in your Claude Code configuration to match.
4. Reload VSCode and Restart Claude Code
- Reload VSCode to activate the extension
- Restart Claude Code to connect to the MCP server
Configuration
Changing the Server Port
You can configure the port the MCP server listens on through VSCode settings:
- Open VSCode Settings (Cmd/Ctrl + ,)
- Search for "LSP MCP"
- Set "Server Port" to your desired port number (default: 37140)
- Reload VSCode for the change to take effect
Alternatively, add this to your VSCode settings.json:
{
"vscode-lsp-mcp.serverPort": 37140
}
If the configured port is already in use, the extension will automatically try the next available port and notify you.
Autostart Configuration
By default, the MCP server does not start automatically when you open a workspace. You can enable autostart per workspace using one of these methods:
Using VSCode Commands
- Open the Command Palette (Cmd/Ctrl + Shift + P)
- Run
LSP MCP: Enable Autostart for This Workspace to enable
- Or run
LSP MCP: Disable Autostart for This Workspace to disable
Using VSCode Settings
Add this to your workspace .vscode/settings.json:
{
"vscode-lsp-mcp.autostart": true
}
CLI Control via URL Scheme
You can control the MCP server from the command line using VSCode's custom URL scheme:
Start the Server
# macOS/Linux
open "vscode://trademe.vscode-lsp-mcp/start"
# Windows
start "vscode://trademe.vscode-lsp-mcp/start"
Stop the Server
# macOS/Linux
open "vscode://trademe.vscode-lsp-mcp/stop"
# Windows
start "vscode://trademe.vscode-lsp-mcp/stop"
Enable Autostart for Current Workspace
# macOS/Linux
open "vscode://trademe.vscode-lsp-mcp/enableAutostart"
# Windows
start "vscode://trademe.vscode-lsp-mcp/enableAutostart"
Disable Autostart for Current Workspace
# macOS/Linux
open "vscode://trademe.vscode-lsp-mcp/disableAutostart"
# Windows
start "vscode://trademe.vscode-lsp-mcp/disableAutostart"
Note: VSCode must be running and the extension must be installed for these commands to work.
Usage
Once configured, Claude Code will have access to the LSP tools. Here are some examples:
Search for Symbols
Find all functions named "handleRequest" in the workspace
Find References
Find all usages of the function at src/server.ts line 42, character 10
Rename Symbol
Rename the variable at src/utils.ts line 15, character 8 to "newVariableName"
Go to Definition
Show me the definition of the function at src/main.ts line 20, character 5
workspace_symbols
Search for symbols across the entire workspace.
Parameters:
query (string): Search query for symbols (can be empty to list all symbols)
Example:
{
"query": "handleRequest"
}
document_symbols
Get all symbols in a specific document.
Parameters:
uri (string): File path of the document
Example:
{
"uri": "/path/to/src/server.ts"
}
find_references
Find all references/usages of a symbol.
Parameters:
uri (string): File path of the document
line (number): Line number (0-based)
character (number): Character position (0-based)
includeDeclaration (boolean, optional): Whether to include the declaration (default: true)
Example:
{
"uri": "/path/to/src/server.ts",
"line": 42,
"character": 10
}
rename_symbol
Rename a symbol across the workspace.
Parameters:
uri (string): File path of the document
line (number): Line number (0-based)
character (number): Character position (0-based)
newName (string): New name for the symbol
Example:
{
"uri": "/path/to/src/utils.ts",
"line": 15,
"character": 8,
"newName": "newVariableName"
}
go_to_definition
Find the definition of a symbol.
Parameters:
uri (string): File path of the document
line (number): Line number (0-based)
character (number): Character position (0-based)
Example:
{
"uri": "/path/to/src/main.ts",
"line": 20,
"character": 5
}
go_to_type_definition
Find the type definition of a symbol.
Parameters:
uri (string): File path of the document
line (number): Line number (0-based)
character (number): Character position (0-based)
go_to_implementation
Find the implementation of a symbol.
Parameters:
uri (string): File path of the document
line (number): Line number (0-based)
character (number): Character position (0-based)
Development
Project Structure
vscode-utils/
├── src/
│ ├── extension.ts # VSCode extension entry point
│ ├── mcpServer.ts # MCP server implementation
│ └── tools/ # LSP tool handlers
│ ├── workspaceSymbols.ts
│ ├── documentSymbols.ts
│ ├── findReferences.ts
│ ├── renameSymbol.ts
│ ├── goToDefinition.ts
│ ├── goToTypeDefinition.ts
│ └── goToImplementation.ts
├── package.json
├── tsconfig.json
└── README.md
Available Scripts
npm run compile: Compile TypeScript to JavaScript
npm run watch: Watch for changes and recompile
npm run test: Run integration tests (downloads VSCode if needed)
npm run test:unit: Run unit tests only
npm run lint: Lint the codebase
Testing
The extension includes comprehensive test coverage:
Integration Tests
Integration tests run in a real VSCode instance with the extension activated and test against a sample workspace:
npm test
The integration tests verify:
- Extension activation and command registration
- MCP server HTTP endpoints
- Symbol search (workspace and document-level)
- Find references functionality
- Go to definition/type/implementation
- Rename symbol operations
Unit Tests
Unit tests verify module structure and imports:
npm run test:unit
Test Workspace
The test suite includes a sample workspace with TypeScript and C# files to test LSP features. See src/test/README.md for detailed testing documentation.
Troubleshooting
Extension Not Loading
- Check that the extension is installed:
code --list-extensions | grep vscode-lsp-mcp
- Check the VSCode Output panel (View → Output) and select "Extension Host" from the dropdown
- Look for any error messages related to "vscode-lsp-mcp"
MCP Server Not Connecting
- Check VSCode notification to see which port the server started on (should appear when VSCode loads)
- Verify the URL in your Claude Code MCP configuration matches the server port (default:
http://localhost:37140)
- Test if the server is running:
curl http://localhost:37140/
- Check for port conflicts - try changing the port in VSCode settings if the default is already in use
- Try restarting VSCode and Claude Code
No Symbols Found
Some LSP features depend on the language server being active for the file type. Make sure:
- The appropriate language extension is installed in VSCode
- The workspace is fully loaded
- The language server has finished indexing
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.