You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Model Context Protocol (MCP) server that runs a language server and provides tools for communicating with it.
8
+
This is an [MCP](https://modelcontextprotocol.io/introduction) server that runs and exposes a [language server](https://microsoft.github.io/language-server-protocol/) to LLMs. Not a language server for MCP, whatever that would be.
9
9
10
-
## Motivation
10
+
## Demo
11
11
12
-
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.
12
+
`mcp-language-server` helps MCP enabled clients navigate codebases more easily by giving them access semantic tools like get definition, references, rename, and diagnostics.
13
13
14
-
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?
15
-
16
-
## Status
17
-
18
-
⚠️ Pre-beta Quality ⚠️
19
-
20
-
I have tested this server with the following language servers
21
-
22
-
- gopls (Go)
23
-
- pyright (Python)
24
-
- typescript-language-server (TypeScript)
25
-
- rust-analyzer (Rust)
26
-
27
-
But it should be compatible with many more.
28
-
29
-
## Tools
30
-
31
-
-`read_definition`: Retrieves the complete source code definition of any symbol (function, type, constant, etc.) from your codebase.
32
-
-`find_references`: Locates all usages and references of a symbol throughout the codebase.
33
-
-`get_diagnostics`: Provides diagnostic information for a specific file, including warnings and errors.
34
-
-`get_codelens`: Retrieves code lens hints for additional context and actions on your code.
35
-
-`execute_codelens`: Runs a code lens action.
36
-
-`apply_text_edit`: Allows making multiple text edits to a file programmatically.
37
-
-`hover`: Display documentation, type hints, or other hover information for a given location.
38
-
-`rename_symbol`: Rename a symbol across a project.
39
-
40
-
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.
41
-
42
-
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.
43
-
44
-
## About
45
-
46
-
This codebase makes use of edited code from [gopls](https://go.googlesource.com/tools/+/refs/heads/master/gopls/internal/protocol) to handle LSP communication. See ATTRIBUTION for details.
47
-
48
-
[mcp-go](https://github.com/mark3labs/mcp-go) is used for MCP communication.
49
-
50
-
## Prerequisites
51
-
52
-
Install Go: Follow instructions at <https://golang.org/doc/install>
53
-
54
-
Fetch or update this server:
55
-
56
-
```bash
57
-
go install github.com/isaacphi/mcp-language-server@latest
<p><strong>Configure your MCP client</strong>: This will be different but similar for each client. For Claude Desktop, add the following to <code>~/Library/Application\ Support/Claude/claude_desktop_config.json</code></p>
<p><strong>Note</strong>: Not all clients will need these environment variables. For Claude Desktop you will need to update the environment variables above based on your machine and username:</p>
47
+
<ul>
48
+
<li><code>PATH</code> needs to contain the path to <code>go</code> and to <code>gopls</code>. Get this with <code>echo $(which go):$(which gopls)</code></li>
49
+
<li><code>GOPATH</code>, <code>GOCACHE</code>, and <code>GOMODCACHE</code> may be different on your machine. These are the defaults.</li>
<p><strong>Configure your MCP client</strong>: This will be different but similar for each client. For Claude Desktop, add the following to <code>~/Library/Application\ Support/Claude/claude_desktop_config.json</code></p>
<p><strong>Configure your MCP client</strong>: This will be different but similar for each client. For Claude Desktop, add the following to <code>~/Library/Application\ Support/Claude/claude_desktop_config.json</code></p>
<p><strong>Configure your MCP client</strong>: This will be different but similar for each client. For Claude Desktop, add the following to <code>~/Library/Application\ Support/Claude/claude_desktop_config.json</code></p>
107
+
108
+
<pre>
109
+
{
110
+
"mcpServers": {
111
+
"language-server": {
112
+
"command": "mcp-language-server",
113
+
"args": [
114
+
"--workspace",
115
+
"/Users/you/dev/yourproject/",
116
+
"--lsp",
117
+
"typescript-language-server",
118
+
"--",
119
+
"--stdio"
120
+
]
121
+
}
122
+
}
123
+
}
124
+
</pre>
125
+
</div>
126
+
</details>
127
+
<details>
128
+
<summary>Other</summary>
129
+
<div>
130
+
<p>I have only tested this repo with the servers above but it should be compatible with many more. Note:</p>
131
+
<ul>
132
+
<li>The language server must communicate over stdio.</li>
133
+
<li>Any aruments after <code>--</code> are sent as arguments to the language server.</li>
134
+
<li>Any env variables are passed on to the language server.</li>
135
+
</ul>
136
+
</div>
137
+
</details>
92
138
93
-
Replace:
139
+
## Tools
94
140
95
-
-`/Users/you/dev/yourcodebase` with the absolute path to your project
96
-
-`/opt/homebrew/bin/pyright-langserver` with the path to your language server (found using `which` command e.g. `which pyright-langserver`)
97
-
- Any aruments after `--` are sent as arguments to your language server.
98
-
- 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.
99
-
-`LOG_LEVEL` is optional. See below.
141
+
-`definition`: Retrieves the complete source code definition of any symbol (function, type, constant, etc.) from your codebase.
142
+
-`references`: Locates all usages and references of a symbol throughout the codebase.
143
+
-`diagnostics`: Provides diagnostic information for a specific file, including warnings and errors.
144
+
-`hover`: Display documentation, type hints, or other hover information for a given location.
145
+
-`rename_symbol`: Rename a symbol across a project.
146
+
-`edit_file`: Allows making multiple text edits to a file based on line numbers. Provides a more reliable and context-economical way to edit files compared to search and replace based edit tools.
100
147
101
-
## Development
148
+
## About
102
149
103
-
Clone the repository:
150
+
This codebase makes use of edited code from [gopls](https://go.googlesource.com/tools/+/refs/heads/master/gopls/internal/protocol) to handle LSP communication. See ATTRIBUTION for details. Everything here is covered by a permissive BSD style license.
A [justfile](https://just.systems/man/en/) is included for convenience:
129
170
130
171
```bash
131
-
UPDATE_SNAPSHOTS=true go test ./integrationtests/...
172
+
just -l
173
+
Available recipes:
174
+
build # Build
175
+
check # Run code audit checks
176
+
fmt # Format code
177
+
generate # Generate LSP types and methods
178
+
help# Help
179
+
install # Install locally
180
+
snapshot # Update snapshot tests
181
+
test# Run tests
132
182
```
133
183
134
184
Configure your Claude Desktop (or similar) to use the local binary:
@@ -142,7 +192,7 @@ Configure your Claude Desktop (or similar) to use the local binary:
142
192
"--workspace",
143
193
"/path/to/workspace",
144
194
"--lsp",
145
-
"/path/to/language/server"
195
+
"language-server-executable"
146
196
],
147
197
"env": {
148
198
"LOG_LEVEL": "DEBUG"
@@ -154,28 +204,28 @@ Configure your Claude Desktop (or similar) to use the local binary:
154
204
155
205
Rebuild after making changes.
156
206
157
-
## Feedback
207
+
### Logging
208
+
209
+
Setting the `LOG_LEVEL` environment variable to DEBUG enables verbose logging to stderr for all components including messages to and from the language server and the language server's logs.
158
210
159
-
Include
211
+
### LSP interaction
212
+
213
+
-`internal/lsp/methods.go` contains generated code to make calls to the connected language server.
214
+
-`internal/protocol/tsprotocol.go` contains generated code for LSP types. I borrowed this from `gopls`'s source code. Thank you for your service.
215
+
- LSP allows language servers to return different types for the same methods. Go doesn't like this so there are some ugly workarounds in `internal/protocol/interfaces.go`.
216
+
217
+
### Local Development and Snapshot Tests
218
+
219
+
There is a snapshot test suite that makes it a lot easier to try out changes to tools. These run actual language servers on mock workspaces and capture output and logs.
220
+
221
+
You will need the language servers installed locally to run them. There are tests for go, rust, python, and typescript.
160
222
161
223
```
162
-
env: {
163
-
"LOG_LEVEL": "DEBUG",
164
-
}
224
+
integrationtests/
225
+
├── tests/ # Tests are in this folder
226
+
├── snapshots/ # Snapshots of tool outputs
227
+
├── test-output/ # Gitignored folder showing the final state of each workspace and logs after each test run
228
+
└── workspaces/ # Mock workspaces that the tools run on
165
229
```
166
230
167
-
To get detailed LSP and application logs. 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.
168
-
169
-
The following features are on my radar:
170
-
171
-
-[x] Read definition
172
-
-[x] Get references
173
-
-[x] Apply edit
174
-
-[x] Get diagnostics
175
-
-[x] Code lens
176
-
-[x] Hover info
177
-
-[x] Rename symbol
178
-
-[ ] Code actions
179
-
-[ ] Better handling of context and cancellation
180
-
-[ ] Add LSP server configuration options and presets for common languages
181
-
-[ ] Create tools at a higher level of abstraction, combining diagnostics, code lens, hover, and code actions when reading definitions or references.
231
+
To update snapshots, run `UPDATE_SNAPSHOTS=true go test ./integrationtests/...`
0 commit comments