一个Java MCP(模型上下文协议)服务器,利用LSP4J包裹JDTLS(Eclipse JDT语言服务器),为像Claude这样的AI助手提供Java IDE功能。
概览
一个Java MCP(模型上下文协议)服务器,利用LSP4J包裹JDTLS(Eclipse JDT语言服务器),为像Claude这样的AI助手提供Java IDE功能。 该MCP服务器提供以下工具: - Java 21+ - Maven 3.8+ - 安装JDTLS(例如,通过自制软件:brew安装jdtls) 这样在目标/lsp4j-mcp-1.0.0-SNAPSHOT.jar就形成了一个阴影的JAR。 构建多阶段镜像。它包含 Java 21、着色 MCP 服务器和一个钉顶的 Eclipse JDTLS 发行版: 在 stdio 上运行,然后在 /workspace 挂载 Java 项目: 在 Linux 上,当语言服务器需要将项目元数据写入已挂载的工作区时,可以使用主机 UID/GID: 服务器使用 stdio,因此镜像不暴露任何网络端口。容器日志写入 stderr,而 stdout 则保留给 MCP 协议。镜像默认运行为 UID/GID 10001,预计至少有 1 GB 容器内存。
概述(AI 翻译)
一个Java MCP(模型上下文协议)服务器,利用LSP4J包裹JDTLS(Eclipse JDT语言服务器),为像Claude这样的AI助手提供Java IDE功能。
特色
该MCP服务器提供以下工具:
| 工具 | 描述 |
|---|---|
find_symbols |
按名称搜索 Java 符号(类、方法、字段) |
[find_references |
查找给定文件位置上对符号的所有引用 |
find_definition |
前往符号定义 |
document_symbols |
获取 Java 文件中定义的所有符号 |
find_interfaces_with_method |
查找所有包含带有名字的方法的接口 |
先修条件
- Java 21+
- Maven 3.8+
- 安装JDTLS(例如,通过自制软件:
brew install jdtls)
建造
这会在target/lsp4j-mcp-1.0.0-SNAPSHOT.jar处生成一个阴影JAR。
用途
选项1:运行脚本
选项2:直接Java命令
示例:
选项3:Claude代码MCP配置
补充到你的.mcp.json:
选项4:Docker
构建多阶段镜像。它包括Java 21、着色MCP服务器,以及 置顶Eclipse JDTLS分发:
在 stdio 上运行,并将 Java 项目挂载于 /workspace:
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
LSP4J-MCP Server
A Java MCP (Model Context Protocol) server that wraps JDTLS (Eclipse JDT Language Server) using LSP4J to provide Java IDE features to AI assistants like Claude.
Features
This MCP server exposes the following tools:
| Tool | Description |
|---|---|
find_symbols |
Search for Java symbols (classes, methods, fields) by name |
find_references |
Find all references to a symbol at a given file location |
find_definition |
Go to the definition of a symbol |
document_symbols |
Get all symbols defined in a Java file |
find_interfaces_with_method |
Find all interfaces containing a method with a given name |
Prerequisites
- Java 21+
- Maven 3.8+
- JDTLS installed (e.g., via Homebrew:
brew install jdtls)
Build
mvn clean package
This creates a shaded JAR at target/lsp4j-mcp-1.0.0-SNAPSHOT.jar.
Usage
Option 1: Run Script
./run.sh /path/to/your/java/project
Option 2: Direct Java Command
java -jar target/lsp4j-mcp-1.0.0-SNAPSHOT.jar
Example:
java -jar target/lsp4j-mcp-1.0.0-SNAPSHOT.jar /Users/me/projects/myapp jdtls
Option 3: Claude Code MCP Configuration
Add to your .mcp.json:
{
"mcpServers": {
"java-lsp": {
"command": "java",
"args": [
"-jar",
"/path/to/LSP4J-MCP/target/lsp4j-mcp-1.0.0-SNAPSHOT.jar",
"/path/to/your/java/project",
"jdtls"
],
"env": {
"LOG_FILE": "/tmp/lsp4j-mcp.log"
}
}
}
}
Option 4: Docker
Build the multi-stage image. It includes Java 21, the shaded MCP server, and a pinned Eclipse JDTLS distribution:
docker build -t lsp4j-mcp:local .
Run it over stdio and mount the Java project at /workspace:
docker run --rm -i \
--mount type=bind,source=/absolute/path/to/java/project,target=/workspace \
lsp4j-mcp:local
On Linux, use the host UID/GID when the language server needs to write project metadata into the mounted workspace:
docker run --rm -i \
--user "$(id -u):$(id -g)" \
--mount type=bind,source=/absolute/path/to/java/project,target=/workspace \
lsp4j-mcp:local
Example MCP configuration:
{
"mcpServers": {
"java-lsp-docker": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"--mount",
"type=bind,source=/absolute/path/to/java/project,target=/workspace",
"lsp4j-mcp:local"
]
}
}
}
The server uses stdio, so the image exposes no network port. Container logs are
written to stderr while stdout remains reserved for the MCP protocol. The image
runs as UID/GID 10001 by default and expects at least 1 GB of container memory.
Project Structure
LSP4J-MCP/
├── pom.xml # Maven build configuration
├── run.sh # Startup script
安装
docker run --rm -i --mount type=bind source=/absolute/path/to/java/project target=/workspace lsp4j-mcp:local配置
{
"mcpServers": {
"java-lsp": {
"command": "java",
"args": [
"-jar",
"/path/to/LSP4J-MCP/target/lsp4j-mcp-1.0.0-SNAPSHOT.jar",
"/path/to/your/java/project",
"jdtls"
],
"env": {
"LOG_FILE": "/tmp/lsp4j-mcp.log"
}
}
}
}