Skip to content

fix: 工具发现按连接隔离失败,单个连接器故障不再拖垮整个 MCP 会话 - #16

Merged
sheepbox8646 merged 1 commit into
mainfrom
fix/con-6-partial-tool-discovery
Oct 15, 2026
Merged

sheepbox8646 merged 1 commit into
mainfrom
fix/con-6-partial-tool-discovery

Conversation

@sheepbox8646

@sheepbox8646 sheepbox8646 commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

背景

Memoh Cloud 生产排查发现:POST /v1/mcp-sessions 的工具发现是全有或全无,任意一个连接的上游 tools/list 失败(当前主要是 Google 官方远程 MCP 返回 403、Cloudflare 返回 403/429)就整体返回 502 tool_discovery_failed,下游 bot 的全部连接器工具一起消失。

Linear issue:CON-6

改动

  • packages/service/sessions:discoverTools 改为按 alias 收集结果,失败的 alias 跳过并以 DiscoveryFailure 返回;只有全部 alias 失败、或 allowlist 指名了失败 alias 下的工具时才返回 ErrToolDiscovery。失败 alias 不再绑定到会话。每个失败 alias 仍以 sessions: tool discovery failed for alias "<alias>": <err> 记日志,保持与下游日志按时间戳配对的方式不变。
  • packages/api:POST /v1/mcp-sessions 响应新增 failed_connections(alias、connection_id、error),全部成功时省略;swagger 与 TS SDK 已重新生成。
  • sdk/go:MCPSession 解码 failed_connections;MCPSessionConfig 新增 OnSessionCreated 观察回调,MCPAuthHandler 在每次签发新会话后(锁外)调用,供下游暴露降级信息。
  • docs/architecture.md:更新会话快照语义描述。

验证

  • mise run vet、mise run test(含 TEST_DATABASE_URL 集成测试)全部通过。
  • 新增测试:sessions 包的局部失败 / 全部失败 / allowlist 依赖失败 alias / 全部成功四种情况;API 层局部失败时会话可用且响应带 failed_connections;SDK 解码与观察回调。
  • pnpm --dir packages/web run test 通过。

本地真实服务验证

用本分支构建镜像 connect-it:con6 接入 memoh dev 栈,创建伪造 token 的 cloudflare 连接(真实上游 mcp.cloudflare.com 返回 Unauthorized)与托管型 resend 连接:

  • 只请求 cloudflare:POST /v1/mcp-sessions 仍返回 502 tool_discovery_failed。
  • cloudflare + resend:返回 201,failed_connections 只含 cloudflare 及其上游错误;用 MCP 客户端对 /mcp 做 initialize + tools/list,拿到 resend__api_request。
  • 对照:同一对连接在已发布的 ghcr.io/felinics/connect-it:0.3.1 上返回 502。
  • 日志保持 sessions: tool discovery failed for alias "cloudflare": … 格式。

⚠️ No human QA — this PR has not been verified by a human yet. Remove this line once a human confirms the happy path.

🤖 Generated with Claude Code

A single connection whose upstream failed to list tools used to fail the
whole MCP session issue, so one broken connector removed every connector
tool from the downstream bot. Discovery now skips the failed aliases,
binds only the discovered ones, and reports them in failed_connections.
The issue still fails with tool_discovery_failed when every alias fails
or the allowlist depends on a failed alias.

The Go SDK decodes failed_connections and MCPSessionConfig gains an
OnSessionCreated observer so downstreams can surface the degradation.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@sheepbox8646
sheepbox8646 merged commit e47f250 into main Oct 15, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant