Files
vscode/src/vs
Connor Peet 57479c0e8a mcp: fix concurrent request response collection race (#299628)
* mcp: fix concurrent request response collection race

- JsonRpcProtocol.handleMessage now returns JsonRpcMessage[] containing
  responses generated by incoming requests, rather than delegating
  response collection to callers via side-channel state
- McpGatewaySession simplified by removing _pendingResponses and
  _isCollectingPostResponses fields, which were susceptible to racing
  under concurrent HTTP POSTs. Now directly uses handleMessage's
  return value for the response body
- _send callback still invoked for all messages (backward compatible
  with McpServerRequestHandler and SSE notification broadcast)
- Updated tests to assert on handleMessage return values

Fixes #297780

(Commit message generated by Copilot)

* mcp: address review comments on jsonRpcProtocol changes

- Adds JSDoc to handleMessage clarifying what is returned (only responses
  for incoming requests), ordering guarantees for batch inputs, and that
  responses are still emitted via _send callback to avoid double-sending
- Tightens _handleRequest return type from Promise<JsonRpcMessage> to
  Promise<JsonRpcResponse>, enforcing that only valid responses are
  returned. Introduces JsonRpcResponse type alias for better type safety
- Expands error handling tests to assert that returned replies match
  what is emitted via _send for both JsonRpcError and generic error paths

Fixes #297780

(Commit message generated by Copilot)
2026-03-06 14:52:44 -08:00
..