Skip to content

fix(mcp): MCP Instrumentation: streamablehttp_client Parameter Corruption #3199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from contextlib import asynccontextmanager
from dataclasses import dataclass
from typing import Any, AsyncGenerator, Callable, Collection, Tuple, cast
from typing import Any, AsyncGenerator, Callable, Collection, Tuple, cast, Union
import json
import logging
import traceback
Expand Down Expand Up @@ -124,16 +124,30 @@ def _transport_wrapper(self, tracer):
async def traced_method(
wrapped: Callable[..., Any], instance: Any, args: Any, kwargs: Any
) -> AsyncGenerator[
Tuple["InstrumentedStreamReader", "InstrumentedStreamWriter"], None
Union[
Tuple[InstrumentedStreamReader, InstrumentedStreamWriter],
Tuple[InstrumentedStreamReader, InstrumentedStreamWriter, Any]
],
None
]:
async with wrapped(*args, **kwargs) as result:
try:
read_stream, write_stream = result
yield InstrumentedStreamReader(
read_stream, tracer
), InstrumentedStreamWriter(write_stream, tracer)
except ValueError:
read_stream, write_stream, _ = result
yield InstrumentedStreamReader(
read_stream, tracer
), InstrumentedStreamWriter(write_stream, tracer)
try:
read_stream, write_stream, get_session_id_callback = result
yield InstrumentedStreamReader(
read_stream, tracer
), InstrumentedStreamWriter(write_stream, tracer), get_session_id_callback
except Exception as e:
logging.warning(f"mcp instrumentation _transport_wrapper exception: {e}")
yield result
except Exception as e:
logging.warning(f"mcp instrumentation transport_wrapper exception: {e}")
yield result

return traced_method

Expand Down