Nexus 存储库查询服务器

为 Sonatype Nexus Repository Manager 3(OSS 和 Pro)提供 MCP(Model Context Protocol)服务,支持查询 Maven、Python(PyPI)和 Docker 存储库。

  • by addozhang
  • Python
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 addozhang/nexus-mcp-server

使用说明

Nexus MCP服务器

英语| 简体中文

Sonatype Nexus Repository Manager 3(OSS和Pro)的MCP(模型上下文协议)服务器,使AI助手能够查询Maven、Python(PyPI)和Docker存储库。

特性

  • 多种运输方式 -SSE(默认)或流式http传输
  • HTTP流传输 -具有报头身份验证的现代基于SSE的传输
  • 按请求身份验证 -通过HTTP标头传递的凭据(没有硬编码的秘密)
  • Maven支持 -搜索工件、列出版本、获取元数据
  • Python支持 -搜索包、列出版本、获取元数据
  • Docker支持 -列出图像、获取标签、图像元数据
  • FastMCP框架 -快速、现代的Python实现

兼容性

支持的Nexus版本:

  • ✅ Nexus存储库管理器3.x开源软件
  • ✅ Nexus存储库管理器3.x专业版

此服务器使用标准Nexus REST API v1(/service/rest/v1),有OSS和Pro两个版本。

可用工具

此MCP服务器提供 6个只读工具 查询Nexus存储库:

📦 Maven工具

工具 说明 参数
search_maven_artifact 搜索Maven工件 group_id, artifact_id, version, repository
get_maven_versions 获取Maven工件的所有版本(分页) group_id, artifact_id, repository, page_size, continuation_token

🐍 Python/PyPI工具

工具 说明 参数
search_python_package 搜索Python包 name, repository
get_python_versions 获取Python包的所有版本(分页) package_name, repository, page_size, continuation_token

🐳 Docker工具

工具 说明 参数
list_docker_images 列出存储库中的所有Docker镜像 repository
get_docker_tags 获取Docker镜像的所有标签 repository, image_name

注: 所有工具都是只读的,可以安全使用。不支持写操作(创建/更新/删除)。

安装

来源

# Clone the repository
git clone https://github.com/your-org/nexus-mcp-server.git
cd nexus-mcp-server

# Create virtual environment
python -m venv venv
source venv/bin/activate  # or venv/bin/activate.fish

# Install in development mode
pip install -e ".[dev]"

# Run the server (defaults to http://0.0.0.0:8000)
python -m nexus_mcp

使用Docker

# Quick start
docker run -p 8000:8000 addozhang/nexus-mcp-server:latest

# Or use docker-compose
docker-compose up

# See DOCKER.md for detailed deployment guide

有关详细的部署指南,请参阅 医生.md.

配置

服务器配置

可以使用命令行参数或环境变量配置服务器:

变量 CLI参数 描述 默认值
NEXUS_MCP_HOST --host 要绑定的主机 0.0.0.0
NEXUS_MCP_PORT --port 要收听的端口 8000
NEXUS_MCP_TRANSPORT --transport 运输方式(sse 或 streamable-http) sse

优先: CLI参数>环境变量>默认值

运输方式:

  • sse (默认)-服务器发送事件传输,与大多数MCP客户端兼容
  • streamable-http -为喜欢此协议的客户端提供流式HTTP传输

运行服务器

本地开发

# SSE mode (default)
python -m nexus_mcp

# Streamable-HTTP mode
python -m nexus_mcp --transport streamable-http

# Custom port
python -m nexus_mcp --port 9000

# Custom host and port
python -m nexus_mcp --host 127.0.0.1 --port 9000

使用Docker

# SSE mode (default)
docker run -p 8000:8000 addozhang/nexus-mcp-server:latest

# Streamable-HTTP mode
docker run -e NEXUS_MCP_TRANSPORT=streamable-http -p 8000:8000 addozhang/nexus-mcp-server:latest

# Custom port
docker run -e NEXUS_MCP_PORT=9000 -p 9000:9000 addozhang/nexus-mcp-server:latest

# Or use docker-compose
docker-compose up

# See DOCKER.md for detailed deployment guide

有关详细的部署指南,请参阅 医生.md.

通过HTTP标头进行身份验证

凭据作为HTTP标头随每个请求传递:

标题 描述 示例 必填
X-Nexus-Url Nexus实例URL https://nexus.company.com 是的
X-Nexus-Username 用户名 admin 是的
X-Nexus-Password 密码 secret123 是的
X-Nexus-Verify-SSL 验证SSL证书 false 否(默认值: true)

备注:设置 X-Nexus-Verify-SSL: false 当使用自签名证书连接到自托管Nexus实例时。

