File tree Expand file tree Collapse file tree
packages/opencode/src/mcp Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -839,10 +839,13 @@ export const layer = Layer.effect(
839839 const storedState = yield * auth . getOAuthState ( mcpName )
840840 if ( storedState !== result . oauthState ) {
841841 yield * auth . clearOAuthState ( mcpName )
842+ yield * Effect . tryPromise ( ( ) => McpOAuthCallback . stopIfIdle ( ) ) . pipe ( Effect . ignore )
842843 throw new Error ( "OAuth state mismatch - potential CSRF attack" )
843844 }
844845 yield * auth . clearOAuthState ( mcpName )
845- return yield * finishAuth ( mcpName , code )
846+ const status = yield * finishAuth ( mcpName , code )
847+ yield * Effect . tryPromise ( ( ) => McpOAuthCallback . stopIfIdle ( ) ) . pipe ( Effect . ignore )
848+ return status
846849 } )
847850
848851 const finishAuth = Effect . fn ( "MCP.finishAuth" ) ( function * ( mcpName : string , authorizationCode : string ) {
Original file line number Diff line number Diff line change @@ -225,6 +225,12 @@ export async function stop(): Promise<void> {
225225 mcpNameToState . clear ( )
226226}
227227
228+ export async function stopIfIdle ( ) : Promise < void > {
229+ if ( pendingAuths . size === 0 ) {
230+ await stop ( )
231+ }
232+ }
233+
228234export function isRunning ( ) : boolean {
229235 return server !== undefined
230236}
You can’t perform that action at this time.
0 commit comments