Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/opencode/src/mcp/oauth-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,15 @@ export class McpOAuthProvider implements OAuthClientProvider {

async state(): Promise<string> {
const entry = await McpAuth.get(this.mcpName)
if (!entry?.oauthState) {
throw new Error(`No OAuth state saved for MCP server: ${this.mcpName}`)
if (entry?.oauthState) {
return entry.oauthState
}
return entry.oauthState
// Generate and persist a new state if none exists (e.g. during initial connection)
const generated = Array.from(crypto.getRandomValues(new Uint8Array(32)))
.map((b) => b.toString(16).padStart(2, "0"))
.join("")
await McpAuth.updateOAuthState(this.mcpName, generated)
return generated
}

async invalidateCredentials(type: "all" | "client" | "tokens"): Promise<void> {
Expand Down
Loading