fix: directions_tool geojson always returns coordinates, any trip length - #255
Open
mattpodwysocki wants to merge 1 commit into
Open
fix: directions_tool geojson always returns coordinates, any trip length#255mattpodwysocki wants to merge 1 commit into
mattpodwysocki wants to merge 1 commit into
Conversation
An agent asking for raw coordinates (geometries="geojson") got them
directly in the response for a short trip, but for a long one (reported:
London to a point in Scotland) the response exceeded 50KB and the tool
silently swapped to a completely different contract -- geometry and legs
stripped out, replaced by a mapbox://temp/... resource URI that isn't
even a fetchable HTTP URL. There was no way for a caller to know in
advance which contract it would get, since the split was driven by trip
length rather than anything the caller controlled.
Root cause: the tool always requested overview=full (maximum-precision
geometry) regardless of trip length. New optional `overview` input
("full" | "simplified") now defaults to "simplified" whenever
geometries="geojson" (matching the parameter optimization_tool already
exposes, and already defaults to). Confirmed live against the real
Directions API: a real London->Edinburgh route (~420 miles) drops from
10,057 coordinate pairs / ~700KB down to 46 pairs / ~4.7KB under
simplified overview -- comfortably inside the response limit, and still a
fully accurate, drawable line. overview="full" stays available as an
explicit opt-in for callers who need maximum precision, accepting the
same large-response fallback as before.
Tradeoff: the Directions API rejects the congestion annotation unless
overview=full (422, confirmed live) -- distance/speed annotations have no
such restriction. congestion_information is now correctly omitted (not
reported as a misleading all-zero breakdown, which the code did
previously whenever congestion was unavailable for any reason) when it
wasn't requested. render_map_tool's live map preview is unaffected either
way, since it already always fetches its own full-detail geometry
client-side, independent of directions_tool's own response.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
4 tasks
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.
Summary
Someone trying the MCP server reported that their agent, building an app, couldn't get a drawable route for a long trip (London to a point in Scotland) — it kept burning cycles on a size-based contract split it had no way to anticipate.
Root cause:
geometries="geojson"always requestedoverview=full(maximum-precision geometry) regardless of trip length. For a short trip this fits comfortably in the response; for a long one it can be tens of thousands of coordinate pairs, blowing past the 50KB threshold — at which point the tool silently swapped to a completely different contract: geometry and legs stripped out, replaced by amapbox://temp/...resource URI. That URI isn't even a fetchable HTTP URL — it only works via the MCP resources API — so an agent trying to embed the route in generated app code had nothing usable.Fix: new optional
overviewinput ("full" | "simplified"), defaulting to"simplified"whenevergeometries="geojson"(and to"full"whengeometries="none", unchanged, since no geometry is returned there either way). This mirrors theoverviewparameteroptimization_toolalready exposes — and already defaults to"simplified"— which is presumably why that tool never needed this kind of large-response fallback in the first place.Confirmed live against the real Directions API: a real London→Edinburgh route (~420 miles) drops from 10,057 coordinate pairs / ~700KB (
overview=full) to 46 coordinate pairs / ~4.7KB (overview=simplified) — comfortably inside the response limit, and still a fully accurate, drawable line.overview="full"remains available as an explicit, documented opt-in for callers who need maximum precision, accepting the same large-response fallback as before (now a deliberate choice rather than a surprise past a size cliff).Tradeoff, documented in the schema: the Directions API rejects the
congestionannotation unlessoverview=full(422: Overview option must be full for congestion, confirmed live) —distance/speedannotations have no such restriction and stay accurate at any level. Socongestion_informationis only present when the effective overview is"full". Along the way, fixed a real pre-existing bug: the code previously reported an all-zerocongestion_informationbreakdown whenever congestion happened to be unavailable, which reads as "confirmed no traffic" rather than "not checked" — it's now correctly omitted instead.render_map_tool's live map preview is unaffected either way — it already always fetches its own full-detail geometry client-side (mapbox://selffetch/directions...), independent of whatdirections_tool's own response contains.Acceptance criteria
geometries/overviewschema docs explain how to get coordinates vs. distance/duration/instructions, and what happens (rare, opt-in) when geometry is still large.render_map_toolpreview) still works for both short and long routes.CHANGELOG.mdrecords the behavior change under Unreleased.Test plan
npx vitest run— all 945 tests pass, including new coverage inbuildDirectionsRequestUrl.test.ts,cleanResponseData.test.ts, andDirectionsTool.test.ts(short + long route fixtures,congestion_informationomission)npm run buildsucceeds, lint cleangeometries="none"→ congestion still present; long route with explicitoverview="full"→ falls back to the old temp-resource behavior as documented🤖 Generated with Claude Code