Skip to content

Conversation

@jonathannorris
Copy link
Member

@jonathannorris jonathannorris commented Jul 18, 2025

Fix Zodios Validation Errors in MCP Tools

Problem

MCP tools were failing with "Zodios: Invalid response from endpoint" errors despite successful HTTP 200 API responses. Schema validation failed due to missing properties, type mismatches, and incomplete comparator enums in Zod schemas.

Solution

Core Changes

  • New handleZodiosValidationErrors utility - Extracts response data from validation errors when HTTP succeeds but schema validation fails
  • Enhanced Zod schemas - Added missing properties (_audiences, startWith/endWith comparators)
  • Environment controls - disable output schemas by default withENABLE_OUTPUT_SCHEMAS as they don't working Curosr and ENABLE_DVC_MCP_DEBUG for debug logs.

@jonathannorris jonathannorris requested a review from a team as a code owner July 18, 2025 15:44
@jonathannorris jonathannorris changed the base branch from main to chore-mcp-planning-doc July 18, 2025 15:44

This comment was marked as outdated.

@jonathannorris jonathannorris requested a review from Copilot July 18, 2025 18:31
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes Zodios validation errors in MCP tools by implementing error handling for cases where HTTP requests succeed (200 OK) but schema validation fails. The solution adds a new utility function to extract response data from validation errors and enhances Zod schemas with missing properties and comparators.

  • Introduces handleZodiosValidationErrors utility to gracefully handle validation failures
  • Updates Zod schemas to include missing properties (_audiences, filters, bucketingKey) and new comparators (startWith, endWith)
  • Adds environment variables to control output schema behavior and debug logging

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/mcp/utils/api.ts Adds handleZodiosValidationErrors utility and removes debug logging
src/ui/targetingTree.ts Adds missing string comparators to support new filter types
src/api/zodClient.ts Enhances Zod schemas with missing properties and comparators
src/mcp/server.ts Adds environment controls for output schemas and debug logging
src/api/apiClient.ts Fixes TypeScript type inference issues with explicit type annotations
src/mcp/tools/*.ts Wraps API calls with validation error handling across all tool files
Comments suppressed due to low confidence (1)

src/api/apiClient.ts:114

  • [nitpick] The variable name '_createApiClient' with underscore prefix suggests it's private, but it's just an alias. Consider a more descriptive name like 'createApiClientFn' or 'apiClientFactory'.
const _createApiClient = createApiClient

@jonathannorris jonathannorris requested a review from JamieSinn July 18, 2025 18:34
@jonathannorris jonathannorris merged commit f802290 into chore-mcp-planning-doc Jul 18, 2025
8 checks passed
@jonathannorris jonathannorris deleted the fix-zod-error-responses branch July 18, 2025 19:12
jonathannorris added a commit that referenced this pull request Jul 23, 2025
* fix: Zodios Validation Errors in MCP Tools

* chore: cleanup TS comments
jonathannorris added a commit that referenced this pull request Jul 25, 2025
* fix: Zodios Validation Errors in MCP Tools

* chore: cleanup TS comments
jonathannorris added a commit that referenced this pull request Aug 11, 2025
* fix: Zodios Validation Errors in MCP Tools

* chore: cleanup TS comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants