Reapply "Merge pull request #33 from mapbox/output_schemas" #36
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 branch introduces structured output schemas for MCP tools to improve type safety and enable better validation of tool responses. The changes affect 82 files with 2,506 additions and 1,326 deletions.
Key Changes
1. Schema Architecture
New Files Created
src/schemas/style.ts(242 new lines)BaseStylePropertiesSchemawith.passthrough()to preserve API metadataTool Schema Separation
All tools now have separate input and output schemas:
*.schema.ts→*.input.schema.ts*.output.schema.tsfiles for each tool2. Core Tool Infrastructure
BaseTool (
src/tools/BaseTool.ts)outputSchemaparameter to constructorinstallTo()to register output schemas with MCPMapboxApiBasedTool (
src/tools/MapboxApiBasedTool.ts)isValidJwtFormat())fetchRequesttohttpRequestparameterhttpRequest: HttpRequest3. HTTP Pipeline Refactor
Renamed & Restructured
src/utils/fetchRequest.ts→src/utils/httpPipeline.tstest/utils/fetchRequest.test.ts→test/utils/httpPipeline.test.tstest/utils/fetchRequestUtils.ts→test/utils/httpPipelineUtils.tsNew Utilities
src/utils/jwtUtils.ts(53 new lines)getUserNameFromToken()- Extract username from JWTmapboxAccessToken()- Get access token from envmapboxApiEndpoint()- Get API endpoint with fallbacktest/utils/jwtUtils.test.ts(79 new lines)4. Tool Updates
All tools updated with output schemas and structured content:
BoundingBoxTool
BoundingBoxTool.input.schema.tsBoundingBoxTool.output.schema.ts(18 lines)[minX, minY, maxX, maxY]arrayCountryBoundingBoxTool
CountryBoundingBoxTool.input.schema.tsCountryBoundingBoxTool.output.schema.ts(20 lines)CoordinateConversionTool
CoordinateConversionTool.input.schema.tsCoordinateConversionTool.output.schema.ts(16 lines)CreateStyleTool
CreateStyleTool.input.schema.ts(17 lines)CreateStyleTool.output.schema.ts(30 lines)BaseStylePropertiesSchemaCallToolResultinstead of throwingCreateTokenTool
CreateTokenTool.input.schema.tsCreateTokenTool.output.schema.ts(20 lines)DeleteStyleTool
DeleteStyleTool.input.schema.ts(unchanged)GeojsonPreviewTool
GeojsonPreviewTool.input.schema.tsGetMapboxDocSourceTool
GetMapboxDocSourceTool.input.schema.tsListStylesTool
ListStylesTool.input.schema.tsListStylesTool.output.schema.ts(10 lines)response.okbefore schema validationBaseStylePropertiesSchemaListTokensTool
ListTokensTool.input.schema.ts(unchanged)ListTokensTool.output.schema.ts(26 lines)PreviewStyleTool
PreviewStyleTool.input.schema.ts(unchanged)RetrieveStyleTool
RetrieveStyleTool.input.schema.ts(unchanged)RetrieveStyleTool.output.schema.ts(30 lines)BaseStylePropertiesSchemaStyleBuilderTool
StyleBuilderTool.input.schema.tsStyleComparisonTool
StyleComparisonTool.schema.ts(updated)TilequeryTool
TilequeryTool.input.schema.tsTilequeryTool.output.schema.ts(77 lines)UpdateStyleTool
UpdateStyleTool.input.schema.ts(25 lines)UpdateStyleTool.output.schema.ts(29 lines)BaseStylePropertiesSchema5. Test Fixes & Improvements
Test Infrastructure
setupHttpRequest()fromhttpPipelineUtilshttpRequestto tool constructorsStyleBuilderTool Tests (
test/tools/style-builder-tool/StyleBuilderTool.test.ts)Fixed Issues:
base_style: 'streets' as any→'streets-v12'(5 occurrences)render_type: 'symbol'overrides (8 occurrences)ListStylesTool Tests (
test/tools/list-styles-tool/ListStylesTool.test.ts)Fixed Issues:
sources: {}andlayers: []to mock dataCreateStyleTool Tests (
test/tools/create-style-tool/CreateStyleTool.test.ts)Fixed Issues:
styleobject (2 occurrences)MapboxApiBasedTool Tests (
test/tools/MapboxApiBasedTool.test.ts)Fixed Issues:
CallToolResultstructureTool Naming Convention Tests (
test/tools/tool-naming-convention.test.ts)Fixed Issues:
httpRequestfromsetupHttpRequest()for tool instantiationJWT Utils Tests (
test/utils/jwtUtils.test.ts)New File (79 lines)
getUserNameFromToken()6. Configuration Updates
Package.json
CSpell Configuration (
cspell.config.json)7. Test Results
All 228 tests passing ✅
Test Coverage:
Migration Guide
For Tool Developers
If you're creating a new tool or updating an existing one:
Split schemas:
Add output schema to constructor:
Return structured content:
Validate responses:
Check HTTP response before validation:
For Test Writers
Use httpPipelineUtils:
Provide httpRequest to tools:
Include required schema fields in mocks:
Benefits
Breaking Changes
Constructor Changes
All
MapboxApiBasedToolsubclasses now requirehttpRequestparameter:Error Handling
Tools now return
CallToolResultwithisError: trueinstead of throwing:Testing
Testing list styles:

Testing retrieve style:

Testing country bounding box:

Testing country bounding box on Claude Desktop:

Checklist
Additional Notes