Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 91 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# MCP Language Server

A Model Context Protocol (MCP) server that runs a language server and provides tools for communicating with it.
**Note:** This repository is a fork of [isaacphi/mcp-language-server](https://github.com/isaacphi/mcp-language-server). It has undergone significant architectural changes (supporting multiple language servers in a single process via a configuration file) and is not intended for merging back into the original repository.

## Motivation
A Model Context Protocol (MCP) server that manages multiple language servers for different programming languages within a single workspace. It provides tools for communicating with the appropriate language server based on file context or explicit language specification.

Claude desktop with the [filesystem](https://github.com/modelcontextprotocol/servers/tree/main/src/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, I want to create that experience when working with large projects.
## Motivation

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 makes bring those tools to LLMs. LSP also seems like a clear inspiration for MCP so why not jam them together?
Language servers excel at tasks that LLMs often struggle with, such as precisely understanding types, navigating complex codebases, and providing accurate symbol references across large projects. This project aims to bring the power of multiple language servers to LLMs through a unified MCP interface, enabling more sophisticated code understanding and manipulation capabilities.

## Status

Expand All @@ -23,16 +23,18 @@ 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 server provides the following tools, automatically routing requests to the appropriate language server based on file extensions (for file-based tools) or an explicit `language` argument.

- `read_definition`: Retrieves the complete source code definition of a symbol. **Requires a `language` argument** (e.g., `"typescript"`, `"go"`) to specify which language server to query.
- `find_references`: Locates all usages and references of a symbol. **Requires a `language` argument** (e.g., `"typescript"`, `"go"`) to specify which language server to query.
- `get_diagnostics`: Provides diagnostic information for a specific file (language determined by file extension).
- `get_codelens`: Retrieves code lens hints for a specific file (language determined by file extension).
- `execute_codelens`: Runs a code lens action for a specific file (language determined by file extension).
- `apply_text_edit`: Allows making multiple text edits to a file programmatically (language determined by file extension). Supports simple insert/delete/replace, regex-based replacement (using `isRegex`, `regexPattern`, `regexReplace`), and optional bracket balance protection (using `preserveBrackets`, `bracketTypes`) to prevent edits that break pairs like `()`, `{}`, `[]`.

Behind the scenes, this MCP server can act on `workspace/applyEdit` requests from the language server, so it can apply things like refactor requests, adding imports, formatting code, etc.
Behind the scenes, this MCP server can act on `workspace/applyEdit` requests from the language servers, enabling features like refactoring, adding imports, and code formatting.

Each tool supports various options for customizing output, such as including line numbers or additional context. See the tool documentation for detailed usage. Line numbers are necessary for `apply_text_edit` to be able to make accurate edits.
Most tools support options like `showLineNumbers`. Refer to the tool schemas for detailed usage.

## About

Expand All @@ -42,64 +44,91 @@ This codebase makes use of edited code from [gopls](https://go.googlesource.com/

## Prerequisites

Install Go: Follow instructions at <https://golang.org/doc/install>

Fetch or update this server:

```bash
go install github.com/isaacphi/mcp-language-server@latest
```

Install a language server for your codebase:

- Python (pyright): `npm install -g pyright`
1. **Install Go:** Follow instructions at <https://golang.org/doc/install>
2. **Install Language Servers:** Install the language servers for the languages you want to use in your project. Examples:
- 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 something like the following configuration to your Claude Desktop settings (or similar MCP-enabled client):

```json
{
"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": {
"DEBUG": "1"
1. **Build the Server:**
Clone the repository and build the executable:
```bash
git clone https://github.com/isaacphi/mcp-language-server.git
cd mcp-language-server
go build -o mcp-language-server .
```

2. **Create Configuration File (`config.json`):**
Create a JSON configuration file (e.g., `config.json` in the project root or another location) to define the language servers you want to manage.

**`config.json` Example:**
```json
{
"workspaceDir": "/Users/you/dev/yourcodebase", // Absolute path to your project root
"languageServers": [
{
"language": "typescript", // Unique name for the language
"command": "typescript-language-server", // Command to run the LSP server
"args": ["--stdio"], // Arguments for the LSP command
"extensions": [".ts", ".tsx", ".js", ".jsx"] // File extensions for this language
},
{
"language": "go",
"command": "/path/to/your/gopls", // Absolute path or command name for gopls
"args": [],
"extensions": [".go"]
},
{
"language": "python",
"command": "pyright-langserver",
"args": ["--stdio"],
"extensions": [".py"]
}
// Add entries for other languages as needed
]
}
```
- Replace `/Users/you/dev/yourcodebase` with the absolute path to your project.
- Replace `/path/to/your/gopls` etc. with the correct command or absolute path for each language server.

3. **Configure MCP Client:**
Add the following configuration to your Claude Desktop settings (or similar MCP-enabled client), adjusting paths as necessary:

```json
{
"mcpServers": {
"mcp-language-server": { // You can choose any name here
"command": "/full/path/to/your/clone/mcp-language-server/mcp-language-server", // Absolute path to the built executable
"args": [
"--config", "/full/path/to/your/config.json" // Absolute path to your config.json
],
"cwd": "/full/path/to/your/clone/mcp-language-server", // Optional: Set working directory to project root
"env": {
// Add any necessary environment variables for LSP servers (e.g., PATH)
// "PATH": "...",
"DEBUG": "1" // Optional: Enable debug logging
}
}
// Add other MCP servers here if needed
}
}
}
}
```

Replace:

- `/Users/you/dev/yourcodebase` with the absolute path to your project
- `/opt/homebrew/bin/pyright-langserver` with the path to your language server (found using `which` command e.g. `which pyright-langserver`)
- Any aruments after `--` are sent as arguments to your language server.
- Any env variables are passed on to the language server. Some may be necessary for you language server. For example, `gopls` required `GOPATH` and `GOCACHE` in order for me to get it working properly.
- `DEBUG=1` is optional. See below.
```
- Ensure the `command` path points to the `mcp-language-server` executable you built.
- Ensure the `--config` argument points to the `config.json` file you created.
- Set `cwd` if necessary (usually the directory containing the executable).
- Add required environment variables (like `PATH` if using shims like `asdf`) to the `env` object.

## Development

Clone the repository:

```bash
git clone https://github.com/isaacphi/mcp-language-server.git
cd mcp-language-server
forcd mcp-language-server
```

Install dev dependencies:
Expand All @@ -114,28 +143,27 @@ Build:
go build
```

Configure your Claude Desktop (or similar) to use the local binary:
Configure your Claude Desktop (or similar) to use the local binary, similar to the Setup section, ensuring the `command` points to your locally built executable and the `--config` argument points to your development `config.json`:

```json
{
"mcpServers": {
"language-server": {
"command": "/full/path/to/your/clone/mcp-language-server/mcp-language-server",
"mcp-language-dev": { // Example name for development server
"command": "/full/path/to/your/clone/mcp-language-server/mcp-language-server", // Path to your built binary
"args": [
"--workspace",
"/path/to/workspace",
"--lsp",
"/path/to/language/server"
"--config", "/full/path/to/your/clone/mcp-language-server/config.dev.json" // Path to your development config file
],
"cwd": "/full/path/to/your/clone/mcp-language-server", // Working directory
"env": {
"DEBUG": "1"
"DEBUG": "1" // Enable debug logging for development
}
}
}
}
```
Remember to create a `config.dev.json` (or similar) for your development environment.

Rebuild after making changes.
Rebuild (`go build -o mcp-language-server .`) after making code changes.

## Feedback

Expand Down
26 changes: 26 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"workspaceDir": "/path/to/workspace",
"languageServers": [
{
"language": "typescript",
"command": "typescript-language-server",
"args": [
"--stdio"
],
"extensions": [
".ts",
".tsx",
".js",
".jsx"
]
},
{
"language": "go",
"command": "gopls",
"args": [],
"extensions": [
".go"
]
}
]
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ require (
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/invopop/jsonschema v0.13.0 // indirect
github.com/kisielk/errcheck v1.9.0 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.10.0 // indirect
github.com/tidwall/gjson v1.18.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
Expand Down
Loading