davsclaus opened a new pull request, #29301: URL: https://github.com/apache/camel/pull/29301
Fixes [CAMEL-26668](https://issues.apache.org/jira/browse/CAMEL-26668). ## What was wrong With the embedded HTTP server (Camel Main and Camel JBang), `VertxMcpStreamableServerTransportProvider.respondError` wrote the `McpError` Java object as JSON for the replies of requests that fail before they reach the MCP session: - 415 when the `Content-Type` is not `application/json`; - 400 when the message cannot be parsed, a required header is missing, or (DELETE) the session id is missing; - 404 when the session is not found; - 500 for an unknown message type. MCP clients expect a JSON-RPC error object there. ## What changed - `respondError` takes the error code and a message, and writes a JSON-RPC error response without an `id` (the request id is not known, and `McpSchema.JSONRPCResponse` requires one): `{"jsonrpc":"2.0","error":{"code":-32600,"message":"Session not found"}}` - The messages are short and fixed: "Invalid message format" no longer appends the text of the parser (that goes to the DEBUG log), and "Session not found" no longer repeats the session id. - Error codes: `-32700` (parse error) for a message that cannot be parsed, `-32600` (invalid request) for the other cases. Before, a missing header or session id gave `-32601` (method not found) and an unknown session `-32603` (internal error). - The HTTP status codes are unchanged. ## Tests New `VertxMcpErrorResponseTest` (5 tests, raw HTTP against the engine): wrong content type, a message that cannot be parsed, missing session id, unknown session, DELETE without session id. Each checks the status, `Content-Type`, and that the body has exactly `jsonrpc` and `error` (`code`, `message`). All 5 fail without the change in `src/main`. Module build `mvn clean install -Psourcecheck`: 64 unit tests and 19 ITs pass. ## Docs Upgrade guide 4.24: new section "camel-mcp-server - error replies on /mcp are JSON-RPC error responses" (body shape and the changed error codes). ## Notes - #29284 (CAMEL-26359) adds a 403 for a refused `Origin` in its own handler, already as a JSON-RPC error without an `id`, so all error replies on `/mcp` have the same shape once both are merged. The two PRs touch different files except the upgrade guide. - Spring Boot and Quarkus use their own transports and are not changed. _Claude Code on behalf of Claus Ibsen (davsclaus)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
