-
Notifications
You must be signed in to change notification settings - Fork 5
[tools] Update tools to use structuredContent with schema #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattpodwysocki I am running into this issue after switch to this branch, with cursor:

Disable this MCP or Switch to Main branch works well

| const errorBody = await response.text(); | ||
| this.log( | ||
| 'error', | ||
| `SearchAndGeocodeTool: API Error - Status: ${response.status}, Body: ${errorBody}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
☝️ this is Tilequery tool, not SearchAndGeocodeTool.
SearchAndGeocodeTool is in the other MCP servers.
Revert "Merge pull request #33 from mapbox/output_schemas"
This reverts commit 4853cac.
Reapply "Merge pull request #33 from mapbox/output_schemas"

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