SBML模型管理服务

一个基于Python/FastAPI的SBML模型管理服务,用于ModelSEEDVault的SBML数据整理和API交互。

  • by Fxe
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 Fxe/ModelSEEDVault-MCP

使用说明

模型种子库的MCP服务器

用于ModelSEEDVault SBML管理的初始Python/FastAPI MCP服务器支架。

快速入门

.venv/ 被git故意忽略。每个开发人员都应该在该目录中创建自己的本地虚拟环境。使用Python 3.11实现一致性:

uv venv --python 3.11 .venv
source .venv/bin/activate

将项目安装到该环境中:

uv pip install -e .

使用您本地的virtualenv Python运行服务器:

SBML_API_BASE_URL='http://192.168.1.202:8080/' \
uv run --python .venv/bin/python uvicorn mcp_curation.main:app --host 127.0.0.1 --port 8000 --reload

如果在您的环境中启用了auth,请同时包含API密钥:

MCP_API_KEY='change-me' \
SBML_API_BASE_URL='http://192.168.1.202:8080/' \
uv run --python .venv/bin/python uvicorn mcp_curation.main:app --host 127.0.0.1 --port 8000 --reload

安装

pip install -e .

运行组合服务器(FastAPI+FastMCP)

export MCP_API_KEY="change-me"
uvicorn mcp_curation.main:app --host 127.0.0.1 --port 8000 --reload

配置SBML后端端点

默认后端URL:

  • http://localhost:8080

用以下内容覆盖它:

export SBML_API_BASE_URL="http://localhost:8080"
export MCP_API_KEY="change-me"
uvicorn mcp_curation.main:app --host 127.0.0.1 --port 8000 --reload

为前端开发配置CORS

默认允许的前端来源:

  • http://192.168.1.164:62699

用逗号分隔的列表覆盖它:

export CORS_ALLOW_ORIGINS="http://192.168.1.164:62699,http://localhost:3000"

服务器允许:

  • 方法: GET, POST, OPTIONS
  • 标题: Authorization, Content-Type, X-API-Key

未认证 OPTIONS 允许飞行前请求,因此浏览器CORS检查在经过身份验证的API调用之前成功。

FastMCP安装到FastAPI中的位置:

  • /mcp

MCP认证:

  • 必需的环境变量: MCP_API_KEY (如果未设置,则在启动时自动生成)
  • 发送:
    • Authorization: Bearer <MCP_API_KEY>
    • X-API-Key: <MCP_API_KEY>
  • 适用于所有非公共路线,包括 /mcp/* 和 /sbml-curation/*.
  • 公共路由(不需要API密钥):
    • /health
    • /docs
    • /redoc
    • /openapi.json

例子:

curl -H "Authorization: Bearer $MCP_API_KEY" \
  http://127.0.0.1:8000/sbml-curation/models

Swagger测试 /docs:

  • 点击 Authorize.
  • 您可以使用以下任一方式:
    • HTTPBearer:仅输入API密钥值。
    • APIKeyHeader:输入的API密钥值 X-API-Key.
  • 运行任何 /sbml-curation/* 从文档UI中选择端点。

第一条路线

  • GET /health
  • GET /sbml-curation/config
  • GET /sbml-curation/models
  • GET /sbml-curation/models/{model_id}/compartments
  • GET /sbml-curation/models/{model_id}/species
  • GET /sbml-curation/models/{model_id}/reactions
  • GET /sbml-curation/models/{model_id}/genes
  • POST /sbml-curation/annotation
  • GET /sbml-curation/models/{model_id}/compartment/{compartment_id}/annotation
  • GET /sbml-curation/models/{model_id}/species/{species_id}/annotation
  • GET /sbml-curation/models/{model_id}/reaction/{reaction_id}/annotation
  • GET /sbml-curation/models/{model_id}/gene/{gene_id}/annotation

文档

  • Swagger用户界面: http://127.0.0.1:8000/docs

FastMCP工具

  • sbml_curation_config
  • list_models
  • list_model_compartments
  • list_model_species
  • list_model_reactions
  • list_model_genes

SBML客户端助手

  • mcp_curation.client.sbml_client.add_curation_event(subject_eid, object, agent_id) 发布到 /graph/edge/{src}/{dst}/has_annotation_event?agent=...
  • mcp_curation.client.sbml_client.list_curation_events(subject_eid) 获取 /graph/node/{subject_eid}/child?edgeType=has_annotation_event