MCP OCI注册服务器
用于查询OCI容器注册表的模型上下文协议(MCP)服务器。与 fastmcp 该服务器提供与Docker Hub、GHCR和其他OCI兼容注册表等容器注册表交互的工具和提示。
特性
工具:
ping-健康检查工具list_oci_tags-列出OCI存储库的所有标签get_oci_details-获取清单详细信息,包括架构、摘要和注释
提示:
list_tags_prompt-列出存储库标签的说明list_architectures_prompt-列出支持架构的说明list_digests_prompt-检索图像摘要的说明list_annotations_prompt-OCI注释列表说明
附加功能:
- 自定义
NonValidatingRegistry绕过清单列表/索引的jsonschema验证的类 - 支持多架构图像
- 可选身份验证(用户名/密码)
- HTTP健康检查端点(
/healthz) - Docker支持与Docker compose开发
需求
- Python 3.11+
- Docker(可选,用于容器化部署)
安装
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -r requirements.txt用法
在stdio模式下运行(默认)
默认情况下,服务器在stdio上运行,这是大多数MCP客户端所期望的:
python server.py该进程将等待stdin/stdout上的JSON-RPC请求。通常,您不会手动运行它;它由MCP兼容客户端启动。
使用uvicorn运行(HTTP)
对于HTTP访问,请使用Makefile:
make run或手动:
uvicorn server:asgi_app --host 127.0.0.1 --port 8888使用Docker Compose运行
对于热重载开发:
make compose-up或手动:
docker compose up --build工具使用示例
列表标签:
# Using FastMCP Client
from fastmcp import Client, FastMCP
import server
client = Client(server.mcp)
async with client:
tags = await client.call_tool("list_oci_tags", {
"registry": "registry-1.docker.io",
"repository": "library/alpine"
})
print(tags.data) # ['latest', '3.22.2', 'edge', ...]获取OCI详细信息:
details = await client.call_tool("get_oci_details", {
"registry": "registry-1.docker.io",
"repository": "library/alpine",
"reference": "3.22.2"
})
print(details.data)
# {
# "digest": "sha256:...",
# "architectures": ["amd64", "arm64", ...],
# "annotations": {...}
# }MCP客户端配置(克劳德桌面)
在Claude Desktop MCP配置中添加条目(~/.cursor/mcp.json 或类似):
{
"mcpServers": {
"mcp-oci-registry": {
"command": "/path/to/.venv/bin/python",
"args": [
"/path/to/mcp-oci-registry/server.py"
],
"env": {}
}
}
}根据环境需要调整路径。
项目布局
mcp-oci-registry/
├── server.py # MCP server entrypoint
├── tools.py # Tool functions (ping, list_oci_tags, get_oci_details)
├── prompts.py # Prompt templates
├── registry.py # NonValidatingRegistry class
├── __init__.py # Package initialization
├── requirements.txt # Python dependencies
├── Dockerfile # Container image definition
├── docker-compose.yml # Development environment
├── Makefile # Common operations
└── tests/ # Test suite
├── test_tools.py
└── test_integration_http.py发展
运行测试:
make test可用目标:
make install-安装依赖项make run-使用uvicorn运行服务器make test-运行测试套件make docker-build-构建Docker镜像make docker-run-运行Docker容器make compose-up-从docker compose开始make compose-down-停止docker编写make compose-logs-查看docker编写日志
测试
该项目包括单元测试和集成测试:
- 单元测试 (
tests/test_tools.py)-使用模拟依赖关系测试单个工具功能 - 集成测试 (
tests/test_integration_http.py)-使用FastMCP客户端测试完整的MCP协议流
运行所有测试:
pytest -v延伸
添加新工具:
- 将该功能添加到
tools.py - 在中注册
server.py:mcp.tool(your_function)
添加新提示:
- 将提示功能添加到
prompts.py - 在中注册
server.py:mcp.prompt(your_prompt)
许可证
阿帕奇
