|
6 | 6 | responses, with streaming support for long-running operations. |
7 | 7 | """ |
8 | 8 |
|
9 | | -import json |
10 | 9 | import logging |
11 | 10 | import re |
12 | 11 | from abc import ABC, abstractmethod |
|
17 | 16 | from typing import Any |
18 | 17 |
|
19 | 18 | import anyio |
| 19 | +import pydantic_core |
20 | 20 | from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream |
21 | 21 | from pydantic import ValidationError |
22 | 22 | from sse_starlette import EventSourceResponse |
23 | 23 | from starlette.requests import Request |
24 | 24 | from starlette.responses import Response |
25 | 25 | from starlette.types import Receive, Scope, Send |
26 | 26 |
|
27 | | -from mcp.server.transport_security import ( |
28 | | - TransportSecurityMiddleware, |
29 | | - TransportSecuritySettings, |
30 | | -) |
| 27 | +from mcp.server.transport_security import TransportSecurityMiddleware, TransportSecuritySettings |
31 | 28 | from mcp.shared.message import ServerMessageMetadata, SessionMessage |
32 | 29 | from mcp.shared.version import SUPPORTED_PROTOCOL_VERSIONS |
33 | 30 | from mcp.types import ( |
@@ -453,9 +450,8 @@ async def _handle_post_request(self, scope: Scope, request: Request, receive: Re |
453 | 450 | body = await request.body() |
454 | 451 |
|
455 | 452 | try: |
456 | | - # TODO(Marcelo): Replace `json.loads` with `pydantic_core.from_json`. |
457 | | - raw_message = json.loads(body) |
458 | | - except json.JSONDecodeError as e: |
| 453 | + raw_message = pydantic_core.from_json(body) |
| 454 | + except ValueError as e: |
459 | 455 | response = self._create_error_response(f"Parse error: {str(e)}", HTTPStatus.BAD_REQUEST, PARSE_ERROR) |
460 | 456 | await response(scope, receive, send) |
461 | 457 | return |
|
0 commit comments