gnodet-bot commented on code in PR #29301:
URL: https://github.com/apache/camel/pull/29301#discussion_r4490178513


##########
components/camel-ai/camel-mcp-server/src/main/java/org/apache/camel/component/mcp/server/vertx/VertxMcpStreamableServerTransportProvider.java:
##########
@@ -488,17 +486,26 @@ private boolean respondBadRequest(Context connection, 
RoutingContext ctx, List<S
         if (errors.isEmpty()) {
             return false;
         }
-        respondError(connection, ctx, 400,
-                
McpError.builder(McpSchema.ErrorCodes.METHOD_NOT_FOUND).message(String.join("; 
", errors)).build());
+        respondError(connection, ctx, 400, 
McpSchema.ErrorCodes.INVALID_REQUEST, String.join("; ", errors));
         return true;
     }
 
-    private void respondError(Context connection, RoutingContext ctx, int 
status, McpError error) {
+    /**
+     * Answers with the given HTTP status and a JSON-RPC error response 
without an id (the request id is not known, and
+     * {@link McpSchema.JSONRPCResponse} requires one).
+     */
+    private void respondError(Context connection, RoutingContext ctx, int 
status, int code, String message) {
+        Map<String, Object> error = new LinkedHashMap<>();
+        error.put("code", code);
+        error.put("message", message);
+        Map<String, Object> response = new LinkedHashMap<>();
+        response.put("jsonrpc", McpSchema.JSONRPC_VERSION);
+        response.put("error", error);
         String json;
         try {
-            json = jsonMapper.writeValueAsString(error);
+            json = jsonMapper.writeValueAsString(response);
         } catch (Exception e) {

Review Comment:
   ๐Ÿ’ก **Nit:** The fallback string omits `"message"`, which is a **required** 
field in a JSON-RPC 2.0 error object (ยง5.1: *"message โ€” A String providing a 
short description of the error"*). This path only fires if Jackson itself fails 
to serialize two plain `LinkedHashMap` instances โ€” essentially impossible โ€” but 
the fix is trivial:
   
   ```suggestion
               json = "{\"jsonrpc\":\"" + McpSchema.JSONRPC_VERSION + 
"\",\"error\":{\"code\":" + code
                       + ",\"message\":\"" + message.replace("\\", 
"\\\\").replace("\"", "\\\"") + "\"}}";
   ```



-- 
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]

Reply via email to