MCP Maven Server

MCP Maven Server

Wraps Maven and Spring Boot operations for Claude Code, providing structured JSON output instead of raw build logs to save tokens and focus on code fixes.

Category
访问服务器

README

MCP Maven Server

An MCP (Model Context Protocol) server that wraps Maven and Spring Boot operations for Claude Code. Provides structured JSON output instead of raw build logs — saving tokens and allowing Claude to focus on code fixes.

Prerequisites

  • Node.js 18+ (with npm)
  • Maven 3.6+ (in PATH or configured via MCP_MAVEN_COMMAND)
  • Java 8–21+ (detected automatically)

Installation

# Clone
cd C:\Java
git clone https://github.com/Christian-Carminati/mcp-maven-server.git
cd mcp-maven-server

# Install and build
npm install
npm run build

Integration with Claude Code

1. MCP Server Configuration

Add to ~\.claude.json:

{
  "mcpServers": {
    "mcp-maven": {
      "type": "stdio",
      "command": "node",
      "args": ["C:\\Java\\mcp-maven-server\\dist\\index.js"],
      "env": {
        "MCP_MAVEN_TIMEOUT_MS": "300000",
        "MCP_MAVEN_MAX_LOG_LINES": "500",
        "MCP_MAVEN_COMMAND": "C:\\Program Files\\JetBrains\\IntelliJ IDEA 2025.3.6\\plugins\\maven\\lib\\maven3\\bin\\mvn.cmd"
      }
    }
  }
}

MCP_MAVEN_COMMAND is optional — set it if mvn is not in your system PATH. Omitting it makes the server look for mvn via PATH.

2. Block Maven via Bash (Permissions)

Add to ~\.claude\settings.json:

{
  "permissions": {
    "deny": ["Bash(mvn *)", "Bash(./mvnw *)", "Bash(java -jar *)"]
  }
}

3. PreToolUse Hook (Bash Interception)

Add to ~\.claude\settings.json:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "C:\\Java\\mcp-maven-server\\hooks\\maven-intercept.bat"
          }
        ]
      }
    ]
  }
}

4. CLAUDE.md Instruction

Add to ~\.claude\CLAUDE.md:

## Maven MCP Server
For ALL Maven operations (compile, test, verify, package, clean, spring-boot)
use ONLY the `mcp-maven` MCP tools. Available:
compileProject, runTests, runSingleTest, runSingleMethod, getFailedTests,
verifyProject, packageProject, cleanProject, executeMavenCommand,
getCoverageReport,
springBootRun, springBootStop, springBootRestart, springBootStatus, springBootLogs,
getProjectInfo, getJavaInfo, getMavenInfo, ping,
getCacheInfo, clearCache.

The Bash tool is blocked for mvn/java commands by permission rules.
Do not attempt to run mvn via Bash — it will be denied.

### Example
- ❌ "Run `mvn test` in the terminal"
- ✅ "Run tests using mcp-maven's runTests tool"
- ❌ "Compile with `mvn compile` via Bash"
- ✅ "Compile using mcp-maven's compileProject tool"
- ❌ "Start Spring Boot with `mvn spring-boot:run`"
- ✅ "Start Spring Boot using mcp-maven's springBootRun tool"

Available Tools

Build

Tool Description Key Parameters
compileProject Compile with structured error output (file, line, column, message) projectPath, module, profile
verifyProject Compile + test + integration-check projectPath, module, profile
packageProject Build JAR/WAR artifact (skips tests by default) projectPath, module, skipTests
cleanProject Clean build artifacts projectPath, module
executeMavenCommand Run arbitrary Maven with parsed error output projectPath, args[]

Test

Tool Description Key Parameters
runTests Execute tests with build cache (second call is instant) projectPath, module, profile, force, parallel
runSingleTest Run one test class projectPath, className
runSingleMethod Run one test method projectPath, className, methodName
getFailedTests Read failed tests without re-running projectPath, module
getTestReports Read existing reports from disk projectPath, module

runTests caching: By default, checks if any source/test files changed since the last run. If nothing changed, returns cached results instantly — no Maven execution. Use force: true to bypass cache and re-run all tests. Use parallel: true (default) for parallel execution (-T 2 -DforkCount=2). Response includes _cached: true flag when served from cache.

Cache Management

Tool Description
getCacheInfo Show which modules are cached and how old
clearCache Invalidate cache for a module (or all)

Coverage

Tool Description Key Parameters
getCoverageReport Read JaCoCo coverage report (lines, branches, methods per package) projectPath, generate (run jacoco:report first)

Spring Boot

Tool Description Key Parameters
springBootRun Start the application (detects port, captures logs) projectPath, profile, waitForStartup
springBootStop Stop gracefully (actuator shutdown first, SIGTERM fallback) projectPath, module
springBootRestart Restart the app projectPath, profile
springBootStatus Check status, port, PID, health endpoint projectPath, module
springBootLogs View recent log lines projectPath, lines

Project Info

Tool Description Key Parameters
getProjectInfo Detect project structure, modules, Java version projectPath
getJavaInfo Detect JDK version and vendor projectPath
getMavenInfo Get Maven version and home
ping Health check

projectPath: all build/test/project tools accept an optional projectPath parameter. Use it to target a specific module without changing Claude Code's working directory. Example: runTests({ projectPath: "C:/Java/BancomatPay/be-bancomatpay" })

Configuration

All settings are optional and configured via environment variables (set in the MCP server env block):

Variable Default Description
MCP_MAVEN_TIMEOUT_MS 300000 Build timeout in milliseconds
MCP_MAVEN_MAX_LOG_LINES 500 Max stdout lines to keep
MCP_MAVEN_SPRING_RING_BUFFER 500 Spring Boot log ring buffer size
MCP_MAVEN_SPRING_STARTUP_TIMEOUT 120000 Max wait for Spring Boot startup
MCP_MAVEN_CACHE_ENABLED true Enable/disable build caching
MCP_MAVEN_DEFAULT_PROFILE Default Maven profile
MCP_JAVA_HOME Override JDK path
MCP_MAVEN_COMMAND mvn Full path to mvn.cmd/mvn binary (e.g. IntelliJ-bundled Maven)
MCP_MAVEN_CACHE_ENABLED true Enable/disable build cache

Project Structure

src/
├── index.ts              # Entry point
├── core/                 # Server setup, types, config
│   ├── server.ts         # MCP server init, tool registration
│   ├── config.ts         # Environment variable loader
│   └── types.ts          # Shared TypeScript interfaces
├── project/              # Project discovery
│   ├── discovery.ts      # pom.xml upward scan, module resolution
│   ├── pom-parser.ts     # XML parser for pom.xml
│   └── java-env.ts       # JDK version detection (all sources)
├── maven/                # Maven execution
│   ├── runner.ts         # mvn process spawn with execa
│   ├── parser.ts         # Javac error parser (JDK 8–21)
│   ├── reports.ts        # Surefire/Failsafe XML reader
│   └── process-manager.ts # Process queue, cancel, timeout
├── tools/                # MCP tool implementations
│   ├── index.ts          # Tool registry
│   ├── compile.ts        # compileProject, getCompilationErrors
│   ├── test.ts           # runTests, runSingleTest, getFailedTests
│   ├── build.ts          # verifyProject, packageProject, cleanProject
│   ├── project.ts        # getProjectInfo, getJavaInfo, getMavenInfo, ping
│   └── spring-boot.ts    # Spring Boot lifecycle tools
└── utils/
    └── spring-boot-manager.ts  # Long-running process management

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选