-
Notifications
You must be signed in to change notification settings - Fork 887
Handle schema validation failures gracefully #741
Copy link
Copy link
Open
Labels
P1Significant bug affecting many users, highly requested featureSignificant bug affecting many users, highly requested featureenhancementNew feature or requestNew feature or requestwaiting for userWaiting for user feedback or more detailsWaiting for user feedback or more details
Metadata
Metadata
Assignees
Labels
P1Significant bug affecting many users, highly requested featureSignificant bug affecting many users, highly requested featureenhancementNew feature or requestNew feature or requestwaiting for userWaiting for user feedback or more detailsWaiting for user feedback or more details
Type
Fields
Give feedbackNo fields configured for Enhancement.
When using the
DefaultMcpStatelessServerHandler#handleRequestmethod, the SDK throws various exceptions if the incoming request doesn't adhere to the MCP schema. Here are a couple examples I've observed:This causes an IllegalArgumentException to be thrown by
McpStatelessAsyncServerwhen Jackson attempts to parse theargumentsfield, which is supposed to be an Object:java-sdk/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessAsyncServer.java
Lines 395 to 399 in b518393
Here's a second example:
In this example, the
namefield was omitted. This causesMcpStatelessAsyncServerto throw a NullPointerException when it attempts to callname().equals(...):java-sdk/mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessAsyncServer.java
Lines 401 to 403 in b518393
Is there a way to validate the incoming JSON against the MCP schema before passing it to the handler object? Or can the handler object be enhanced to deal with these kinds of errors more gracefully and return a friendlier error to the caller? Thanks!