跳转到主要内容

单一 Connection 服务器

对于单一 Connection 服务器,name 参数是可选的,dispatch 会自动解析:
gmail = Connection(secrets=SecretKeys(token="GMAIL_TOKEN"))  # 无需名称

async def _req(method, path, body=None):
    ctx = get_context()
    return await ctx.dispatch(HttpRequest(method=method, path=path, body=body))

Connection 命名

Connection 名称是根据服务器的 slug 派生出来的:windsor/gmail-mcp -> gmail-mcp 如果你在 dispatch("gmail", ...) 中硬编码了不同的名称,请求会失败。对于只有一个 Connection 的服务器,请使用自动分发(auto-dispatch)。

支持多个 Connection 的服务器

当你有多个 Connection 时,需要显式指定目标:
await ctx.dispatch("gmail", HttpRequest(...))
await ctx.dispatch("calendar", HttpRequest(...))
每个 Connection 都需要单独的 OAuth 授权流程。在创建会话时传入 connection_name
# API creates session with explicit connection name
session = await admin_api.create_oauth_session(
    server_id=deployment_id,
    scopes=["gmail.readonly"],
    connection_name="gmail",  # 以此名称存储
)

调试

找不到 Connection?检查 JWT 里的内容:
@tool(description="Debug")
async def debug() -> dict:
    ctx = get_context()
    return {"connections": list(ctx.runtime.get("connections", {}).keys())}