Add large response handling with temporary resources#114
Open
mattpodwysocki wants to merge 15 commits intomainfrom
Open
Add large response handling with temporary resources#114mattpodwysocki wants to merge 15 commits intomainfrom
mattpodwysocki wants to merge 15 commits intomainfrom
Conversation
Implements MCP server icons at the correct architectural level (server initialization) instead of at the tool level. Adds both light and dark theme variants of the Mapbox logo using base64-encoded SVG data URIs. - Add mapbox-logo-black.svg for light theme backgrounds - Add mapbox-logo-white.svg for dark theme backgrounds - Update server initialization to include icons array with theme property - Use 800x180 SVG logos embedded as base64 data URIs This replaces the previous incorrect approach of adding icons to individual tools, which was not aligned with the MCP specification. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Updates the MCP SDK from 1.25.1 to 1.25.2 and recreates the output validation patch for the new version. The patch continues to convert strict output schema validation errors to warnings, allowing tools to gracefully handle schema mismatches. Changes: - Update @modelcontextprotocol/sdk from ^1.25.1 to ^1.25.2 - Recreate SDK patch for version 1.25.2 - Remove obsolete 1.25.1 patch file - All 397 tests pass with new SDK version Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Implements conditional resource creation for DirectionsTool responses
that exceed 50KB to prevent context window overflow.
Features:
- New TemporaryResourceManager for in-memory resource storage
- Temporary resources with 30-minute TTL and automatic cleanup
- DirectionsTool detects large responses and creates resources
- Returns summary (distance, duration, resource URI) for large responses
- Full geometry available via MCP resource API: mapbox://temp/directions-{id}
- Small responses (<50KB) work unchanged
This addresses performance issues on long-distance routes (e.g., DC to NYC)
where detailed geometry can exceed context limits.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Added guidance in tool description to help LLMs choose appropriate geometry format: - Use geometries='none' for route planning and distance calculations - Only use geometries='geojson' for map visualization or detailed navigation This prevents unnecessary large responses and avoids the appearance of 'retry' behavior when Claude requests full geometry then realizes it's too large. Improves UX by guiding the LLM to make the right choice on first call.
When DirectionsTool creates a temporary resource for large responses, it now returns lightweight structured content containing: - Route summary data (distance, duration, leg summaries) - Waypoints - Custom _resourceUri and _truncated fields This satisfies the output schema validation without bloating the context window with large geometry data. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Use cleaned route fields (leg_summaries, intersecting_admins, etc.) instead of full legs array with required nested fields. Explicitly remove geometry and legs from structured content to keep it minimal. This prevents schema validation errors that were causing Claude Desktop to show "Tool execution failed" even though the tool succeeded. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
The prompt was instructing Claude to "get the route geometry" which caused it to request geometries="geojson" even for long routes. Now: - Explicitly requests geometries="none" for route metadata - Uses linear interpolation for sampling instead of extracting from geometry - Simplified sampling strategy to 5-7 points for all route lengths This aligns with the DirectionsTool optimization for large responses. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Contributor
Author
✅ Verification - Feature Working PerfectlyTested with query: "find gas stations between washington dc and new york" Observed BehaviorStep 1 - Route Planning:
Step 2 - Search Results:
Key Improvements Verified✅ No "Tool execution failed" errors Result: Feature working as designed! 🎉 |
Screenshots are visible in PR comment, no need to store in repo.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


Overview
Implements conditional resource creation for DirectionsTool responses that exceed 50KB to prevent context window overflow.
Fixes the issue where long-distance routes (e.g., Washington DC to New York) return massive JSON responses that exceed the LLM's context window.
Solution
Conditional Resource Creation:
mapbox://temp/directions-{id}Resource Management:
LLM Guidance:
geometries="none"for route planning,geometries="geojson"only for visualizationsearch-along-routeprompt to request compact responses by defaultSchema Compliance:
Example Output
Small Response (<50KB):
{ "routes": [...full route with geometry...], "waypoints": [...] }Large Response (>50KB):
Changes
TemporaryResourceManager- In-memory resource storage with TTLTemporaryDataResource- MCP resource handler for temporary dataDirectionsTool- Conditional resource creation for large responsesDirectionsTool- Description guides LLMs to usegeometries="none"for planningDirectionsTool- Returns schema-compliant structured content for large responsesSearchAlongRoutePrompt- Usesgeometries="none"and linear interpolation for samplingTesting
✅ Build passes with no TypeScript errors
✅ Small responses work unchanged
✅ Large responses create resources and return summaries with structured content
✅ Resources retrievable via MCP API
✅ Cleanup works correctly
✅ No validation warnings or errors in Claude Desktop
Impact
Future Work
This pattern can be extended to other tools that may return large datasets:
Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com