Skip to content

Commit 3bfad01

Browse files
authored
Merge branch 'main' into docs/fix-readme-848
2 parents 7e9dbd4 + 2cbc435 commit 3bfad01

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/mcp/client/streamable_http.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ async def handle_get_stream(
195195
self.url,
196196
headers=headers,
197197
timeout=httpx.Timeout(
198-
self.timeout.seconds, read=self.sse_read_timeout.seconds
198+
self.timeout.total_seconds(),
199+
read=self.sse_read_timeout.total_seconds(),
199200
),
200201
) as event_source:
201202
event_source.response.raise_for_status()
@@ -226,7 +227,7 @@ async def _handle_resumption_request(self, ctx: RequestContext) -> None:
226227
self.url,
227228
headers=headers,
228229
timeout=httpx.Timeout(
229-
self.timeout.seconds, read=ctx.sse_read_timeout.seconds
230+
self.timeout.total_seconds(), read=ctx.sse_read_timeout.total_seconds()
230231
),
231232
) as event_source:
232233
event_source.response.raise_for_status()
@@ -468,7 +469,8 @@ async def streamablehttp_client(
468469
async with httpx_client_factory(
469470
headers=transport.request_headers,
470471
timeout=httpx.Timeout(
471-
transport.timeout.seconds, read=transport.sse_read_timeout.seconds
472+
transport.timeout.total_seconds(),
473+
read=transport.sse_read_timeout.total_seconds(),
472474
),
473475
auth=transport.auth,
474476
) as client:

src/mcp/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
ProgressToken = str | int
3535
Cursor = str
3636
Role = Literal["user", "assistant"]
37-
RequestId = str | int
37+
RequestId = Annotated[int | str, Field(union_mode="left_to_right")]
3838
AnyFunction: TypeAlias = Callable[..., Any]
3939

4040

@@ -353,7 +353,7 @@ class ProgressNotificationParams(NotificationParams):
353353
"""Total number of items to process (or total progress required), if known."""
354354
message: str | None = None
355355
"""
356-
Message related to progress. This should provide relevant human readable
356+
Message related to progress. This should provide relevant human readable
357357
progress information.
358358
"""
359359
model_config = ConfigDict(extra="allow")

tests/shared/test_sse.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
import httpx
99
import pytest
1010
import uvicorn
11+
from inline_snapshot import snapshot
1112
from pydantic import AnyUrl
1213
from starlette.applications import Starlette
1314
from starlette.requests import Request
1415
from starlette.responses import Response
1516
from starlette.routing import Mount, Route
1617

18+
import mcp.types as types
1719
from mcp.client.session import ClientSession
1820
from mcp.client.sse import sse_client
1921
from mcp.server import Server
@@ -503,3 +505,17 @@ async def test_request_context_isolation(context_server: None, server_url: str)
503505
assert ctx["request_id"] == f"request-{i}"
504506
assert ctx["headers"].get("x-request-id") == f"request-{i}"
505507
assert ctx["headers"].get("x-custom-value") == f"value-{i}"
508+
509+
510+
def test_sse_message_id_coercion():
511+
"""Test that string message IDs that look like integers are parsed as integers.
512+
513+
See <https://github.com/modelcontextprotocol/python-sdk/pull/851> for more details.
514+
"""
515+
json_message = '{"jsonrpc": "2.0", "id": "123", "method": "ping", "params": null}'
516+
msg = types.JSONRPCMessage.model_validate_json(json_message)
517+
assert msg == snapshot(
518+
types.JSONRPCMessage(
519+
root=types.JSONRPCRequest(method="ping", jsonrpc="2.0", id=123)
520+
)
521+
)

0 commit comments

Comments
 (0)