UniProt MCP服务器
](https://pypi.org/project/uniprot-mcp/) ](https://pypi.org/project/uniprot-mcp/)  
提供无缝访问的模型上下文协议(MCP)服务器 UniProtKB 蛋白质数据。查询蛋白质条目、序列、基因本体注释,并通过为LLM代理设计的类型化、弹性接口执行ID映射。
✨ 特性
- 🔌 双重运输:Stdio用于本地开发,Streamable HTTP用于远程部署
- 📊 丰富的数据访问:获取包含序列、特征、GO注释、交叉引用和分类学的完整蛋白质条目
- 🔍 高级搜索:全文搜索,按评论状态、生物、关键字等进行过滤
- 🔄 ID映射:使用进度跟踪在200多种数据库标识符类型之间进行转换
- 🛡️ 生产就绪:指数回退自动重试,CORS支持,Prometheus指标
- 📝 键入响应:结构化Pydantic模型确保数据一致性
- 🎯 MCP图元:为代理工作流设计的资源、工具和提示
🚀 快速开始
安装
pip install uniprot-mcp运行服务器
地方发展(stdio):
uniprot-mcp远程部署(HTTP):
uniprot-mcp-http --host 0.0.0.0 --port 8000HTTP服务器提供:
- MCP端点:
http://localhost:8000/mcp - 健康检查:
http://localhost:8000/healthz - 韵律学:
http://localhost:8000/metrics(普罗米修斯格式)
使用MCP检查员进行测试
npx @modelcontextprotocol/inspector uniprot-mcp📚 MCP图元
资源
通过URI模式访问静态或动态数据:
| URI | 描述 |
|---|---|
uniprot://uniprotkb/{accession} | 用于任何登录的原始UniProtKB条目JSON |
uniprot://help/search | 搜索查询语法文档 |
工具
执行操作并检索键入的数据:
| 工具 | 参数 | 返回 | 描述 |
|---|---|---|---|
fetch_entry | accession, fields? | Entry | 获取包含所有注释的完整蛋白质条目 |
get_sequence | accession | Sequence | 获取具有长度和元数据的蛋白质序列 |
search_uniprot | query, size, reviewed_only, fields?, sort?, include_isoform | SearchHit[] | 具有高级过滤功能的全文搜索 |
map_ids | from_db, to_db, ids | MappingResult | 在200多个数据库之间转换标识符 |
fetch_entry_flatfile | accession, version, format | string | 检索历史条目版本(txt/fasta) |
进度跟踪: map_ids 报告长时间运行的作业的进度(0.0→1.0)。
提示
常见工作流的预构建模板:
- 蛋白质概述:根据UniProt登录生成结构化摘要,包括生物体、功能、GO术语和显著特征。
🔧 配置
环境变量
| 变量 | 默认值 | 描述 |
|---|---|---|
UNIPROT_ENABLE_FIELDS | unset | 请求最小字段子集以减小有效载荷大小 |
UNIPROT_LOG_LEVEL | info | 日志记录级别: debug, info, warning, error |
UNIPROT_LOG_FORMAT | plain | 日志格式: plain 或 json |
UNIPROT_MAX_CONCURRENCY | 8 | 最大并发UniProt API请求数 |
MCP_HTTP_HOST | 0.0.0.0 | HTTP服务器绑定地址 |
MCP_HTTP_PORT | 8000 | HTTP服务器端口 |
MCP_HTTP_LOG_LEVEL | info | Uvicorn测井水位 |
MCP_HTTP_RELOAD | 0 | 启用自动重新加载: 1 或 true |
MCP_CORS_ALLOW_ORIGINS | * | CORS允许的来源(逗号分隔) |
MCP_CORS_ALLOW_METHODS | GET,POST,DELETE | CORS允许的方法 |
MCP_CORS_ALLOW_HEADERS | * | CORS允许的标头 |
CLI标志
# HTTP server flags
uniprot-mcp-http --host 127.0.0.1 --port 9000 --log-level debug --reload📖 使用示例
摄入蛋白质
# Using MCP client
result = await session.call_tool("fetch_entry", {
"accession": "P12345"
})
# Returns structured Entry with:
# - primaryAccession, protein names, organism
# - sequence (length, mass, sequence string)
# - features (domains, modifications, variants)
# - GO annotations (biological process, molecular function, cellular component)
# - cross-references to other databases寻找蛋白质
# Search reviewed human proteins
result = await session.call_tool("search_uniprot", {
"query": "kinase AND organism_id:9606",
"size": 50,
"reviewed_only": True,
"sort": "annotation_score"
})
# Returns list of SearchHit objects with accessions and scores映射标识符
# Convert UniProt IDs to PDB structures
result = await session.call_tool("map_ids", {
"from_db": "UniProtKB_AC-ID",
"to_db": "PDB",
"ids": ["P12345", "Q9Y6K9"]
})
# Returns MappingResult with successful and failed mappings🛠️ 发展
先决条件
- Python 3.11或3.12
- 紫外线 (推荐)或pip
设置
# Clone the repository
git clone https://github.com/josefdc/Uniprot-MCP.git
cd Uniprot-MCP
# Install dependencies
uv sync --group dev
# Install development tools
uv tool install ruff
uv tool install mypy运行测试
# Run all tests with coverage
uv run pytest --maxfail=1 --cov=uniprot_mcp --cov-report=term-missing
# Run specific test file
uv run pytest tests/unit/test_parsers.py -v
# Run integration tests only
uv run pytest tests/integration/ -v代码质量
# Lint
uv tool run ruff check .
# Format
uv tool run ruff format .
# Type check
uv tool run mypy src
# Run all checks
uv tool run ruff check . && \
uv tool run ruff format --check . && \
uv tool run mypy src && \
uv run pytest本地开发服务器
# Stdio server
uv run uniprot-mcp
# HTTP server with auto-reload
uv run python -m uvicorn uniprot_mcp.http_app:app --reload --host 127.0.0.1 --port 8000🏗️ 建筑
src/uniprot_mcp/
├── adapters/ # UniProt REST API client and response parsers
│ ├── uniprot_client.py # HTTP client with retry logic
│ └── parsers.py # Transform UniProt JSON → Pydantic models
├── models/
│ └── domain.py # Typed data models (Entry, Sequence, etc.)
├── server.py # MCP stdio server (FastMCP)
├── http_app.py # MCP HTTP server (Starlette + CORS)
├── prompts.py # MCP prompt templates
└── obs.py # Observability (logging, metrics)
tests/
├── unit/ # Unit tests for parsers, models, tools
├── integration/ # End-to-end tests with VCR fixtures
└── fixtures/ # Test data (UniProt JSON responses)📦 出版
此服务器发布到:
- PyPI: Unibrot mcp
- MCP注册表:
建筑与出版
# Build distribution packages
uv build
# Publish to PyPI (requires token)
uv publish --token pypi-YOUR_TOKEN
# Publish to MCP Registry (requires GitHub auth)
mcp-publisher login github
mcp-publisher publish看 docs/register.md 有关注册表发布的详细说明。
🤝 贡献
欢迎投稿!拜托:
贡献者快速入门:
- 复刻仓库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 通过测试进行更改
- 运行质量检查:
uv tool run ruff check . && uv tool run mypy src && uv run pytest - 使用提交 约定式提交 (
feat:,fix:,docs:等等) - 推送并打开拉取请求
📄 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
🙏 致谢
- UniProt联盟:通过其REST API提供全面、高质量的蛋白质数据
- Anthropic:用于模型上下文协议规范和Python SDK
- 社区:用于反馈、错误报告和贡献
🔗 链接
- 文档:
- UniProt API: REST API文档
- MCP规范: 模型上下文协议
- 问题与支持:
⚠️ 免责声明
这是一个独立的项目,与UniProt联盟没有正式联系或认可。请查看UniProt的 使用条款 当使用他们的数据时。
______________________________________________________________________
内置于❤️ 面向生物信息学和人工智能社区