MCP客户端配置(克劳德桌面)

添加到您的Claude Desktop配置(~/.config/claude/claude_desktop_config.json):

{
  "mcpServers": {
    "nexus": {
      "url": "http://localhost:8000/mcp",
      "headers": {
        "X-Nexus-Url": "https://nexus.company.com",
        "X-Nexus-Username": "admin",
        "X-Nexus-Password": "secret123"
      }
    }
  }
}

对于自签名证书:

{
  "mcpServers": {
    "nexus": {
      "url": "http://localhost:8000/mcp",
      "headers": {
        "X-Nexus-Url": "https://nexus.company.com",
        "X-Nexus-Username": "admin",
        "X-Nexus-Password": "secret123",
        "X-Nexus-Verify-SSL": "false"
      }
    }
  }
}

MCP客户端配置(其他客户端)

对于支持HTTP传输的其他MCP客户端:

{
  "url": "http://localhost:8000/mcp",
  "headers": {
    "X-Nexus-Url": "https://nexus.company.com",
    "X-Nexus-Username": "your-username",
    "X-Nexus-Password": "your-password"
  }
}

MCP工具

Maven工具

工具 说明 参数
search_maven_artifact 搜索Maven存储库 group_id, artifact_id, version, repository
get_maven_versions 获取工件的版本(分页) group_id, artifact_id, repository, page_size (默认值50), continuation_token

分页示例:

# First page
response = get_maven_versions("com.example", "myapp")
# response contains: versions, hasMore, continuationToken (if hasMore is true)

# Next page
if response["hasMore"]:
    next_response = get_maven_versions(
        "com.example", 
        "myapp", 
        continuation_token=response["continuationToken"]
    )

Python工具

工具 说明 参数
search_python_package 搜索Python包 name, repository
get_python_versions 获取包的版本(分页) package_name, repository, page_size (默认值50), continuation_token

分页: 与Maven模式相同-检查 hasMore 和使用 continuationToken 后续页面。

Docker工具

工具 说明 参数
list_docker_images 在存储库中列出图像 repository
get_docker_tags 获取图像的标签 repository, image_name

发展

运行测试

pytest tests/ -v

类型检查

mypy src/

代码检查

ruff check src/ tests/

项目结构

nexus-mcp-server/
├── specs/                    # Requirements documents
│   ├── authentication.md
│   ├── maven-support.md
│   ├── python-support.md
│   ├── docker-support.md
│   ├── mcp-architecture.md
│   └── http-streaming.md
├── src/nexus_mcp/           # Source code
│   ├── __init__.py          # Package init with version
│   ├── __main__.py          # CLI entry point
│   ├── server.py            # FastMCP server with tools
│   ├── nexus_client.py      # Nexus REST API client
│   ├── auth.py              # Authentication types
│   ├── dependencies.py      # Credential extraction from headers
│   └── tools/               # Tool implementations
│       ├── __init__.py
│       └── implementations.py
├── tests/                   # Test suite
│   ├── conftest.py          # Fixtures and sample data
│   ├── test_nexus_client.py # Client unit tests
│   ├── test_tools.py        # Tool integration tests
│   └── test_http_transport.py # HTTP transport tests
├── AGENTS.md                # Operational guide
├── IMPLEMENTATION_PLAN.md   # Task tracking
└── pyproject.toml           # Python project metadata

故障排除

连接错误

  • 验证MCP服务器是否正在运行(python -m nexus_mcp)
  • 检查端口8000是否可访问
  • 验证 X-Nexus-Url 标题正确且可访问
  • 检查与Nexus实例的网络连接
  • 确保HTTPS证书有效(或对本地实例使用HTTP)

身份验证错误

  • 验证 X-Nexus-Username 和 X-Nexus-Password 标题正确
  • 确保用户具有存储库的读取权限
  • 检查Nexus实例是否需要特定的身份验证方法

缺少凭据错误

  • 确保所有三个标题都已设置: X-Nexus-Url, X-Nexus-Username, X-Nexus-Password
  • 检查您的MCP客户端是否支持HTTP标头

空结果

  • 验证存储库名称是否正确
  • 检查Nexus中是否存在该包/工件
  • 对于Python包,尝试连字符和下划线命名

运输方式问题

可流式传输http的连接超时:

  • 确保您的客户端支持流式http传输
  • 请尝试改用SSE模式: python -m nexus_mcp --transport sse
  • 检查防火墙规则是否允许HTTP连接

工具未出现:

  • SSE和流式http都公开了相同的工具
  • 验证标头是否正确传递(X-Nexus-*)
  • 检查服务器日志中的身份验证错误

许可证

麻省理工学院

贡献

欢迎投稿!请在提交PR之前运行测试和linting。