Skip to content

fix(server): support Zod v4 in query parameter type detection#13963

Open
intojhanurag wants to merge 3 commits intomastra-ai:mainfrom
intojhanurag:fix/zod4-query-param-type-detection
Open

fix(server): support Zod v4 in query parameter type detection#13963
intojhanurag wants to merge 3 commits intomastra-ai:mainfrom
intojhanurag:fix/zod4-query-param-type-detection

Conversation

@intojhanurag
Copy link
Contributor

@intojhanurag intojhanurag commented Mar 7, 2026

Description

wrapSchemaForQueryParams relied on _def.typeName to detect complex schema types (objects, arrays, records) that need JSON parsing from query strings.
Zod v4 uses _def.type with lowercase values ("object", "optional", "array", "record") instead of Zod v3's _def.typeName ("ZodObject", "ZodOptional", "ZodArray", "ZodRecord"). This caused isComplexType() to return false for all fields, so complex query params like date ranges were never wrapped with jsonQueryParam() — the raw JSON string failed validation with "Invalid query parameters".

The fix updates getZodTypeName() to check both _def.typeName (v3) and _def.type (v4), and uses Set lookups for both naming conventions in isComplexType().

Before

image

After

image

Related Issue(s)

Fixes #13962

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test update

Checklist

  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works

Summary by CodeRabbit

  • Bug Fixes
    • Fixed parsing of complex query parameters (objects, arrays, records) so date-range, tag, and metadata filters no longer trigger "Invalid query parameters" errors.
    • Restored consistent filter behavior in Studio Observability UI and the server API for projects using newer schema tooling.

Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
@changeset-bot
Copy link

changeset-bot bot commented Mar 7, 2026

🦋 Changeset detected

Latest commit: 3bb37d6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 21 packages
Name Type
@mastra/server Patch
@mastra/deployer Patch
@mastra/express Patch
@mastra/fastify Patch
@mastra/hono Patch
@mastra/koa Patch
mastra Patch
@mastra/deployer-cloud Patch
@mastra/deployer-cloudflare Patch
@mastra/deployer-netlify Patch
@mastra/deployer-vercel Patch
create-mastra Patch
@mastra/core Patch
@internal/playground Patch
mastracode Patch
@mastra/mcp-docs-server Patch
@mastra/client-js Patch
@mastra/opencode Patch
@mastra/longmemeval Patch
@mastra/playground-ui Patch
@mastra/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Mar 7, 2026

@intojhanurag is attempting to deploy a commit to the Mastra Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d68482e5-5a90-46b4-a3ff-11d3d37f24e2

📥 Commits

Reviewing files that changed from the base of the PR and between d2e7ec5 and 3bb37d6.

📒 Files selected for processing (1)
  • .changeset/fix-zod4-query-param-detection.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/fix-zod4-query-param-detection.md

Walkthrough

Normalize Zod type inspection to support Zod v3 and v4, classify optional and complex types, and wrap detected complex query-parameter fields for JSON parsing to fix invalid query parameter errors for date ranges, tags, and metadata.

Changes

Cohort / File(s) Summary
Changeset Documentation
.changeset/fix-zod4-query-param-detection.md
Adds a patch changelog entry documenting the fix for complex query parameter detection/parsing across Zod v3 and v4.
Zod compatibility & query param handling
packages/server/src/server/server-adapter/routes/route-builder.ts
Refactors Zod type handling: adds OPTIONAL_TYPES and COMPLEX_TYPES, makes getZodTypeName read _def.typeName or _def.type, unwraps optional/nullable via _def.innerType, and uses this classification to wrap complex fields with jsonQueryParam.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is clear and directly related to the main changeset, describing the fix for Zod v4 support in query parameter detection without being overly broad.
Linked Issues check ✅ Passed The PR addresses the root cause from issue #13962 by updating Zod type detection logic to support both v3 and v4 naming conventions for complex query parameters.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing Zod v4 compatibility in query parameter type detection; no unrelated modifications were introduced.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.changeset/fix-zod4-query-param-detection.md:
- Around line 5-7: Rewrite the changeset to describe the user-visible server
fix: explain that `@mastra/server` now correctly parses complex query parameters
(objects, arrays, records) when projects use Zod v4 so features like date-range
filters, tag filters and metadata filters in the server API/Studio work again;
remove internal implementation details about _def.typeName or _def.type and keep
the focus on the observable behavior change; ensure the frontmatter only
references `@mastra/server` and that the body is phrased for end users (what
changed and why it matters) rather than internal symbol names, but you can
mention wrapSchemaForQueryParams in a short note if needed to locate the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f1481887-2ca5-42bc-853c-f65b07cc5a04

📥 Commits

Reviewing files that changed from the base of the PR and between d1a08c0 and 88e44b7.

📒 Files selected for processing (2)
  • .changeset/fix-zod4-query-param-detection.md
  • packages/server/src/server/server-adapter/routes/route-builder.ts

Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
.changeset/fix-zod4-query-param-detection.md (1)

5-7: ⚠️ Potential issue | 🟡 Minor

Rewrite this as a package-scoped release note.

This still reads like a commit title, and it mentions Studio even though the frontmatter only lists @mastra/server. Keep the entry focused on the server behavior users get from this package.

Suggested rewrite
-fix(server): fix complex query parameter parsing for Zod v4 projects
-
-Projects using Zod v4 would get "Invalid query parameters" errors when using date-range filters, tag filters, or metadata filters in the Studio Observability UI and server API. Complex query parameters (objects, arrays, records) are now correctly detected and parsed regardless of whether the project uses Zod v3 or v4.
+Fixed complex query parameter parsing in `@mastra/server` for projects using Zod v4.
+
+Server routes now correctly parse JSON-encoded query parameters for objects, arrays, and records. This fixes requests that previously failed with invalid query parameter errors.

potential_issue

As per coding guidelines, "Avoid commit messages, technical jargon, and acronyms" and "Check that the description inside the changeset file only applies to the packages listed in the frontmatter."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.changeset/fix-zod4-query-param-detection.md around lines 5 - 7, Rewrite the
changeset entry so it is a package-scoped release note for `@mastra/server`
(remove any mention of Studio and commit-style phrasing like "fix(...)").
Replace the title/body starting with "fix(server): fix complex query parameter
parsing for Zod v4 projects" with a plain English release note that states the
user-facing change: that `@mastra/server` now correctly detects and parses complex
query parameters (objects, arrays, records) — including date-range, tag, and
metadata filters — for projects using Zod v4, preventing "Invalid query
parameters" errors; keep it concise and non-technical and ensure it only
references the `@mastra/server` package listed in the frontmatter.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In @.changeset/fix-zod4-query-param-detection.md:
- Around line 5-7: Rewrite the changeset entry so it is a package-scoped release
note for `@mastra/server` (remove any mention of Studio and commit-style phrasing
like "fix(...)"). Replace the title/body starting with "fix(server): fix complex
query parameter parsing for Zod v4 projects" with a plain English release note
that states the user-facing change: that `@mastra/server` now correctly detects
and parses complex query parameters (objects, arrays, records) — including
date-range, tag, and metadata filters — for projects using Zod v4, preventing
"Invalid query parameters" errors; keep it concise and non-technical and ensure
it only references the `@mastra/server` package listed in the frontmatter.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 75a428f8-0812-45bd-87a8-bf8850283edd

📥 Commits

Reviewing files that changed from the base of the PR and between 88e44b7 and d2e7ec5.

📒 Files selected for processing (1)
  • .changeset/fix-zod4-query-param-detection.md

Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
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.

[BUG] Studio Observability Date Filter Invalid Parameters

2 participants