GeezerVison is showing github.com — fix: send `mcpName` as state if authUrl doesn't have `state` (#5681) · toastdriven/opencode@57c3cf1
File tree
Expand file treeCollapse file tree
Open diff view settings
packages/opencode/src/mcp
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/opencode/src/mcp/index.ts +10-3Lines changed: 10 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -494,11 +494,18 @@ export namespace MCP { |
494 | 494 | // Extract state from authorization URL to use as callback key |
495 | 495 | // If no state parameter, use mcpName as fallback |
496 | 496 | const authUrl = new URL(authorizationUrl) |
497 | | - const oauthState = authUrl.searchParams.get("state") ?? mcpName |
| 497 | + let oauthState = mcpName |
| 498 | + |
| 499 | + if (authUrl.searchParams.has("state")) { |
| 500 | + oauthState = authUrl.searchParams.get("state")! |
| 501 | + } else { |
| 502 | + log.info("no state parameter in authorization URL, using mcpName as state", { mcpName }) |
| 503 | + authUrl.searchParams.set("state", oauthState) |
| 504 | + } |
498 | 505 |
|
499 | 506 | // Open browser |
500 | | - log.info("opening browser for oauth", { mcpName, url: authorizationUrl, state: oauthState }) |
501 | | - await open(authorizationUrl) |
| 507 | + log.info("opening browser for oauth", { mcpName, url: authUrl.toString(), state: oauthState }) |
| 508 | + await open(authUrl.toString()) |
502 | 509 |
|
503 | 510 | // Wait for callback using the OAuth state parameter (or mcpName as fallback) |
504 | 511 | const code = await McpOAuthCallback.waitForCallback(oauthState) |
|