Skip to content

[Feature]: Support Zod 4 in @ag-ui/mastra #2874

Closed

Description

@T0nete

Pre-flight Checklist

  • I have searched existing issues and this hasn't been requested yet.

Problem or Motivation

Problem or Motivation

Following up on #1397 for the @ag-ui/mastra package specifically.

As of @ag-ui/mastra@1.1.4, its published package.json declares zod: "^3.25.76" as a dependency. Applications using Zod 4 therefore install a separate Zod 3 copy for the adapter.

This is becoming awkward when @ag-ui/mastra is used alongside libraries that require Zod 4. For example, @rekog/mcp-nest@2.x, a NestJS library for building MCP servers, declares zod: "^4.3.5" as a peer dependency. Downgrading the application's Zod version to 3.x causes npm dependency resolution to fail.

@mastra/client-js and @mastra/core already accept both Zod 3 and Zod 4 in their peer dependency ranges. It would be useful for the AG-UI Mastra adapter to support applications using Zod 4 as well.

Proposed Solution

Test @ag-ui/mastra against Zod 4 and update its dependency declaration to support Zod 4 if the adapter is compatible. If code changes are needed, it would be helpful to document what is required before the dependency range can be widened.

Could the related @ai-sdk/ui-utils dependency also be checked? An npm install with @ag-ui/mastra@1.1.4 can produce an ERESOLVE overriding peer dependency warning involving @mastra/client-js, @ai-sdk/ui-utils, and the nested Zod 3 copy. Updating the adapter's Zod range alone may not remove that warning.

Additional Context

Related broader request: #1397.

Alternatives Considered

No response

Additional Context

No response

Activity

  1. NathanTarbert commented on Oct 2, 2026

    @NathanTarbert
    Contributor

    Hey @T0nete, thanks for opening the issue. I've added support for Zod 4 to the roadmap.

  2. added
    RoadmapThis feature or functionality should be added to the roadmap.
    on Oct 2, 2026
  3. moved this to Under consideration in Road Mapon Oct 2, 2026
  4. sander-su commented on Oct 6, 2026

    @sander-su
    Contributor

    Could the Zod 4 support here come "for free" by moving @ag-ui/mastra off @ai-sdk/ui-utils onto the current AI SDK?
    (I asked my agent to do some summary thingies :) )

    From what I can see on @ag-ui/mastra@1.1.4, the only thing pulling in @ai-sdk/ui-utils (and with it the pinned zod@^3.25.76) is a single import of a single function — parsePartialJson:
    import { parsePartialJson } from "@ai-sdk/ui-utils";

    @ai-sdk/ui-utils is an AI SDK v4-era package that peers zod@^3.23.8, so an app on Zod 4 ends up with a second, nested Zod 3 copy — which is the ERESOLVE overriding peer dependency warning mentioned above.

    The same parsePartialJson is exported by the current AI SDK (the ai package, and @ai-sdk/provider-utils), which @mastra/core already depends on and which accepts zod@^3.25.0 || ^4.0.0. The return shape looks identical, with one difference I want to confirm:

    // @ai-sdk/ui-utils (v4): synchronous
    parsePartialJson(text): { value; state }
    
    // ai / @ai-sdk/provider-utils (current): async
    parsePartialJson(text): Promise<{ value; state }>
    

    So the questions:

    Is parsePartialJson the only reason @ai-sdk/ui-utils is a dependency, or does the adapter use anything else from it?
    Would replacing that import with the one from the AI SDK already in the tree (and await-ing it at the one call site) be enough to drop @ai-sdk/ui-utils entirely — and in doing so let the Zod range widen to ^3.25.0 || ^4.0.0 (matching @mastra/core and @mastra/client-js)?
    If it's not that simple, what else is in the way? (e.g. the sync→async change rippling into a sync stream-transform path, or a behavioral difference in the newer parsePartialJson.)
    

    Also, would making zod a peer dependency (as proposed in #2518) rather than a pinned dependency be preferred here, so the host app controls the Zod version regardless of this specific swap?

  5. sander-su commented on Oct 27, 2026

    @sander-su
    Contributor

    #3224 fixes this. It drops @ai-sdk/ui-utils (the source of the nested Zod 3 copy) by vendoring a synchronous parsePartialJson, the same way Mastra did in mastra-ai/mastra#27297, and widens the adapter's zod range to ^3.25.76 || ^4.0.0. In a consumer install with Zod 4, the adapter now resolves the app's own Zod.

    It supersedes #3007, which took the ai@5 route.

  6. moved this from Under consideration to Done in Road Mapon Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    RoadmapThis feature or functionality should be added to the roadmap.enhancementNew feature or request

    Type

    No type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions