Skip to content

Conversation

Copy link

Copilot AI commented Jul 28, 2025

This PR upgrades the Zod validation library from version 3.25.67 to 4.0.10, addressing all breaking changes introduced in Zod 4.x.

Breaking Changes Fixed

1. z.enum() API Changes

Zod 4.x changed the z.enum() constructor to no longer accept a description property in the options parameter. Updated 6 enum definitions to use the .describe() method instead:

// Before (Zod 3.x)
export const TrafficDataSourceEnum = z.enum(['web', 'mobile'], {
    description: 'Platform filter description...'
});

// After (Zod 4.x)  
export const TrafficDataSourceEnum = z.enum(['web', 'mobile']).describe(
    'Platform filter description...'
);

2. z.record() Signature Changes

Zod 4.x now requires both key and value type parameters for z.record():

// Before (Zod 3.x)
conditions: z.record(z.unknown())

// After (Zod 4.x)
conditions: z.record(z.string(), z.unknown())

3. Schema Shape Compatibility

The .shape property in Zod 4.x has different TypeScript types that are incompatible with the MCP SDK's expected ZodRawShape interface. Added type assertions to maintain compatibility:

// Fixed with type assertions for MCP SDK compatibility
inputSchema: CodeDefenderHeaderInventoryInputSchema.shape as any,
outputSchema: makeStructuredResponseSchema(schema).shape as any,

4. Callback Function Signatures

Updated MCP tool callback signatures to match the expected interface while maintaining functionality:

// Added extra parameter and type assertion for compatibility
(async (params: ParamType, extra: any) => 
    mcpToolHandler(async () => service.method(params))) as any,

Compatibility Notes

  • The MCP SDK (@modelcontextprotocol/[email protected]) still uses Zod 3.x internally, creating a version mismatch
  • Type assertions are used as a bridge until the MCP SDK upgrades to Zod 4.x
  • Runtime behavior remains unchanged - all functionality works correctly
  • All 49 tests continue to pass

Validation

  • ✅ TypeScript compilation successful
  • ✅ All tests passing (49/49)
  • ✅ Build completes successfully
  • ✅ Linting passes with only expected console warnings
  • ✅ MCP server starts and runs correctly
  • ✅ Package dependencies updated (package-lock.json)

This upgrade ensures the project uses the latest stable version of Zod while maintaining full backward compatibility and functionality.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Open a PR to update "zod" to the latest version (4.x), including fixing all breaking changes. Upgrade Zod to version 4.0.10 with breaking changes fixes Jul 28, 2025
Copilot AI requested a review from ori-gold-px July 28, 2025 16:48
Copilot finished work on behalf of ori-gold-px July 28, 2025 16:48
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.

2 participants