Purpose
mcp-language-server is an MCP (Model Context Protocol) server that runs and exposes language servers to LLMs, enabling MCP-capable clients to use semantic tools to navigate codebases. It is not a language server for MCP.
Main capabilities
The server provides the following semantic tools:
- definition: Retrieve the complete source code definition of any symbol (function, type, constant, etc.) from the codebase.
- references: Locate all uses and references of a symbol in the codebase.
- diagnostics: Provide diagnostic information for a specific file, including warnings and errors.
- hover: Display documentation, type hints, or other hover information at a given location.
- rename_symbol: Rename a symbol in the project.
- edit_file: Allow multiple text edits to a file based on line numbers, providing a more reliable and context-efficient way than search-and-replace-based editing tools.
Usage
- Install Go: follow the instructions at https://golang.org/doc/install .
- Install or update this server:
go install github.com/isaacphi/mcp-language-server@latest - Install a language server: follow one of the guides below.
- Configure your MCP client: follow one of the guides below.
Install a language server
- gopls:
go install golang.org/x/tools/gopls@latest - rust-analyzer:
rustup component add rust-analyzer - pyright:
npm install -g pyright - typescript-language-server:
npm install -g typescript typescript-language-server - clangd: Download a precompiled binary from the official LLVM release page, or install it via a system package manager (for example
apt install clangd、brew install clangd).
Configure the MCP client
Each client is configured differently but similarly. For Claude Desktop, add the following to ~/Library/Application Support/Claude/claude_desktop_config.json. Note: not all clients require these environment variables. For Claude Desktop, you need to update the above environment variables according to your machine and username:
PATHneeds to include the paths to go and gopls. Useecho $(which go):$(which gopls)to get them.GOPATH、GOCACHEandGOMODCACHEmay differ on your machine. These are the default values.
Applicable scenarios
This tool is suitable for scenarios that require LLMs or MCP clients to understand and operate on codebases more efficiently, such as code navigation, refactoring, error diagnostics, etc. It has been tested with the above language servers, but should be compatible with more language servers. Note: the language server must communicate via stdio; any arguments after-- will be sent to the language server as arguments; any environment variables will be passed to the language server.
Limitations
This is beta software. If you encounter any problems or have any suggestions, please let us know by creating an issue. Please keep PRs small, and open an issue first for anything substantial. AI-generated code is acceptable as long as it is tested, passes checks, and is not too bad.
Development and testing
- Clone the repository:
- Includes a justfile for convenience:
- Configure your Claude Desktop (or similar tool) to use the local binary:
- Rebuild after changes.
- Setting the
LOG_LEVELenvironment variable toDEBUGenables verbose logging to stderr, including all components (including messages with the language server and the language server's logs).
LSP interaction
internal/lsp/methods.gocontains generated code for calling the connected language server.internal/protocol/tsprotocol.gocontains generated code for LSP types. This is borrowed from gopls's source code.- LSP allows language servers to return different types for the same method. Go does not like this, so in
internal/protocol/interfaces.goThere are some ugly workarounds.
Local development and snapshot testing
There is a snapshot test suite that makes it easier to try out changes to the tool. These tests run the actual language server on a simulated workspace and capture output and logs. You need to install the language server locally to run them. There are tests for go, rust, python, and typescript. To update snapshots, run UPDATE_SNAPSHOTS=true go test ./integrationtests/....
Acknowledgements
This codebase uses edited code from gopls to handle LSP communication. See ATTRIBUTION for details. Everything here is protected by a permissive BSD-style license. mcp-go is used for MCP communication.