Skip to content

fix(mcp): handle JSON-serialized object parameters from MCP clients#5611

Open
bobey wants to merge 2 commits intoHelicone:mainfrom
bobey:fix/mcp-json-string-params
Open

fix(mcp): handle JSON-serialized object parameters from MCP clients#5611
bobey wants to merge 2 commits intoHelicone:mainfrom
bobey:fix/mcp-json-string-params

Conversation

@bobey
Copy link

@bobey bobey commented Feb 27, 2026

Summary

Some MCP clients (e.g. Claude Code) serialize complex object parameters as JSON strings rather than native JavaScript objects. This causes Zod validation to reject valid filter/sort values with invalid_type errors (expected: object, received: string).

This PR adds a z.preprocess wrapper that transparently parses JSON strings before Zod validation runs, keeping all existing schema validation intact.

Affected parameters:

  • filter on query_requests
  • sort on query_requests
  • filter on query_sessions

Closes #5610

Some MCP clients serialize complex object parameters (filter, sort) as
JSON strings rather than native objects. Add a z.preprocess wrapper that
transparently parses JSON strings before Zod validation, keeping all
existing schema validation intact.

Closes Helicone#5610
@vercel
Copy link

vercel bot commented Feb 27, 2026

@bobey is attempting to deploy a commit to the Helicone Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

Extract jsonPreprocess into its own module for testability.
Add vitest with 8 tests covering:
- native objects passed through unchanged
- JSON strings parsed before validation
- "all" literal preserved
- invalid JSON rejected by schema
- nested filter schemas
- sort schemas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP: complex object parameters (filter, sort) fail with clients that serialize them as JSON strings

1 participant