使用说明
Maven MCP服务器
一 MCP(模型上下文协议) 将AI助手连接到的服务器 Maven Central --使他们能够搜索库、查找版本、验证依赖关系并生成特定于构建工具的代码段。
工具
| 工具 | 说明 |
|---|---|
search_maven_artifacts |
按关键字搜索Maven Central |
list_maven_versions |
列出工件的版本(带预发布过滤) |
get_latest_version |
获取包含代码片段的最新稳定或预发布版本 |
check_version_exists |
验证Maven Central上是否存在特定版本 |
get_artifact_info |
获取包含最新版本和片段的完整工件元数据 |
入门指南
需要 Node.js >= 22.0.0.
git clone https://github.com/AmarjeetMalpotra/maven-mcp-server.git
cd maven-mcp-server
npm install
npm run build
生产运行:
npm start
在开发中运行(通过tsx自动重新加载):
npm run dev
整合
克劳德桌面版
添加 claude_desktop_config.json:
{
"mcpServers": {
"maven": {
"command": "node",
"args": ["/absolute/path/to/maven-mcp-server/dist/index.js"]
}
}
}
克劳德代码
claude mcp add --transport stdio maven -- node /absolute/path/to/maven-mcp-server/dist/index.js
GitHub Copilot命令行界面
添加 ~/.copilot/mcp-config.json 或使用 /mcp add 在CLI中:
{
"mcpServers": {
"maven": {
"type": "stdio",
"command": "node",
"args": ["/absolute/path/to/maven-mcp-server/dist/index.js"],
"tools": ["*"]
}
}
}
其他客户
用途 stdio传输,与大多数MCP客户端兼容。有关设置说明,请参阅代理的文档。
工具参考
search_maven_artifacts
按关键字在Maven Central中搜索工件。
| 名称 | 类型 | 必填 | 默认 | 描述 |
|---|---|---|---|---|
query |
string | 是 | -- | 搜索关键字 |
limit |
编号 | -- | 10 |
返回的最大结果数(1-100) |
“在Maven Central中搜索JSON解析库”
list_maven_versions
列出Maven工件的可用版本,按最新版本排序。
| 名称 | 类型 | 必填 | 默认 | 描述 |
|---|---|---|---|---|
groupId |
string | 是 | -- | Maven组ID |
artifactId |
string | 是 | -- | Maven artifactId |
limit |
编号 | -- | 20 |
返回的最大版本数(1-200) |
includePreRelease |
boolean | -- | true |
包括快照/测试版/RC版本 |
“列出com.google.guava:guava的最后10个稳定版本”
get_latest_version
获取所有主要构建工具的最新版本及其依赖代码片段。
| 名称 | 类型 | 必填 | 默认 | 描述 |
|---|---|---|---|---|
groupId |
string | 是 | -- | Maven组ID |
artifactId |
string | 是 | -- | Maven artifactId |
includePreRelease |
boolean | -- | false |
包括预发布版本 |
“杰克逊数据库的最新版本是什么?”
check_version_exists
验证Maven Central上是否存在特定版本。如果找到,则返回元数据和代码段。
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
groupId |
string | 是 | Maven组ID |
artifactId |
string | 是 | Maven artifactId |
version |
string | 是 | 要检查的版本字符串 |
“谷歌番石榴:番石榴33.2.1-jr版本存在吗?”
get_artifact_info
获取完整的工件元数据,包括最新版本、打包、版本计数、5个最新版本和依赖代码片段。
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
groupId |
string | 是 | Maven组ID |
artifactId |
string | 是 | Maven artifactId |
“告诉我Spring Boot启动器web工件的情况”
建筑
src/
├── index.ts # Entry point — stdio transport
├── server.ts # MCP server setup & tool registration
├── tools/
│ ├── helpers.ts # Shared tool response helpers
│ ├── search-artifacts.ts
│ ├── list-versions.ts
│ ├── get-latest-version.ts
│ ├── check-version-exists.ts
│ └── get-artifact-info.ts
├── api/
│ ├── maven-central.ts # Maven Central Search HTTP client
│ └── types.ts # API response type definitions
└── utils/
├── version.ts # Version parsing & comparison
└── formatter.ts # Output formatting helpers
数据流
MCP Client (Claude, Copilot, etc.)
│ JSON-RPC over stdio
▼
index.ts → StdioServerTransport
▼
server.ts → McpServer (tool registration)
▼
tools/*.ts → Zod validation + execution
▼
api/maven-central.ts → fetch()
▼
search.maven.org/solrsearch/select
设计决策
- stdio传输 --CLI集成MCP服务器的标准;与所有主要客户合作
- 本土的
fetch--零HTTP依赖 - Zod模式 --用于MCP工具发现的自动JSON模式生成的输入验证
- 每个文件一个工具 --每个工具都是一个自包含的模块,包含模式、元数据和执行器
- Maven Central Solr API -公共API,无需身份验证
发展
npm install # Install dependencies
npm run dev # Dev mode (auto-reload)
npm run build # Build for production
npm test # Run tests (Vitest)
npm run test:watch # Run tests in watch mode
添加新工具
- 创建
src/tools/my-tool.ts使用Zod模式、工具元数据对象和异步执行器函数。使用text()和toolError()从helpers.ts为了回应。 - 再出口自
src/tools/index.ts - 在中注册该工具
src/server.ts
Maven Central API
所有工具查询 Maven Central Solr搜索API:
| 操作 | 查询 |
|---|---|
| 关键字搜索 | q={keyword} |
| 工件查找 | q=g:{groupId} AND a:{artifactId} |
| 版本列表 | q=g:{groupId} AND a:{artifactId}&core=gav |
| 版本检查 | q=g:{groupId} AND a:{artifactId} AND v:{version}&core=gav |
无需身份验证。请遵守费率限制-API是共享基础设施。
贡献
- 分叉存储库
- 创建要素分支(
git checkout -b feature/my-tool) - 提交您的更改(
git commit -m 'Add my-tool') - 推到分支(
git push origin feature/my-tool) - 打开拉取请求
许可证
致谢
- 模型上下文协议 --LLM上下文交换的开放标准
- Maven Central -公共搜索API
- MCP TypeScript SDK --服务器和客户端实现