MCPcopy Index your code
hub / github.com/anomalyco/opencode / ensureRunning

Function ensureRunning

packages/opencode/src/mcp/oauth-callback.ts:105–131  ·  view source on GitHub ↗
(redirectUri?: string)

Source from the content-addressed store, hash-verified

103}
104
105export async function ensureRunning(redirectUri?: string): Promise<void> {
106 // Parse the redirect URI to get port and path (uses defaults if not provided)
107 const { port, path } = parseRedirectUri(redirectUri)
108
109 // If server is running on a different port/path, stop it first
110 if (server && (currentPort !== port || currentPath !== path)) {
111 await stop()
112 }
113
114 if (server) return
115
116 const running = await isPortInUse(port)
117 if (running) {
118 return
119 }
120
121 currentPort = port
122 currentPath = path
123
124 server = createServer(handleRequest)
125 await new Promise<void>((resolve, reject) => {
126 server!.listen(currentPort, OAUTH_CALLBACK_HOST, () => {
127 resolve()
128 })
129 server!.on("error", reject)
130 })
131}
132
133export function waitForCallback(oauthState: string, mcpName?: string): Promise<string> {
134 if (mcpName) mcpNameToState.set(mcpName, oauthState)

Callers

nothing calls this directly

Calls 5

parseRedirectUriFunction · 0.90
isPortInUseFunction · 0.85
onMethod · 0.80
stopFunction · 0.70
resolveFunction · 0.50

Tested by

no test coverage detected