An MCP (Model Context Protocol) server that allows Claude Desktop to run Maven tests, read source files, and make code changes. Perfect for verifying refactoring and editing code directly from Claude Desktop.
- Concise Test Reports: Get clear ✅/❌ results without Maven's verbose output
- Smart Error Detection: Automatically identifies compilation issues, dependency problems, and test failures
- Helpful Hints: Suggests fixes for common issues (missing
-am
flag, Jackson errors, etc.) - Flexible Testing: Run all tests in a module or target specific test classes
- Read Source Files: View any file in your workspace (Kotlin, Java, XML, etc.)
- Edit Files: Modify source code directly from Claude Desktop
- Path Flexibility: Support for both absolute and workspace-relative paths
- Workspace Awareness: Configurable workspace directory with tilde expansion support
- Safe Operations: Read files before writing, with clear error messages
- Node.js (v18 or higher)
- Maven test wrapper script at
~/.claude/scripts/run-tests.sh
- A Maven project workspace
- Clone or download this repository:
git clone https://github.com/RuneLind/mcp-maven-test-runner.git
cd mcp-maven-test-runner
- Install dependencies and build:
npm install
npm run build
- Add the server to your Claude Desktop configuration.
Edit your Claude Desktop config file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:
%APPDATA%\Claude\claude_desktop_config.json
Add this configuration:
{
"mcpServers": {
"maven-test-runner": {
"command": "node",
"args": ["/absolute/path/to/mcp-maven-test-runner/build/index.js"],
"env": {
"WORKSPACE_DIR": "/Users/username/projects/my-maven-project",
"PATH": "/Users/username/.sdkman/candidates/maven/current/bin:/Users/username/.sdkman/candidates/java/current/bin:/usr/local/bin:/usr/bin:/bin"
}
}
}
}
Important:
- Replace
/absolute/path/to/mcp-maven-test-runner
with the actual path to this project - Replace
WORKSPACE_DIR
with your Maven project's root directory - Update
PATH
to include your Maven and Java installations:- Run
echo $PATH
in your terminal to get your full PATH - Make sure it includes paths to Maven (
mvn
) and Java (java
) - Common locations:
~/.sdkman/candidates/maven/current/bin
,/opt/homebrew/bin
,/usr/local/bin
- Run
- Tilde (
~
) expansion is supported inWORKSPACE_DIR
- Restart Claude Desktop
Once configured, Claude can run tests using natural language:
Run all tests in a module:
Run all tests in the domain module
Run a specific test class:
Run the UserServiceTest tests in the service module
Verify refactoring:
I just refactored the UserService class. Can you run the tests to make sure everything still works?
Read and edit files:
Show me the Behandling.kt file in the domain module
Update the Behandling class to add a new method for validation
The server provides three tools:
Run Maven tests for a specific module.
project
(required): Maven module name (e.g., "domain", "service", "common")testClass
(optional): Specific test class to run (e.g., "UserServiceTest")
Read the contents of a source file.
Parameters:
filePath
(required): Path to file (absolute or relative to workspace)- Example:
domain/src/main/kotlin/no/nav/melosys/domain/Behandling.kt
- Example:
~/source/nav/melosys-api/domain/src/main/kotlin/no/nav/melosys/domain/Behandling.kt
- Example:
Write or update a source file.
Parameters:
filePath
(required): Path to file (absolute or relative to workspace)content
(required): Complete new file content
✅ All tests passed (12 tests run in 8s)
❌ Tests failed
Tests run: 5, Failures: 2, Errors: 0, Skipped: 0
🔍 Failure details:
testCreateUser: Expected <2023-01-01> but was <2023-01-02>
testUpdateUser: NullPointerException at line 45
💡 Tip: Cross-module dependency issue. Try running with -am flag.
⚠️ No tests were run. Check your test configuration.
Here's a common workflow using all three tools:
-
Read existing code:
Show me the Behandling.kt file
-
Make changes:
Add a validation method that checks if the status is valid
(Claude will read the file, understand it, and write the updated version)
-
Verify changes:
Run the domain tests to make sure my changes work
-
Fix issues if needed:
The test failed - can you fix the validation logic?
- Claude calls the
run_tests
tool with a project name and optional test class - The MCP server executes
~/.claude/scripts/run-tests.sh
with appropriate parameters - The script handles Maven's complexity (clean builds, dependency resolution, etc.)
- The server parses the output and returns a concise summary to Claude
- Claude presents the results in a human-readable format
This is the most common issue. The MCP server runs in a minimal environment without your shell's PATH.
Solution: Add your PATH to the Claude Desktop config:
- Run
echo $PATH
in your terminal - Copy the entire PATH value
- Add it to the
env
section in your Claude Desktop config:
"env": {
"WORKSPACE_DIR": "/path/to/workspace",
"PATH": "/your/full/path/here"
}
- Make sure the PATH includes Maven and Java directories
- Restart Claude Desktop
- Verify the script exists at
~/.claude/scripts/run-tests.sh
- Check that the script is executable:
chmod +x ~/.claude/scripts/run-tests.sh
- Make the script executable:
chmod +x ~/.claude/scripts/run-tests.sh
- Consider running fewer tests or specific test classes
- Check if tests are hanging or taking too long
- Verify
WORKSPACE_DIR
in your Claude Desktop config - Use absolute paths (tilde
~
is supported) - Restart Claude Desktop after changing the config
- Check the config file syntax (valid JSON)
- Verify the absolute path to
build/index.js
- Check Claude Desktop logs for error messages
- Restart Claude Desktop
npm run build
npm run watch
npm update
mcp-maven-test-runner/
├── src/
│ └── index.ts # Main server implementation
├── build/ # Compiled JavaScript (generated)
├── package.json
├── tsconfig.json
└── README.md
This is a personal tool, but suggestions and improvements are welcome! Open an issue or submit a pull request.
ISC License - See LICENSE file for details