-
Notifications
You must be signed in to change notification settings - Fork 29
[FUTURE] Task-based optimization tool for async execution #92
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
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]>
- Upgrade @modelcontextprotocol/sdk from 1.21.1 to 1.25.1 - Remove old SDK 1.21.1 patch - Apply SDK 1.25.1 patch with icons support and output validation fixes - Update version to 0.8.1 to match main branch - All 422 tests passing This brings the task-based optimization branch up to date with the latest SDK and includes the necessary patches for proper operation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
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.
Prisma Cloud has found errors in this PR ⬇️
| "dependencies": { | ||
| "@mcp-ui/server": "^5.13.1", | ||
| "@modelcontextprotocol/sdk": "^1.21.1", | ||
| "@modelcontextprotocol/sdk": "^1.25.1", |
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.
@modelcontextprotocol/sdk 1.25.1 / package.json
Total vulnerabilities: 1
| Critical: 0 | High: 1 | Medium: 0 | Low: 0 |
|---|
| Vulnerability ID | Severity | CVSS | Fixed in | Status |
|---|---|---|---|---|
| CVE-2026-0621 | - | - |
Open |
Closing this PRThis PR is superseded by #94 (offline_tools branch). What's in #94 now:
Why V1 instead of V2?The V2 API endpoint ( When will V2 be enabled?Once the V2 API becomes publicly available, we can enable it by uncommenting one line in the toolRegistry. The code is ready to go! Closing this PR as the work is preserved and ready for future activation. 🤖 Generated with Claude Code |
|
Superseded by #94 |
Overview
This PR contains a task-based implementation of the optimization tool using the MCP Tasks API (experimental, SDK 1.25.1+).
Status: DRAFT - Not ready to merge until MCP clients add task support.
Why Task-based?
The Optimization API can take 5-10 seconds to complete, which blocks the agent during execution. A task-based approach allows:
Implementation
registerToolTaskfrom MCP SDK experimental tasks APIcreateTask: Submits job to Mapbox API, returns immediately with task IDgetTask: Returns current task statusgetTaskResult: Returns final optimization results when completeCurrent Blocker: No Client Support
Tested with:
When to Merge
This PR can be merged when:
Files Changed
src/tools/optimization-tool/OptimizationTask.ts- New task-based implementationsrc/index.ts- Task store, capabilities, and registrationsrc/tools/BaseTool.ts- Type assertion workarounds for SDK issue #985src/prompts/OptimizeDeliveriesPrompt.ts- Updated for task-based executionRelated
🤖 Generated with Claude Code