Skip to content

zod 4 bump is blocked by zod-to-openapi's prototype patch order #1316

Open

Description

@neuromechanist

Found while gating the MCP SDK's peer dependency in #1314 (phase 1 of #1065). @modelcontextprotocol/server@2.0.0 depends on zod ^4.2.0; the repo pins ^3.23.x in root and backend/package.json, so the SDK runs on its own nested zod 4 copy while the shared contracts stay on zod 3 (the two-copy risk the phase 1 plan named).

What blocks the bump

bun run typecheck goes green under zod 4 after mechanical fixes (the z.record two-argument form landed in #1314; z.SafeParseReturnType renames to z.ZodSafeParseResult). bun test does not: backend/test/openapi-document.test.ts fails with strictVersionTagSchema.openapi is not a function. scripts/generate-openapi.ts calls @asteasolutions/zod-to-openapi's extendZodWithOpenApi(z), which patches ZodType.prototype.openapi. Under zod 3 the patch is retroactive; under zod 4 a schema constructed before the patch never sees it. Root bun test runs test/ and backend/test/ in one process, and many earlier files import shared/contract/*, so the un-patched prototype is cached for the whole suite. Bumping zod-to-openapi to ^9.1.0 (zod 4 peer) does not change this.

Options

  • Add a bunfig.toml [test] preload that runs extendZodWithOpenApi(z) before any other module, and import the same side-effect module first in scripts/generate-openapi.ts.
  • Drop zod-to-openapi and generate the OpenAPI document from zod 4's native z.toJSONSchema() plus .meta(), which needs no prototype patch at all (make versus take, ADR 0037).

The second option removes the order dependency instead of working around it. Either way the bump is a standalone PR with bun test and bun run typecheck green, not a side effect of the MCP epic. See .context/mcp-server-design.md section 10.1 once #1314 merges.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions