pi-mono/packages/mcp/test
robopipi[bot] 63ea042ce5
fix(mcp): close remaining connections when the OAuth callback server closes (#11855)
After a successful MCP OAuth sign-in, `/mcp login` could stay on
"Connecting…" for minutes. `OAuthCallbackServer.close()` awaited
`http.Server.close()`, which resolves only after every socket has
closed. Browsers may keep an unused connection open to the callback port
(a preconnect, or a spare keep-alive socket). Node's idle-connection
cleanup doesn't close that socket, and `close()` also stops Node's
request timeout checks. So the wait lasted until the browser dropped the
socket. `signInMcpServer` awaits this cleanup before reconnecting, and
cancellation doesn't apply to it, so Ctrl+C did nothing.

`close()` now calls `server.closeAllConnections()` after starting the
shutdown. By the time the server closes, the callback response has
already been sent, so dropping the remaining connections is safe.

**Testing**
- Added a test to `packages/mcp/test/oauth.test.ts`: it opens a spare
TCP connection to the callback port, completes a callback, and expects
`close()` to resolve within 2 s. It fails without the change and passes
with it.
- `npm run check` passes. The MCP OAuth tests and the coding-agent MCP
tests pass.
- Script reproduction: with a spare connection open, `close()` did not
resolve within 400 s before the change, and resolves in about 1 ms after
it.

Fixes #11311

Requested by @petrroll

Co-authored-by: triagent <triagent@localhost>
2026-11-05 23:51:53 +01:00
..
fixtures fix(mcp): clean up server children on stdio close after the server exited (#11724) 2026-11-03 09:31:10 +01:00
auth-provider.test.ts fix(mcp): refresh with the app's redirect URI, cancel sign-in during the lock wait 2026-11-03 14:17:21 +01:00
authorization-server.ts fix(mcp): refresh with the app's redirect URI, cancel sign-in during the lock wait 2026-11-03 14:17:21 +01:00
client.test.ts fix(mcp,coding-agent): accept any JSON value as tool structuredContent 2026-10-12 14:16:35 +02:00
config.test.ts feat(mcp): shared tool naming, schema, output limit and config helpers 2026-11-03 14:17:21 +01:00
content.test.ts fix(mcp,coding-agent): accept any JSON value as tool structuredContent 2026-10-12 14:16:35 +02:00
helpers.ts feat(coding-agent): codemode and MCP 2026-09-29 09:12:50 +02:00
input-schema.test.ts feat(mcp): shared tool naming, schema, output limit and config helpers 2026-11-03 14:17:21 +01:00
lines.test.ts fix(mcp): read large stdio messages in linear time (#11791) 2026-11-04 10:09:23 +01:00
loopback.test.ts feat(mcp): MCP OAuth sign-in in two halves, moved from coding-agent 2026-11-03 14:17:21 +01:00
naming.test.ts feat(mcp): shared tool naming, schema, output limit and config helpers 2026-11-03 14:17:21 +01:00
oauth.test.ts fix(mcp): close remaining connections when the OAuth callback server closes (#11855) 2026-11-05 23:51:53 +01:00
output-limit.test.ts feat(mcp): shared tool naming, schema, output limit and config helpers 2026-11-03 14:17:21 +01:00
pipe.test.ts feat(mcp): PipeTransport, the stdio transport over a program started by the caller 2026-11-03 14:17:21 +01:00
sign-in.test.ts fix(mcp): refresh with the app's redirect URI, cancel sign-in during the lock wait 2026-11-03 14:17:21 +01:00
stdio.test.ts fix(mcp): clean up server children on stdio close after the server exited (#11724) 2026-11-03 09:31:10 +01:00
streamable-http.test.ts fix(mcp): recognize CR-only line endings in Streamable HTTP SSE (#11775) 2026-11-04 09:18:01 +01:00