Maven依赖查询服务器

一个轻量级的MCP服务器,允许大型语言模型查询Maven Central以获取依赖版本信息,包括检查特定版本是否存在以及获取最新版本。

  • by danielscholl
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 danielscholl/maven-mcp-server

使用说明

Maven检查MCP服务器

一个轻量级的MCP服务器,允许大型语言模型向Maven Central查询工件版本。此服务器允许Claude和其他LLM查找Maven依赖关系的最新版本,并检查是否存在特定版本。

特性

  • 查找任何Maven依赖项(库)的最新版本
  • 检查是否存在特定版本的依赖关系
  • 支持包装类型(罐、战争、pom等)
  • POM依赖关系的自动检测(带有-bom或-dependency后缀的工件)
  • 支持分类器
  • 正确的语义版本控制比较
  • 对单个请求中的多个依赖项进行批处理
  • 通过模型上下文协议(MCP)连接

安装

# Clone the repository
git clone https://github.com/danielscholl/maven-mcp-server.git
cd maven-mcp-server

# Install dependencies and the package
uv sync && uv pip install -e .

MCP服务器配置

要将此MCP服务器用于您的项目,请将以下内容添加到您的 .mcp.json:

{
  "mcpServers": {
    "maven-check": {
      "type": "stdio",
      "command": "uv",
      "args": ["run", "maven-check"],
      "env": {}
    }
  }
}

用法

启动服务器:

uv run maven-check

对于调试日志记录:

uv run maven-check --debug

工具

此MCP服务器提供五个工具:

1.获取最新版本

获取Maven依赖项的最新版本。

参数:

  • dependency (必需):依赖关系的格式为“groupId:artifactId”
  • packaging (可选):打包类型,默认为“jar”(自动使用“pom”作为带有-bom或-dependency后缀的依赖项)
  • classifier (可选):分类器(如果有的话)

示例:

{
  "dependency": "org.apache.commons:commons-lang3"
}
{
  "dependency": "org.springframework.boot:spring-boot-dependencies"
}

退货: 字符串形式的最新版本(例如“3.14.0”)

2.检查是否存在

检查Maven依赖项的特定版本是否存在。

参数:

  • dependency (必需):依赖关系的格式为“groupId:artifactId”
  • version (必填):要检查的版本
  • packaging (可选):打包类型,默认为“jar”(自动使用“pom”作为带有-bom或-dependency后缀的依赖项)
  • classifier (可选):分类器(如果有的话)

示例:

{
  "dependency": "org.apache.commons:commons-lang3",
  "version": "3.14.0"
}
{
  "dependency": "org.springframework.boot:spring-boot-dependencies",
  "version": "3.2.0"
}

退货: 一个布尔值,指示版本是否存在(“true”或“false”)

3.find_maven_latest_component_version

获取基于语义版本控制组件(主、次或补丁)的Maven依赖项的最新版本。

参数:

  • dependency (必需):依赖关系的格式为“groupId:artifactId”
  • version (必填):语义版本格式的版本(MAJOR.MINOR.PATCH)
  • target_component (必填):查找最新版本的组件,其中之一:“主要”、“次要”、“补丁”
  • packaging (可选):打包类型,默认为“jar”(自动使用“pom”作为带有-bom或-dependency后缀的依赖项)
  • classifier (可选):分类器(如果有的话)

示例:

{
  "dependency": "org.apache.commons:commons-lang3",
  "version": "3.12.0",
  "target_component": "minor"
}
{
  "dependency": "org.springframework.boot:spring-boot-dependencies",
  "version": "3.1.0",
  "target_component": "minor"
}

退货: 字符串形式的最新版本(例如“3.14.0”)

按目标组件划分的行为

  • 主要的:返回最高可用主版本(所有版本)
  • 较小的:返回给定主要版本中的最高次要版本
  • 补丁:返回给定主版本和次版本中的最高补丁版本

4.获取所有最新版本

在单个调用中获取所有语义版本控制组件(主、次、补丁)的最新版本。

参数:

  • dependency (必需):依赖关系的格式为“groupId:artifactId”
  • version (必填):语义版本格式的版本(MAJOR.MINOR.PATCH)
  • packaging (可选):打包类型,默认为“jar”(自动使用“pom”作为带有-bom或-dependency后缀的依赖项)
  • classifier (可选):分类器(如果有的话)

示例:

