Skip to content

Honor preferred HTTP transport #253

Description

@bettercallsaulj

Honor preferred HTTP transport

Issue

HTTP and HTTPS MCP URLs ignored the caller's preferred HTTP transport when auto negotiation was enabled.

For HTTP URLs, McpClient::negotiateTransport() used URI path heuristics to choose between HTTP+SSE and Streamable HTTP. That meant a caller could configure preferred_transport = StreamableHttp or preferred_transport = HttpSse, but the client could still choose a different transport based only on the URL path.

This broke clients that needed to explicitly select Streamable HTTP or HTTP+SSE for a server whose endpoint path did not match the SDK heuristic.

How to reproduce

  1. Configure an MCP client with an HTTP or HTTPS server URL.
  2. Leave auto negotiation enabled.
  3. Set a preferred HTTP transport explicitly, for example:
preferred_transport = StreamableHttp

or

preferred_transport = HttpSse
  1. Use a URL path whose name points the old heuristic to the opposite transport. Examples:
https://example.test/sse

with preferred_transport = StreamableHttp, or:

https://example.test/mcp

with preferred_transport = HttpSse.

Before the fix, the client chose transport from the path heuristic instead of honoring the explicit preferred transport. That could make the client open the wrong kind of HTTP MCP session and fail during initialization or request handling.

Expected fixed behavior

For http:// and https:// URLs:

  • if auto negotiation is disabled, return preferred_transport directly;
  • if auto negotiation is enabled and preferred_transport is StreamableHttp or HttpSse, use that explicit preference;
  • otherwise fall back to the existing URL path heuristic.

This lets callers override the heuristic when they know which MCP HTTP transport the server expects.

Regression check

A regression test should cover HTTP and HTTPS URLs with:

  1. auto_negotiate_transport = false, verifying the preferred transport is returned;
  2. auto_negotiate_transport = true and preferred_transport = StreamableHttp, verifying Streamable HTTP wins even for an SSE-looking path;
  3. auto_negotiate_transport = true and preferred_transport = HttpSse, verifying HTTP+SSE wins even for a generic path;
  4. no explicit HTTP preference, verifying the existing path heuristic still applies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions