A Model Context Protocol (MCP) server that provides comprehensive Java code analysis capabilities through Eclipse JDT Language Server integration. This server enables AI assistants like Claude to perform advanced Java code operations including call hierarchies, type hierarchies, refactoring, and more.
The server provides 11 powerful tools for Java code analysis:
- get_class_info: Retrieve detailed information about Java classes
- list_classes: List all classes in the project
- find_references: Find all references to a symbol
- get_call_hierarchy: Analyze incoming and outgoing method calls
- get_type_hierarchy: Explore class inheritance relationships
- get_hover_info: Get detailed information about symbols
- get_completion: Get code completion suggestions
- get_definition: Navigate to symbol definitions
- rename_symbol: Rename classes, methods, and variables across the project
- format_code: Format Java code according to project standards
- get_diagnostics: Analyze code for errors and warnings
- Node.js 18 or higher
- Java 17 or higher
- Git
- Clone the repository:
git clone https://github.com/yourusername/java-mcp-server.git
cd java-mcp-server
- Install Eclipse JDT Language Server:
./setup-jdtls.sh
This downloads and extracts the Eclipse JDT.LS (approximately 44MB).
- Build the Java components:
mvn clean package
- Add the server to your Claude configuration:
claude mcp add java-analyzer -s local -- /path/to/java-mcp-server/java-mcp-jdtls.js
-
Restart Claude Desktop to load the server.
-
The server will automatically initialize when you start analyzing Java projects.
Run the server directly for testing:
./java-mcp-jdtls.js
The server communicates via JSON-RPC over stdin/stdout following the MCP protocol.
The server consists of three main components:
- Implements the MCP protocol
- Manages Eclipse JDT.LS lifecycle
- Translates between MCP and Language Server Protocol (LSP)
- Provides full Java language intelligence
- Handles project indexing and analysis
- Supports Gradle and Maven projects
- Fallback implementation for standalone operation
- Direct AST analysis capabilities
- Lightweight alternative for simple operations
java-mcp-server/
├── java-mcp-jdtls.js # Main MCP bridge to JDT.LS
├── java-mcp-server # Executable wrapper script
├── setup-jdtls.sh # JDT.LS installation script
├── src/ # Java source code
│ └── main/
│ └── java/
│ └── com/example/
│ ├── JavaMCPServer.java # Standalone Java server
│ ├── JavaProjectAnalyzer.java # Project analysis utilities
│ └── CallHierarchyAnalyzer.java # Call hierarchy analysis
├── pom.xml # Maven configuration
└── archive/ # Test files and old implementations
-
Initialization: When the server starts, it launches Eclipse JDT.LS as a subprocess and establishes LSP communication.
-
Project Detection: The server automatically detects the project root by looking for:
settings.gradle
orsettings.gradle.kts
(for multi-module Gradle projects)build.gradle
orbuild.gradle.kts
(for single-module Gradle projects)pom.xml
(for Maven projects)
-
Project Indexing: JDT.LS indexes the project, which may take 30-60 seconds for large projects. The server handles this asynchronously to prevent timeouts.
-
Tool Execution: When tools are called via MCP, the bridge translates requests to LSP calls and formats responses according to MCP specifications.
The server uses sensible defaults but can be configured through environment variables:
JAVA_HOME
: Path to Java installation (auto-detected if not set)JDTLS_HOME
: Path to JDT.LS installation (defaults to./jdtls
)
- Ensure Java 17+ is installed:
java -version
- Verify JDT.LS is installed:
ls -la jdtls/
- Check Node.js version:
node --version
(should be 18+)
- Large projects may take 30-60 seconds to index
- Check for
settings.gradle
in multi-module projects - Ensure Gradle wrapper is present (
gradlew
file)
- Wait for indexing to complete after initialization
- Verify the project compiles successfully
- Check that source paths are correctly configured
# Run Java tests
mvn test
# Test the MCP server
node java-mcp-jdtls.js < test-requests.json
- Implement the LSP call in
java-mcp-jdtls.js
- Add tool definition to the
tools
array - Handle the tool in the
callTool
function
MIT License - See LICENSE file for details
Contributions are welcome! Please feel free to submit a Pull Request.
- Eclipse JDT Language Server team for the excellent Java LSP implementation
- Anthropic for the Model Context Protocol specification
- The open-source Java community