-
Notifications
You must be signed in to change notification settings - Fork 492
Description
Problem
MCP clients like Claude Code serialize complex object parameters as JSON strings rather than actual JavaScript objects. The Zod validation in the MCP server rejects these because it expects objects, not strings.
For example, calling query_requests with a filter like:
{"request_response_rmt": {"request_id": {"equals": "some-uuid"}}}fails with a Zod invalid_type error (expected: object, received: string) because the client sends the value as a JSON string rather than a parsed object.
The "all" literal filter works fine since it's already a string.
Suggested fix
Use z.preprocess to transparently parse JSON strings before Zod validation, keeping the existing schema validation intact:
const jsonPreprocess = (schema) => z.preprocess(
(val) => {
if (typeof val === "string" && val !== "all") {
try { return JSON.parse(val); } catch { return val; }
}
return val;
},
schema
);Then in index.ts:
filter: jsonPreprocess(requestFilterNodeSchema).optional(),
sort: jsonPreprocess(sortLeafRequestSchema).optional(),This would make the MCP server resilient to both native objects and JSON-serialized strings, without losing any input validation.
Affected parameters
filteronquery_requestssortonquery_requestsfilteronquery_sessions