[tools] Update schemas to not fail upon parsing #74
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR improves the resilience of output schema validation across all tools by implementing
graceful fallback handling when API responses don't match expected schemas.
Changes
1. Fixed
brand_idschema validation error in SearchAndGeocodeToolbrand_idfromz.string()toz.union([z.string(), z.array(z.string())])inSearchAndGeocodeTool.output.schema.ts:99brand_idas an array instead of a single string, causingvalidation errors
2. Added standardized graceful validation fallback to BaseTool
validateOutput<T>()helper method toBaseTool(src/tools/BaseTool.ts:97-112)3. Updated VersionTool to use graceful validation
validateOutput()helper methodBenefits
schema mismatches
hard failures
Testing
Unit Tests Added:
BaseTool validation tests (
test/tools/BaseTool.test.ts):SearchAndGeocodeTool brand_id tests
(
test/tools/search-and-geocode-tool/SearchAndGeocodeTool.output.schema.test.ts:319-375):brand_idas a string (e.g.,"starbucks-123")brand_idas an array of strings (e.g.,["brand-a-123", "brand-b-456"])Test Results:
Manual Verification:
The original error from the Search and Geocode tool:
MCP error -32602: Output validation error: Invalid structured content for tool
search_and_geocode_tool: Expected string, received array at path features[4].properties.brand_id
is now resolved - the tool accepts both string and array formats for
brand_id.Checklist
Additional Notes