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(mcp): stop idle OAuth callback server (#32245) · ildella/opencode@5d0f866

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/opencode
    • src/mcp
      • oauth-callback.ts
    • test/mcp
      • oauth-callback.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/opencode/src/mcp/oauth-callback.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/mcp/oauth-callback.ts
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ function cleanupStateIndex(oauthState: string) {
7171
}
7272
}
7373

74+
function stopIfIdle() {
75+
if (pendingAuths.size > 0 || !server) return
76+
77+
server.close()
78+
server = undefined
79+
}
80+
7481
function handleRequest(req: import("http").IncomingMessage, res: import("http").ServerResponse) {
7582
const url = new URL(req.url || "/", `http://localhost:${currentPort}`)
7683

@@ -104,6 +111,7 @@ function handleRequest(req: import("http").IncomingMessage, res: import("http").
104111
}
105112
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" })
106113
res.end(HTML_ERROR(errorMsg))
114+
stopIfIdle()
107115
return
108116
}
109117

@@ -130,6 +138,7 @@ function handleRequest(req: import("http").IncomingMessage, res: import("http").
130138

131139
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" })
132140
res.end(HTML_SUCCESS)
141+
stopIfIdle()
133142
}
134143

135144
export async function ensureRunning(redirectUri?: string): Promise<void> {
@@ -168,6 +177,7 @@ export function waitForCallback(oauthState: string, mcpName?: string): Promise<s
168177
pendingAuths.delete(oauthState)
169178
if (mcpName) mcpNameToState.delete(mcpName)
170179
reject(new Error("OAuth callback timeout - authorization took too long"))
180+
stopIfIdle()
171181
}
172182
}, CALLBACK_TIMEOUT_MS)
173183

@@ -185,6 +195,7 @@ export function cancelPending(mcpName: string): void {
185195
pendingAuths.delete(key)
186196
mcpNameToState.delete(mcpName)
187197
pending.reject(new Error("Authorization cancelled"))
198+
stopIfIdle()
188199
}
189200
}
190201

Collapse file

‎packages/opencode/test/mcp/oauth-callback.test.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/test/mcp/oauth-callback.test.ts
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ describe("McpOAuthCallback.ensureRunning", () => {
3232
expect(McpOAuthCallback.isRunning()).toBe(true)
3333
})
3434

35+
test("stops after the callback completes", async () => {
36+
const redirectUri = "http://127.0.0.1:18003/custom/callback"
37+
await McpOAuthCallback.ensureRunning(redirectUri)
38+
const callback = McpOAuthCallback.waitForCallback("success")
39+
40+
const response = await fetch(`${redirectUri}?code=code&state=success`)
41+
42+
expect(response.status).toBe(200)
43+
expect(await callback).toBe("code")
44+
expect(McpOAuthCallback.isRunning()).toBe(false)
45+
})
46+
3547
test("escapes provider error markup in callback HTML", async () => {
3648
const redirectUri = "http://127.0.0.1:18001/custom/callback"
3749
await McpOAuthCallback.ensureRunning(redirectUri)

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.