Pick an ephemeral loopback port for the callback server.
()
| 307 | |
| 308 | /** Pick an ephemeral loopback port for the callback server. */ |
| 309 | function ephemeralPort(): number { |
| 310 | // Bind to port 0 and read back the assigned port, then close immediately. |
| 311 | const probe = http.createServer().listen(0, "127.0.0.1") |
| 312 | const addr = probe.address() |
| 313 | probe.close() |
| 314 | return typeof addr === "object" && addr ? addr.port : 8765 |
| 315 | } |
| 316 | |
| 317 | /** Build an OAuthClientProvider from an McpOAuthConfig. Returns the provider |
| 318 | * plus a callback-port hint (for the interactive flow). */ |