I had some trouble using the MCP server's HTTP transport with Codex so I switched to the stdio transport and forgot about it, but I recently went back to see what was happening.
Firstly, one minor issue:
|
std::string method_not_allowed = |
|
"HTTP/1.1 405 Method Not Allowed\r\n" |
|
"Content-Type: application/json\r\n" |
|
"Content-Length: 56\r\n" + |
|
get_cors_origin_header() + |
|
"Connection: close\r\n" |
|
"\r\n" |
|
"{\"error\":\"SSE streaming not supported by this server\"}"; |
This sends Content-Length: 56 but only 54 bytes of body content, so if you curl the endpoint you get a warning:
$ curl 127.0.0.1:7777/mcp
curl: (18) transfer closed with 2 bytes remaining to read
{"error":"SSE streaming not supported by this server"}
The other issue is the one that was confusing Codex. This part responds to notifications/initialized:
|
else if (method == "notifications/initialized") |
|
{ |
|
// Notifications don't need JSON-RPC response, but HTTP needs HTTP response |
|
if (dynamic_cast<HttpTransport*>(m_transport)) |
|
{ |
|
m_transport->send("{}"); |
|
} |
|
} |
https://www.jsonrpc.org/specification#notification (section 4.1) says
A Notification is a Request object without an "id" member. [...] The Server MUST NOT reply to a Notification, including those that are within a batch request.
And https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#sending-messages-to-the-server says
If the server accepts the input, the server MUST return HTTP status code 202 Accepted with no body.
It seems that Codex doesn't like getting a 200 response with body content, and marks the MCP server as unavailable. Changing to a 202 response with no body fixes this.
I had some trouble using the MCP server's HTTP transport with Codex so I switched to the stdio transport and forgot about it, but I recently went back to see what was happening.
Firstly, one minor issue:
Geargrafx/platforms/shared/desktop/mcp/mcp_transport.h
Lines 693 to 700 in c48cb8b
This sends
Content-Length: 56but only 54 bytes of body content, so if youcurlthe endpoint you get a warning:The other issue is the one that was confusing Codex. This part responds to
notifications/initialized:Geargrafx/platforms/shared/desktop/mcp/mcp_server.cpp
Lines 169 to 176 in c48cb8b
https://www.jsonrpc.org/specification#notification (section 4.1) says
And https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#sending-messages-to-the-server says
It seems that Codex doesn't like getting a 200 response with body content, and marks the MCP server as unavailable. Changing to a 202 response with no body fixes this.