mcp-language-server
by: isaacphi
Model Context Protocol (MCP) server that interacts with a Language Server
📌Overview
Purpose: To create a Model Context Protocol (MCP) server that integrates language server capabilities, enhancing the experience of working with large codebases and providing tools for better LLM interactions.
Overview: The MCP Language Server serves as a bridge between advanced coding tools typically offered by language servers and the capabilities of large language models (LLMs). It aims to maintain the ease of project management while scaling up to larger codebases by utilizing features that enhance understanding of code structures and relationships.
Key Features:
-
Read Definition: Retrieves the full source code definition of any symbol, allowing developers to quickly understand the origins of functions, types, and constants.
-
Find References: Identifies all occurrences and usages of a symbol across the codebase, aiding in code navigation and refactoring.
-
Get Diagnostics: Provides real-time diagnostic information, including warnings and errors, for improved code quality and faster debugging.
-
Code Lens Support: Offers code lens hints for contextual actions, enhancing developer productivity by revealing additional options and insights directly in the IDE.
-
Execute Code Lens: Runs specific actions tied to code lens hints, facilitating inline modifications and improvements to the code.
-
Apply Text Edit: Enables multiple text edits on files programmatically, streamlining code corrections and updates.
MCP Language Server
A Model Context Protocol (MCP) server that runs a language server and provides tools for communicating with it.
Motivation
Claude desktop with the filesystem server feels like magic when working on small projects. This starts to fall apart after you add a few files and imports. With this project, the goal is to create that experience when working with large projects.
Language servers excel at tasks that LLMs often struggle with, such as precisely understanding types, understanding relationships, and providing accurate symbol references. This project aims to bring those tools to LLMs. LSP also seems like a clear inspiration for MCP, so this project combines them.
Status
⚠️ Pre-beta Quality ⚠️
Tested with the following language servers:
- pyright (Python)
- tsserver (TypeScript)
- gopls (Go)
- rust-analyzer (Rust)
But it should be compatible with many more.
Tools
read_definition
: Retrieves the complete source code definition of any symbol (function, type, constant, etc.) from your codebase.find_references
: Locates all usages and references of a symbol throughout the codebase.get_diagnostics
: Provides diagnostic information for a specific file, including warnings and errors.get_codelens
: Retrieves code lens hints for additional context and actions on your code.execute_codelens
: Runs a code lens action.apply_text_edit
: Allows making multiple text edits to a file programmatically.
This MCP server can also act on workspace/applyEdit
requests from the language server, enabling it to apply refactor requests, add imports, format code, etc.
Each tool supports options for customizing output, such as including line numbers or additional context. Line numbers are necessary for apply_text_edit
to make accurate edits.
About
This codebase uses edited code from gopls to handle LSP communication. See ATTRIBUTION for details.
mcp-go is used for MCP communication.
Prerequisites
Install Go: Follow instructions at https://golang.org/doc/install
Fetch or update this server:
go install github.com/isaacphi/mcp-language-server@latest
Install a language server for your codebase:
- Python (pyright):
npm install -g pyright
- TypeScript (tsserver):
npm install -g typescript typescript-language-server
- Go (gopls):
go install golang.org/x/tools/gopls@latest
- Rust (rust-analyzer):
rustup component add rust-analyzer
- Or use any language server
Setup
Add a configuration similar to the following to your Claude Desktop settings (or similar MCP-enabled client):
{
"mcpServers": {
"language-server": {
"command": "go",
"args": [
"run",
"github.com/isaacphi/mcp-language-server@latest",
"--workspace",
"/Users/you/dev/yourcodebase",
"--lsp",
"/opt/homebrew/bin/pyright-langserver",
"--",
"--stdio"
],
"env": {
"LOG_LEVEL": "INFO"
}
}
}
}
Replace:
/Users/you/dev/yourcodebase
with the absolute path to your project/opt/homebrew/bin/pyright-langserver
with the path to your language server (e.g. found usingwhich pyright-langserver
)- Arguments after
--
are passed to your language server - Environment variables are passed to the language server; some may be necessary (e.g.
GOPATH
,GOCACHE
for gopls) LOG_LEVEL
is optional
Development
Clone the repository:
git clone https://github.com/isaacphi/mcp-language-server.git
cd mcp-language-server
Install dev dependencies:
go mod download
Build:
go build
Run tests:
go test ./...
Update test snapshots:
UPDATE_SNAPSHOTS=true go test ./integrationtests/...
Configure your Claude Desktop (or similar) to use the local binary:
{
"mcpServers": {
"language-server": {
"command": "/full/path/to/your/clone/mcp-language-server/mcp-language-server",
"args": [
"--workspace",
"/path/to/workspace",
"--lsp",
"/path/to/language/server"
],
"env": {
"LOG_LEVEL": "DEBUG"
}
}
}
}
Rebuild after making changes.
Feedback
To get detailed LSP and application logs, include:
env: {
"LOG_LEVEL": "DEBUG"
}
Setting LOG_LEVEL
to DEBUG enables verbose logging for all components. Adding LOG_COMPONENT_LEVELS
with wire:DEBUG
shows raw LSP JSON messages.
Please include as much information as possible when opening issues.
Roadmap
- Read definition
- Get references
- Apply edit
- Get diagnostics
- Code lens
- Hover info
- Code actions
- Better handling of context and cancellation
- Add LSP server configuration options and presets for common languages
- Make a more consistent and scalable API for tools (pagination, etc.)
- Create tools at a higher level of abstraction, combining diagnostics, code lens, hover, and code actions when reading definitions or references