S

Synapse注释服务器

@susheel/synapse-mcp
0 Stars 50 次浏览 susheel 更新于 2026-08-23

一个模型上下文协议服务器,它公开Synapse实体(数据集、项目、文件夹、文件、表格)及其注解,通过RESTful API实现对Synapse数据资源的程序化访问。

该服务暂未提供标准配置,请参考 README 手动接入

服务介绍

Synapse MCP 服务器

一个模型上下文协议 (MCP) 服务器,通过该协议可以访问带有注释的 Synapse 实体(数据集、项目、文件夹、文件、表)。

概述

此服务器通过模型上下文协议 (MCP) 提供了一个 RESTful API,用于访问 Synapse 实体及其注释。它允许您:

  • 使用 Synapse 进行身份验证
  • 通过 ID 检索实体
  • 获取实体注释
  • 获取实体子项
  • 基于各种条件查询实体
  • 查询 Synapse 表

安装

# Clone the repository
git clone https://github.com/SageBionetworks/synapse-mcp.git
cd synapse-mcp

# Create a virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies
pip install -e .

从 PyPI 安装

# Install from PyPI
pip install synapse-mcp

使用

启动服务器

python server.py

这将启动默认端口(9000)上的 MCP 服务器。

使用 CLI

# Start the server using the CLI
synapse-mcp --host 127.0.0.1 --port 9000 --debug

命令行选项

usage: server.py [-h] [--host HOST] [--port PORT] [--debug]

Run the Synapse MCP server

options:
  -h, --help     show this help message and exit
  --host HOST    Host to bind to
  --port PORT    Port to listen on
  --debug        Enable debug logging

运行测试

# Run all tests with coverage
./run_tests.sh

# Or run pytest directly
python -m pytest

测试服务器

python examples/client_example.py

API 端点

服务器信息

  • GET /info - 获取服务器信息

工具

  • GET /tools - 列出可用工具
  • POST /tools/authenticate - 与 Synapse 进行身份验证
  • POST /tools/get_entity - 通过 ID 获取实体
  • POST /tools/get_entity_annotations - 获取实体的注释
  • POST /tools/get_entity_children - 获取容器实体的子实体
  • POST /tools/query_entities - 基于各种条件查询实体
  • POST /tools/query_table - 查询 Synapse 表

资源

  • GET /resources - 列出可用资源
  • GET /resources/entity/{id} - 通过 ID 获取实体
  • GET /resources/entity/{id}/annotations - 获取实体注释
  • GET /resources/entity/{id}/children - 获取实体子项
  • GET /resources/query/entities/{entity_type} - 按类型查询实体
  • GET /resources/query/entities/parent/{parent_id} - 按父 ID 查询实体
  • GET /resources/query/entities/name/{name} - 按名称查询实体
  • GET /resources/query/table/{id}/{query} - 使用类似 SQL 的语法查询表

示例

身份验证

您需要使用真实的 Synapse 凭据进行身份验证才能使用服务器:

import requests

# Authenticate with Synapse
response = requests.post("http://127.0.0.1:9000/tools/authenticate", json={
    "email": "your-synapse-email@example.com",
    "password": "your-synapse-password"
})
result = response.json()
print(result)

# Alternatively, you can authenticate with an API key
response = requests.post("http://127.0.0.1:9000/tools/authenticate", json={
    "api_key": "your-synapse-api-key"
})

获取实体

import requests

# Get an entity by ID
response = requests.get("http://127.0.0.1:9000/resources/entity/syn123456")  # Replace with a real Synapse ID
entity = response.json()
print(entity)

获取实体注释

import requests

# Get annotations for an entity
response = requests.get("http://127.0.0.1:9000/resources/entity/syn123456/annotations")  # Replace with a real Synapse ID
annotations = response.json()
print(annotations)

查询实体

import requests

# Query for files in a project
response = requests.get("http://127.0.0.1:9000/resources/query/entities/parent/syn123456", params={  # Replace with a real Synapse ID
    "entity_type": "file"
})
files = response.json()
print(files)

查询表

import requests

# Query a table
table_id = "syn123456"  # Replace with a real Synapse table ID
query = "SELECT * FROM syn123456 LIMIT 10"  # Replace with a real Synapse table ID
response = requests.get(f"http://127.0.0.1:9000/resources/query/table/{table_id}/{query}")
table_data = response.json()
print(table_data)

以 Croissant 格式获取数据集

import requests
import json

# Get public datasets in Croissant format
response = requests.get("http://127.0.0.1:9000/resources/croissant/datasets")
croissant_data = response.json()

# Save to file
with open("croissant_metadata.json", "w") as f:
    json.dump(croissant_data, f, indent=2)

许可证

MIT