GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(opencode): recover expired MCP sessions (#32088) · moonug/opencode@c7dee9c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • bun.lock
  • package.json
  • packages/opencode/test
    • fixture
      • mcp-session-recovery.ts
    • mcp
      • session-recovery.test.ts
  • patches
    • @modelcontextprotocol%[email protected]
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎bun.lock‎

Copy file name to clipboardExpand all lines: bun.lock
+1Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎package.json‎

Copy file name to clipboardExpand all lines: package.json
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
"@ai-sdk/[email protected]": "patches/@ai-sdk%[email protected]",
150150
"[email protected]": "patches/[email protected]",
151151
"[email protected]": "patches/[email protected]",
152-
"@ai-sdk/[email protected]": "patches/@ai-sdk%[email protected]"
152+
"@ai-sdk/[email protected]": "patches/@ai-sdk%[email protected]",
153+
"@modelcontextprotocol/[email protected]": "patches/@modelcontextprotocol%[email protected]"
153154
}
154155
}
Collapse file

‎packages/opencode/test/fixture/mcp-session-recovery.ts‎

Copy file name to clipboard
+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
2+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
3+
import { LATEST_PROTOCOL_VERSION } from "@modelcontextprotocol/sdk/types.js"
4+
5+
const posts: Array<{ method: string; session: string | null }> = []
6+
let initializeCount = 0
7+
let pingCount = 0
8+
const server = Bun.serve({
9+
port: 0,
10+
async fetch(request) {
11+
if (request.method === "GET") return new Response(null, { status: 405 })
12+
if (request.method === "DELETE") return new Response(null, { status: 200 })
13+
14+
const message = (await request.json()) as { id?: number; method: string }
15+
const session = request.headers.get("mcp-session-id")
16+
posts.push({ method: message.method, session })
17+
18+
if (message.method === "initialize") {
19+
initializeCount++
20+
return Response.json(
21+
{
22+
jsonrpc: "2.0",
23+
id: message.id,
24+
result: {
25+
protocolVersion: LATEST_PROTOCOL_VERSION,
26+
capabilities: {},
27+
serverInfo: { name: "test", version: "1" },
28+
},
29+
},
30+
{ headers: { "mcp-session-id": initializeCount === 1 ? "expired" : "replacement" } },
31+
)
32+
}
33+
34+
if (message.method === "notifications/initialized") return new Response(null, { status: 202 })
35+
36+
pingCount++
37+
if (pingCount === 1) return new Response("Session not found", { status: 404 })
38+
return Response.json({ jsonrpc: "2.0", id: message.id, result: {} })
39+
},
40+
})
41+
const client = new Client({ name: "test", version: "1" })
42+
43+
try {
44+
await client.connect(new StreamableHTTPClientTransport(server.url))
45+
await client.ping()
46+
process.stdout.write(JSON.stringify(posts))
47+
} finally {
48+
await client.close()
49+
server.stop(true)
50+
}
Collapse file

‎packages/opencode/test/mcp/session-recovery.test.ts‎

Copy file name to clipboard
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import path from "node:path"
2+
import { describe, expect, test } from "bun:test"
3+
4+
describe("mcp session recovery", () => {
5+
test("reinitializes and retries once after a session-bound POST returns 404", async () => {
6+
const child = Bun.spawn([process.execPath, path.join(import.meta.dir, "../fixture/mcp-session-recovery.ts")], {
7+
cwd: path.join(import.meta.dir, "../.."),
8+
stdout: "pipe",
9+
stderr: "pipe",
10+
})
11+
const [code, stdout, stderr] = await Promise.all([
12+
child.exited,
13+
Bun.readableStreamToText(child.stdout),
14+
Bun.readableStreamToText(child.stderr),
15+
])
16+
17+
expect(code, stderr).toBe(0)
18+
expect(JSON.parse(stdout)).toEqual([
19+
{ method: "initialize", session: null },
20+
{ method: "notifications/initialized", session: "expired" },
21+
{ method: "ping", session: "expired" },
22+
{ method: "initialize", session: null },
23+
{ method: "notifications/initialized", session: "replacement" },
24+
{ method: "ping", session: "replacement" },
25+
])
26+
})
27+
})

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.