|
36 | 36 | INVALID_REQUEST, |
37 | 37 | PARSE_ERROR, |
38 | 38 | PROTOCOL_VERSION_META_KEY, |
39 | | - UNSUPPORTED_PROTOCOL_VERSION, |
40 | 39 | ErrorData, |
41 | 40 | JSONRPCError, |
42 | 41 | JSONRPCNotification, |
43 | 42 | JSONRPCRequest, |
44 | 43 | JSONRPCResponse, |
45 | 44 | ProgressToken, |
46 | 45 | RequestId, |
47 | | - UnsupportedProtocolVersionErrorData, |
48 | 46 | ) |
49 | 47 | from mcp_types import methods as _methods |
50 | | -from mcp_types.version import MODERN_PROTOCOL_VERSIONS |
51 | 48 | from pydantic import ValidationError |
52 | 49 | from starlette.requests import Request |
53 | 50 | from starlette.responses import Response |
|
67 | 64 | InboundModernRoute, |
68 | 65 | classify_inbound_request, |
69 | 66 | find_duplicated_routing_header, |
| 67 | + unsupported_protocol_version_rejection, |
70 | 68 | validate_mcp_param_headers, |
71 | 69 | ) |
72 | 70 | from mcp.shared.jsonrpc_dispatcher import progress_token_from_params |
@@ -169,7 +167,7 @@ def _sse_event(msg: JSONRPCResponse | JSONRPCError | JSONRPCNotification) -> byt |
169 | 167 |
|
170 | 168 | async def _write_rejection( |
171 | 169 | rejection: InboundLadderRejection, |
172 | | - request_id: RequestId, |
| 170 | + request_id: RequestId | None, |
173 | 171 | scope: Scope, |
174 | 172 | receive: Receive, |
175 | 173 | send: Send, |
@@ -250,19 +248,8 @@ async def _acknowledge_notification( |
250 | 248 | await _write(_INVALID_BODY, scope, receive, send) |
251 | 249 | return |
252 | 250 | requested = request.headers.get(MCP_PROTOCOL_VERSION_HEADER, "") |
253 | | - if requested not in MODERN_PROTOCOL_VERSIONS: |
254 | | - rej = JSONRPCError( |
255 | | - jsonrpc="2.0", |
256 | | - id=None, |
257 | | - error=ErrorData( |
258 | | - code=UNSUPPORTED_PROTOCOL_VERSION, |
259 | | - message="Unsupported protocol version", |
260 | | - data=UnsupportedProtocolVersionErrorData( |
261 | | - supported=list(MODERN_PROTOCOL_VERSIONS), requested=requested |
262 | | - ).model_dump(mode="json"), |
263 | | - ), |
264 | | - ) |
265 | | - await _write(rej, scope, receive, send) |
| 251 | + if (unsupported := unsupported_protocol_version_rejection(requested)) is not None: |
| 252 | + await _write_rejection(unsupported, None, scope, receive, send) |
266 | 253 | return |
267 | 254 | logger.debug("acknowledged and dropped client notification %s at %s", notification.method, requested) |
268 | 255 | await Response(status_code=202)(scope, receive, send) |
|
0 commit comments