Skip to content

fix: update mcp test mocks for SDK streamable transport#2664

Merged
lpcox merged 2 commits intomainfrom
fix/mcp-test-sdk-transport-hang
Mar 27, 2026
Merged

fix: update mcp test mocks for SDK streamable transport#2664
lpcox merged 2 commits intomainfrom
fix/mcp-test-sdk-transport-hang

Conversation

@lpcox
Copy link
Copy Markdown
Collaborator

@lpcox lpcox commented Mar 27, 2026

Fixes hanging TestConnection_SendRequest in internal/mcp caused by SDK streamable transport changes from #2608.

Root cause: After #2608 removed the headers shortcut, NewHTTPConnection always tries SDK streamable transport first. Two mock server issues caused hangs:

  1. newPlainJSONTestServer didn't handle notifications/initialized (SDK sends this after initialize)
  2. TestConnection_SendRequest hardcoded "id": 1 — SDK assigns sequential IDs, so the response never matched the Await call

Fix:

  • Added notifications/initialized handler (202 Accepted) to newPlainJSONTestServer
  • Echo back req["id"] instead of hardcoding 1 in the test handler

The newPlainJSONTestServer helper and TestConnection_SendRequest were
not handling the SDK streamable transport protocol correctly:

- newPlainJSONTestServer: add notifications/initialized handler (SDK
  sends this after successful initialize)
- TestConnection_SendRequest: echo back request ID instead of
  hardcoding 1 (SDK assigns sequential IDs)

Without these fixes, the SDK transport hangs waiting for a matching
response ID during the initialize handshake.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 27, 2026 17:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates MCP test mocks to align with the SDK’s Streamable HTTP transport handshake so internal/mcp tests don’t hang after transport selection changes (per #2608).

Changes:

  • Teach newPlainJSONTestServer to acknowledge notifications/initialized with 202 Accepted.
  • Update TestConnection_SendRequest mock handler to echo the incoming JSON-RPC id instead of hardcoding 1.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/mcp/sdk_method_dispatch_test.go Adds a notifications/initialized acknowledgement to the plain JSON test server handshake.
internal/mcp/connection_stderr_test.go Makes the mock response correlate with the request by echoing the JSON-RPC id.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@lpcox lpcox merged commit 1305100 into main Mar 27, 2026
13 checks passed
@lpcox lpcox deleted the fix/mcp-test-sdk-transport-hang branch March 27, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants