[tools] Update schemas to not fail upon parsing #43
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
Makes output schema validation non-fatal for tools, matching the pattern established in
mapbox/mcp-server#74.
Changes
Added
validateOutputhelper to BaseTool (src/tools/BaseTool.ts:111-132)Updated 3 tools to use graceful validation:
safeParsewithvalidateOutputhelpersafeParsewithvalidateOutputhelpersafeParsewithvalidateOutputhelperImpact
Before: When API responses deviated from expected schemas (but were still valid), tools would
fail with schema validation errors.
After: Tools log warnings and continue operating with raw data, improving resilience while
maintaining debuggability through logged validation issues.
Key Benefits
✅ Non-fatal validation - Schema mismatches log warnings instead of failing tool operations
✅ Better resilience - Tools work even when API responses change slightly
✅ Maintained debuggability - Validation failures still logged at warning level
✅ Consistent pattern - All tools follow the same graceful validation approach
Tests
New Unit Tests
Added 3 unit tests verifying graceful schema validation fallback:
ListStylesTool (test/tools/list-styles-tool/ListStylesTool.test.ts:271-313)
CreateTokenTool (test/tools/create-token-tool/CreateTokenTool.test.ts:366-402)
ListTokensTool (test/tools/list-tokens-tool/ListTokensTool.test.ts:568-605)
Test Results
✅ All 286 tests passing (283 original + 3 new)
✅ Build successful
✅ No new linting issues
Each test verifies three critical behaviors:
Checklist
Additional Notes