Synapse MCP サーバー
Synapse エンティティ (データセット、プロジェクト、フォルダー、ファイル、テーブル) とその注釈を公開するモデル コンテキスト プロトコル (MCP) サーバー。
概要
このサーバーは、モデルコンテキストプロトコル(MCP)を介してSynapseエンティティとそのアノテーションにアクセスするためのRESTful APIを提供します。これにより、以下のことが可能になります。
- 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
使用法
サーバーの起動
これにより、デフォルトのポート (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 /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)
ライセンス
マサチューセッツ工科大学