File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 33from __future__ import annotations
44
55import contextlib
6+ import json
67import logging
78from collections .abc import AsyncIterator
89from http import HTTPStatus
@@ -288,9 +289,17 @@ async def run_server(
288289 await http_transport .handle_request (scope , receive , send )
289290 else : # pragma: no cover
290291 # Unknown or expired session ID - return 404 per MCP spec
291- # This tells the client to reinitialize
292+ # Use JSON-RPC error format for consistency with transport errors
293+ error_body = json .dumps (
294+ {
295+ "jsonrpc" : "2.0" ,
296+ "id" : "server-error" ,
297+ "error" : {"code" : - 32600 , "message" : "Session not found" },
298+ }
299+ )
292300 response = Response (
293- "Session not found" ,
301+ content = error_body ,
294302 status_code = HTTPStatus .NOT_FOUND ,
303+ media_type = "application/json" ,
295304 )
296305 await response (scope , receive , send )
You can’t perform that action at this time.
0 commit comments