mcp: no reconnect when a legacy HTTP server answers an expired session with 400 "No valid session ID provided"
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 72/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript
- 领域
- api
调研方向
从 packages/core/src/mcp/client.ts 中的 failure() 开始(大约第 497-512 行),它把 404 和带有 Bad Request: Server not initialized 的 400 映射为 SessionExpiredError;新情况是 body 中包含 No valid session ID 的 400,仍然以 transport 持有 session id 为条件。然后阅读 connection.ts:139-149,确认 recovering 就是触发重连的东西,这样你就能判断修复是否有效。在 packages/core/test 中添加或扩展一个 bun test,用报告中的 400 body 回应一个旧 session id,并断言该调用会重试并成功。注意报告者提出可以发送一个带测试的 PR,所以开始前先检查 thread。
由索引模型根据 Issue 内容生成。
描述
Description
When a legacy Streamable HTTP server forgets the session (restart or idle expiry) and answers the old Mcp-Session-Id with HTTP 400 Bad Request: No valid session ID provided, opencode does not reconnect. Every later tool call on that server fails with that 400, and the server still shows connected until the user reconnects it by hand.
This was reported in #32809 (Atlassian MCP 1.12.4 after ~15-30 min idle). The bot closed it for inactivity and asked for a new issue if it is still relevant. It still happens on v2 dev.
The cause is failure() in packages/core/src/mcp/client.ts:497-512. It maps a 404 to SessionExpiredError, but a 400 only when the body contains Bad Request: Server not initialized. Older Python SDK session managers and the TypeScript SDK example servers answer an unknown session id with Bad Request: No valid session ID provided. FastMCP-based servers such as mcp-atlassian inherit this. That body falls through as a plain error, so recovering (connection.ts:139-149) never runs.
Fix idea: also treat a 400 whose body contains No valid session ID as an expired session. The check stays narrow: it only applies when the transport holds a session id, like the existing cases, so other 400s still pass through.
I can send a PR with a test if this is OK.
Plugins
No response
OpenCode version
dev adc958a7d7 (2.4.1)
Steps to reproduce
- Run a stateful legacy MCP server that answers an unknown session id with 400
{"jsonrpc":"2.0","error":{"code":-32000,"message":"Bad Request: No valid session ID provided"},"id":null}, and add it as a remote server. - Call a tool once. It works.
- Restart the server (or let the session expire).
- Call the tool again. It fails with
MCP tool "echo" on server "legacy" failed: Error POSTing to endpoint: {..."Bad Request: No valid session ID provided"...} (HTTP 400), and every later call fails the same way. With a 404 for the same case, opencode reconnects and the call succeeds.
I have this as a bun test in packages/core/test.
Screenshot
No response
Operating System
Windows 11
Terminal
No response
- 主要语言
- TypeScript
- 星标
- 228k
- 派生
- 31k
- 平均合并
- 3 小时 22 分钟
- 30 天内合并 PR
- 476
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
anomalyco/opencode 的其他 Issue
-
desktop: app-version.v1 in drafts.sqlite is never refreshed — reports 1.19.4 while running 2.3.2未关闭area/desktop platform/windows type/feature version/v2
难度 2/5 1-3 小时 新手友好度 66/100
anomalyco/opencode#66079 · 1 条评论 ·
维护者通常 1 天内回复
-
area/providers platform/windows type/feature version/v2
难度 2/5 1-3 小时 新手友好度 74/100
anomalyco/opencode#66001 · 1 条评论 ·
维护者通常 1 天内回复
-
area/mcp platform/windows type/feature version/v2
难度 2/5 1-3 小时 新手友好度 72/100
anomalyco/opencode#65997 · 1 条评论 ·
维护者通常 1 天内回复
-
@opencode/ui: v2-text-text-faint and light v2-state-fg-warning fall below WCAG AA 4.5:1 contrast可能已有人在做 @KhadeerBasha1232 今天认领。 未关闭status/repro-plausible
难度 2/5 1-3 小时 新手友好度 75/100
anomalyco/opencode#65923 · 2 条评论 ·
维护者通常 1 天内回复
-
area/core platform/windows type/bug version/v2
难度 2/5 1-3 小时 新手友好度 80/100
anomalyco/opencode#65880 · 1 条评论 ·
维护者通常 1 天内回复
查看 anomalyco/opencode 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
lidofinance/validator-ejector#233 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 1 天内回复
-
ai-driven-qa bug claude Major
难度 2/5 1-3 小时 新手友好度 78/100
linagora/twake-mail-admin#742 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
OpenSlides/openslides-client#6728 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 66/100