feat: Add API request validator tool#76
feat: Add API request validator tool#76mattpodwysocki wants to merge 2 commits intofeature/api-endpoint-explorerfrom
Conversation
Add validate_api_request_tool to validate Mapbox API requests against endpoint definitions before sending them to the API. Features: - Validates required parameters are present - Checks parameter types (string, number, boolean, array, object) - Validates enum constraints for parameters with allowed values - Verifies token has required scopes for operations - Detects extra/unknown parameters with warnings - Returns detailed validation results with specific error messages - Helps prevent failed API calls by catching issues early Validation coverage: - Path, query, and body parameters - Type checking with clear error messages - Enum validation (e.g., routing profiles, geocoding modes) - Token scope verification - Case-insensitive API and operation names Implementation: - Uses endpoint definitions from mapboxApiEndpoints.ts (from PR #75) - Implements comprehensive validation logic - 19 test cases covering all validation scenarios - Proper MCP structured content with separated text and data - Updated tool registry and documentation This tool builds on top of explore_mapbox_api_tool by using the same endpoint definitions to provide validation capabilities. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
| content: [ | ||
| { | ||
| type: 'text', | ||
| text: `❌ API "${input.api}" not found. Use explore_mapbox_api_tool to see available APIs.` |
There was a problem hiding this comment.
I can see how it might backfire, e.g. new APIs, is this a valid concern or how we avoid that?
Addresses feedback from PR review about handling new/unknown APIs. Changes: - Updated class docstring to explain this validates against a curated list of known APIs - Improved error message when API not found to be more helpful and acknowledge limitation - Updated tool description to clarify it only validates known APIs - Added note in README about the limitation and how to handle new APIs The tool now clearly communicates that: 1. It validates against a curated, known list of APIs 2. New Mapbox APIs may not be included yet 3. Users can check official docs for newer APIs 4. Requests can still be made without validation This prevents confusion when legitimate newer APIs aren't recognized. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
Addressed the feedback about handling new APIs! Changes MadeI've updated the tool to clearly communicate that it validates against a curated list of known APIs, not all possible Mapbox APIs: 1. Updated Class DocumentationAdded a note explaining:
2. Improved Error MessageWhen an API isn't found, the new message:
3. Updated Tool DescriptionNow says "known endpoint definitions" and clarifies the limitation upfront. 4. Added README NoteAdded a visible note in the README explaining the limitation and how to handle it. Why This WorksThis approach:
The tool is designed as a quality-of-life helper for common APIs, not a comprehensive validator for every possible Mapbox endpoint. Users working with brand new APIs can skip validation and proceed directly to testing. If new APIs become popular, contributors can add them to |
Summary
Implements
validate_api_request_toolto validate Mapbox API requests against endpoint definitions before sending them. Builds on top of PR #75 (API Endpoint Explorer) by reusing the endpoint definitions frommapboxApiEndpoints.ts.This PR targets
feature/api-endpoint-explorer(PR #75) and should be merged after #75 is merged.Features
Use Cases
Implementation
BaseToolwith proper input/output schemasMAPBOX_API_ENDPOINTSfrom PR feat: Add API endpoint explorer tool #75Testing
Test Coverage
Example Usage
{ "api": "geocoding", "operation": "forward-geocode", "parameters": { "path": { "mode": "mapbox.places", "query": "San Francisco" }, "query": { "access_token": "pk.test" } }, "tokenScopes": ["geocoding:read", "styles:read"] }Returns: Detailed validation result with ✅/❌ status, parameter summary, and specific error messages.
Documentation
explore_mapbox_api_toolby providing validation capabilitiesDependencies
mapboxApiEndpoints.tsfrom the API Explorer toolfeature/api-endpoint-explorerbranch🤖 Generated with Claude Code