Fix: handle MCP notifications/initialized without 400
This commit is contained in:
+18
-3
@@ -285,10 +285,10 @@ class MCPSummaryHandler(BaseHTTPRequestHandler):
|
||||
})
|
||||
return
|
||||
|
||||
# Some clients probe for OpenAPI spec; safe to return 404.
|
||||
self.send_error(404, "Not Found")
|
||||
except Exception as e:
|
||||
logger.error(f"GET error: {e}", exc_info=True)
|
||||
# Ensure we still send something
|
||||
try:
|
||||
self.send_error(500, "Internal Server Error")
|
||||
except Exception:
|
||||
@@ -322,6 +322,22 @@ class MCPSummaryHandler(BaseHTTPRequestHandler):
|
||||
|
||||
logger.info(f"MCP request: method={method}, id={req_id}")
|
||||
|
||||
# MCP: notifications (e.g. notifications/initialized)
|
||||
# These are one-way; respond with 200 and no result, do not error.
|
||||
if isinstance(method, str) and method.startswith("notifications/"):
|
||||
# If there's an id, respond with empty result; otherwise just 200.
|
||||
if req_id is not None:
|
||||
self._send_json(200, {
|
||||
"jsonrpc": "2.0",
|
||||
"id": req_id,
|
||||
"result": {}
|
||||
})
|
||||
else:
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Length", "0")
|
||||
self.end_headers()
|
||||
return
|
||||
|
||||
# MCP: initialize
|
||||
if method == "initialize":
|
||||
self._send_json(200, {
|
||||
@@ -376,12 +392,11 @@ class MCPSummaryHandler(BaseHTTPRequestHandler):
|
||||
})
|
||||
return
|
||||
|
||||
# Unknown method
|
||||
# Unknown method (non-notification) -> 400
|
||||
self._send_json(400, {"error": "Unknown method: " + str(method)})
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"POST error: {e}", exc_info=True)
|
||||
# Fallback response to avoid silent drop
|
||||
try:
|
||||
self.send_error(500, "Internal Server Error")
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user