{
  "dependency": "org.apache.commons:commons-lang3",
  "version": "3.12.0"
}
{
  "dependency": "org.springframework.boot:spring-boot-dependencies",
  "version": "3.1.0"
}

退货: 一个JSON对象,包含每个组件的最新版本:

{
  "latest_major_version": "3.14.0",
  "latest_minor_version": "3.12.0",
  "latest_patch_version": "3.12.0"
}

5.批次_版本_检查

在单个批处理请求中检查多个Maven依赖项的最新版本,从而在处理包含多个依赖项的项目时减少API调用的数量。

参数:

  • dependencies (必填):要检查的依赖对象列表,每个对象包含:
    • dependency (必需):依赖关系的格式为“groupId:artifactId”
    • version (必填):任何支持格式的版本
    • packaging (可选):打包类型,默认为“jar”(自动使用“pom”作为带有-bom或-dependency后缀的依赖项)
    • classifier (可选):分类器(如果有的话)

例子:

{
  "dependencies": [
    {
      "dependency": "org.apache.commons:commons-lang3",
      "version": "3.12.0" 
    },
    {
      "dependency": "org.springframework.boot:spring-boot-dependencies", 
      "version": "3.1.0"
    },
    {
      "dependency": "org.json:json",
      "version": "20231013"
    }
  ]
}

退货: 一个JSON对象,包含每个依赖项的摘要和结果:

{
  "summary": {
    "total": 3,
    "success": 3,
    "failed": 0
  },
  "dependencies": [
    {
      "dependency": "org.apache.commons:commons-lang3",
      "status": "success",
      "versions": {
        "latest_major_version": "3.14.0",
        "latest_minor_version": "3.12.0",
        "latest_patch_version": "3.12.0"
      }
    },
    {
      "dependency": "org.springframework.boot:spring-boot-dependencies",
      "status": "success",
      "versions": {
        "latest_major_version": "3.2.0",
        "latest_minor_version": "3.1.5",
        "latest_patch_version": "3.1.0"
      }
    },
    {
      "dependency": "org.json:json",
      "status": "success",
      "versions": {
        "latest_major_version": "20240303",
        "latest_minor_version": "20240303",
        "latest_patch_version": "20240303"
      }
    }
  ]
}

运作原理

服务器的工作原理如下:

  1. 查询Maven Central Repository搜索API
  2. 解析和验证依赖关系格式
  3. 自动检测POM依赖关系:
    • 用“-bom”或“-dependency”后缀标识工件
    • 对这些工件使用“pom”包装类型
  4. 有关最新版本的查询:
    • 获取工件的所有版本
    • 使用适当的语义版本控制规则对它们进行排序
    • 返回最新版本
  5. 对于版本存在性检查:
    • 直接向Maven Central查询特定版本
    • 返回是否存在
  6. 对于批量版本检查:
    • 在一次调用中处理多个依赖关系请求
    • 返回每个依赖项的详细结果,并显示成功/错误状态
    • 提供成功和失败请求计数的摘要

发展

测试

运行所有测试:

uv run pytest

与克劳德一起使用

设置好服务器并连接Claude Code后,您可以使用以下工具:

  1. 获取Maven依赖项的最新版本:

    What is the latest version of org.springframework:spring-framework-bom 
    
  2. 检查是否存在特定版本:

    Does version 3.14.0 of org.apache.commons:commons-lang3 exist?
    
  3. 获取最新补丁版本:

    I'm using version 2.0.2 of org.springdoc:springdoc-openapi-starter-webmvc-ui what is the latest patch?
    
  4. 处理BOM和POM依赖关系:

    What is the latest version of org.springframework.boot:spring-boot-dependencies?
    

    服务器会自动检测带有“-dependency”或“-bom”后缀的依赖关系,并使用POM打包类型。

  5. 在一次通话中获取所有最新版本:

    Check latest versions org.springframework.boot:spring-boot-dependencies (currently using 3.1.0)
    

    这将在一次调用中返回最新的主要、次要和补丁版本,从而有效地了解升级选项。

  6. 使用批处理一次检查多个依赖关系:

    I need to check the latest versions for:
    - org.apache.commons:commons-lang3 (currently using 3.12.0)
    - org.springframework.boot:spring-boot-dependencies (currently using 3.1.0)
    - org.json:json (currently using 20231013)
    

    批处理工具检查一个请求中的所有依赖关系,提高了具有多个依赖关系的项目的效率。