Maven依赖版本查找器

一个用于查询Maven中央仓库依赖最新版本的服务,支持Gradle和Maven格式,可作为独立Web服务器或Docker容器运行。

  • by Incept5
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 incept5/mvn-version-server

使用说明

Maven依赖版本查找器MCP服务器

此MCP服务器允许您查询Maven Central Repository以查找最新版本的依赖关系。它可以被其他AI工具用来构建它们的依赖文件。

特性

  • 查询Maven Central Repository以查找依赖项的最新版本
  • 支持Gradle和Maven依赖格式
  • 可以作为独立的web服务器在本地运行,也可以在Docker容器中运行
  • 使用Python构建

安装

先决条件

  • Python 3.8+
  • Docker(可选,用于容器化部署)

本地设置

  1. 克隆此存储库
  2. 安装依赖项:
    pip install -r requirements.txt
    
  3. 运行服务器:
    python src/main.py
    

Docker设置

  1. 构建Docker镜像:
    docker build -t maven-dependency-finder .
    
  2. 运行容器:
    docker run -p 8000:8000 maven-dependency-finder
    

API使用

查找最新版本

端点: /api/find-latest-version

方法: 发布

请求正文:

{
  "dependency": "org.springframework:spring-core:5.3.0"
}

或

{
  "dependency": "implementation 'org.springframework:spring-core:5.3.0'"
}

答复:

{
  "groupId": "org.springframework",
  "artifactId": "spring-core",
  "latestVersion": "6.1.3",
  "currentVersion": "5.3.0",
  "repository": "central"
}

搜索工件

端点: /api/search-artifacts

方法: 发布

请求正文:

{
  "query": "spring-boot",
  "rows": 20,
  "start": 0,
  "groupId": "org.springframework.boot",
  "artifactId": "spring-boot",
  "version": "3.0.0",
  "packaging": "jar",
  "classifier": "javadoc"
}

注: 必须至少提供一个搜索参数(查询、组ID、artifactId、版本、包装或分类器)。

高级搜索示例:

  1. 基本文本搜索:
{
  "query": "spring-boot"
}
  1. 按Maven坐标搜索:
{
  "groupId": "org.springframework.boot",
  "artifactId": "spring-boot"
}
  1. 全坐标搜索(类似于Sonatype REST API):
{
  "groupId": "com.google.inject",
  "artifactId": "guice",
  "version": "3.0",
  "packaging": "jar",
  "classifier": "javadoc"
}

答复:

{
  "response": {
    "numFound": 123,
    "start": 0,
    "docs": [
      {
        "g": "org.springframework.boot",
        "a": "spring-boot",
        "v": "3.2.0",
        "latestVersion": "3.2.0",
        "repositoryId": "central",
        "p": "jar",
        "timestamp": 1701234567890
      },
      // More results...
    ]
  }
}

WebSocket支持

此服务器实现WebSocket通信,以实现Maven Central Repository的实时查询。有两种可用方法:

find_latest_version

// Example WebSocket request
{
  "id": "request-id",
  "method": "find_latest_version",
  "params": {
    "dependency": "org.springframework:spring-core:5.3.0"
  }
}

search_artifacts

// Example WebSocket request
{
  "id": "request-id", 
  "method": "search_artifacts",
  "params": {
    "query": "spring-boot",
    "rows": 20,
    "start": 0
  }
}

使用Maven坐标的高级搜索示例:

// Example WebSocket request with coordinates
{
  "id": "request-id", 
  "method": "search_artifacts",
  "params": {
    "groupId": "com.google.inject",
    "artifactId": "guice",
    "version": "3.0",
    "packaging": "jar",
    "classifier": "javadoc",
    "rows": 20,
    "start": 0
  }
}

客户示例

存储库包括示例客户端以演示用法:

  • examples/mcp_client.py -用于查找最新版本的Python客户端
  • examples/mcp_client.js -用于查找最新版本的JavaScript客户端
  • examples/search_client.py -用于搜索工件的Python客户端

文档

许可证

麻省理工学院