Repository navigation
fix: 工具发现按连接隔离失败,单个连接器故障不再拖垮整个 MCP 会话 - #16
Merged
Merged
Conversation
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>
2 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
Memoh Cloud 生产排查发现:
POST /v1/mcp-sessions的工具发现是全有或全无,任意一个连接的上游tools/list失败(当前主要是 Google 官方远程 MCP 返回 403、Cloudflare 返回 403/429)就整体返回 502tool_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连接:POST /v1/mcp-sessions仍返回 502tool_discovery_failed。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": …格式。🤖 Generated with Claude Code