-
Notifications
You must be signed in to change notification settings - Fork 29
Add Map Matching and Optimization tools #89
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
Add two new prompts to guide users through using the Map Matching and Optimization tools added in PR #89. New Prompts: - clean-gps-trace: Clean and snap noisy GPS traces to roads * Guides through parsing GPS coordinates * Uses map_matching_tool with proper parameters * Shows before/after visualization with confidence scores * Example: "Clean up this GPS trace from my bike ride" - optimize-deliveries: Optimize multi-stop routes * Handles address geocoding automatically * Configures optimization with shipments format * Shows optimized route with efficiency metrics * Example: "Optimize my delivery route for these addresses" Changes: - Added CleanGpsTracePrompt.ts with map matching workflow - Added OptimizeDeliveriesPrompt.ts with route optimization workflow - Updated promptRegistry.ts with new prompts - Added comprehensive tests in promptRegistry.test.ts - Updated README.md with example prompts Testing: - All 424 tests passing ✓ - New prompt metadata tests verify correct structure - Prompts follow kebab-case naming convention 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Implements two new Mapbox Navigation API tools: - Map Matching Tool (map_matching_tool): Snaps GPS traces to roads - Supports 2-100 coordinates with optional timestamps and radiuses - Returns confidence scores, matched geometry, and annotations - Handles driving, cycling, walking, and driving-traffic profiles - Optimization Tool (optimization_tool): Solves vehicle routing problems - Supports up to 1000 coordinates - Simplified mode: auto-generates vehicle and services - Advanced mode: custom vehicles, services, shipments, time windows - Async polling mechanism (POST + GET) Both tools include: - Complete input/output schemas with Zod validation - Comprehensive unit tests (19 tests total) - Proper annotations (readOnlyHint, openWorldHint, etc.) All 422 tests passing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
This commit converts the OptimizationTool from a synchronous blocking tool
to an async task-based tool using the experimental MCP Tasks API.
**Problem:** The Optimization API v2 is long-running (up to 10 seconds with
polling), blocking the agent from doing other work while waiting for results.
**Solution:** Implemented task-based execution using MCP SDK 1.25.1's
experimental tasks API:
- **src/tools/optimization-tool/OptimizationTask.ts** (NEW): Task-based
implementation with three handlers:
- createTask: Submits optimization job to Mapbox API, returns immediately
without blocking
- getTask: Returns current task status (pending, working, completed, failed)
- getTaskResult: Returns final optimization results when complete
- Background polling runs asynchronously with proper error handling
- **src/index.ts**: Added task support to server
- Created InMemoryTaskStore and InMemoryTaskMessageQueue
- Updated server capabilities to include tasks: { requests: { tools: { call: {} } } }
- Registered OptimizationTask instead of synchronous OptimizationTool
- Fixed "Type instantiation is excessively deep" error in GetPromptRequestSchema
handler with type assertions (workaround for MCP SDK 1.25.1 issue #985)
- **src/tools/BaseTool.ts**: Fixed TypeScript compilation error
- Added type assertions to break complex type inference chains
- Workaround for "Type instantiation is excessively deep" errors with
MCP SDK 1.25.1 generic types
**Benefits:**
- Non-blocking execution - returns task ID immediately
- Agent can do other work while optimization runs in background
- Progress updates via task status messages
- Proper error handling and timeout management
- All existing tests pass (422 tests)
- Zero TypeScript compilation errors
**Testing:**
- Server starts successfully with task support
- All 422 existing tests pass
- Build completes without errors
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
- Add OptimizeDeliveriesPrompt for the task-based optimization tool - Guides agent through route optimization workflow - References async task-based execution - Provides clear instructions for displaying results - Add CleanGpsTracePrompt for the map matching tool - Guides agent through GPS trace cleaning/snapping - Shows before/after visualization approach - Includes quality metrics and statistics - Register both new prompts in promptRegistry.ts All tests passing (422 tests) and build successful.
No MCP clients currently support the experimental Tasks API: - MCP Inspector: task support not available - Claude Desktop/CLI: returns error -32601 (task augmentation required) - Goose: falls back to other tools Changes: - Remove task-based OptimizationTask.ts implementation - Re-enable synchronous OptimizationTool.ts (with polling) - Remove task capabilities from server (taskStore, InMemoryTaskStore, etc.) - Update OptimizeDeliveriesPrompt to remove task-based language - Tool now blocks for 5-10 seconds during optimization (necessary trade-off) The synchronous version: - Works in all current MCP clients - Still does async polling internally (POST job, GET results) - Returns results when optimization completes - All 422 tests passing We can convert back to task-based when clients add support. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
9611892 to
08a6ca3
Compare
The Mapbox Optimization API v2 is currently in beta and not accessible to all users. This commit migrates to the publicly available V1 API. Key changes: - Changed from async job submission (POST + polling) to synchronous GET - Updated coordinate limit from 1000 to 12 (V1 constraint) - Simplified input schema: removed vehicles/services/shipments complexity - Updated output schema: changed from routes/stops to waypoints/trips - Updated prompt to reflect V1 limitations and synchronous behavior - Rewrote all tests (11 tests) to match V1 API format All tests passing (11/11). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
✅ Updated: Optimization API V1 Migration CompleteThe OptimizationTool has been migrated from the beta V2 API to the publicly available V1 API. Changes MadeAPI Migration:
Schema Updates:
Code Changes:
Testing:
Why This Change?The Mapbox Optimization API v2 is currently in beta and not accessible to all Mapbox users. Migrating to V1 ensures the tool works for everyone with a public Mapbox account. Impact
Commit: f489d33 |
Closing this PRThis PR is superseded by #94 (offline_tools branch). What's in #94 now:
Why switch to V1?The V2 optimization API (
What about V2 features?The V2 implementation from this PR has been preserved as Closing this PR as all functionality is now in #94. 🤖 Generated with Claude Code |
|
Superseded by #94 |
Summary
Implements two new Mapbox Navigation API tools and their companion prompts to expand API coverage:
Map Matching Tool (
map_matching_tool)Optimization Tool (
optimization_tool)New Prompts
optimize-deliveriesGuides agents through route optimization workflow:
clean-gps-traceGuides agents through GPS trace cleaning:
Implementation Details
Tools
Prompts
Test Coverage
All 422 tests passing ✅
Why These Tools?
These were the last two major Mapbox Navigation APIs not yet implemented in the public MCP server:
The prompts make these tools more discoverable and provide clear usage patterns for AI agents.
Note on Task-based Implementation
An async task-based version of the optimization tool was explored but reverted because no MCP clients currently support the experimental Tasks API (Inspector, Claude Desktop/CLI, Goose all fail with task augmentation errors). The current synchronous version works in all clients. A separate PR will track the task-based implementation for when client support becomes available.
Test plan
🤖 Generated with Claude Code