(redirectUri?: string)
| 103 | } |
| 104 | |
| 105 | export 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 | |
| 133 | export function waitForCallback(oauthState: string, mcpName?: string): Promise<string> { |
| 134 | if (mcpName) mcpNameToState.set(mcpName, oauthState) |
nothing calls this directly
no test coverage detected