Skip to content

feat: use MCP sampling to classify grounding strategy#173

Open
mattpodwysocki wants to merge 1 commit intofeat/ground-location-toolfrom
feat/ground-location-sampling
Open

feat: use MCP sampling to classify grounding strategy#173
mattpodwysocki wants to merge 1 commit intofeat/ground-location-toolfrom
feat/ground-location-sampling

Conversation

@mattpodwysocki
Copy link
Copy Markdown
Contributor

Summary

Enhances ground_location_tool with MCP sampling to intelligently classify what kind of location grounding a query needs before making any Mapbox API calls.

Grounding strategies

Strategy Geocode types POI search Isochrone
neighborhood neighborhood, locality, place if query given yes
routing address, poi if query given no
poi neighborhood, locality, place always (min 15 results) no
region region, district, place if query given yes

How it works

When the client supports sampling, the tool sends a short classification prompt to the LLM asking it to pick one of the four strategies. The response shapes which Mapbox APIs are called and what parameters are used — e.g. routing gets types=address,poi for precise routable coordinates, while poi boosts the result limit to at least 15.

Graceful degradation: Falls back to neighborhood (current behavior) if:

  • Client does not advertise sampling capability
  • Sampling returns an unrecognised value
  • Sampling throws an error

No changes to the tool's public interface, schema, or registry wiring.

Test plan

  • 7 unit tests covering all strategies, fallback cases, and limit boosting
  • npm test passes
  • npm run build succeeds

🤖 Generated with Claude Code

…ion_tool

When the client supports sampling, ground_location_tool asks the LLM to
classify the query intent into one of four strategies before making any
Mapbox API calls:

- neighborhood: reverse geocode at neighborhood/locality level + isochrone
- routing: reverse geocode at address/poi level for precise routable coords
- poi: category search with boosted limit (min 15), no isochrone
- region: reverse geocode at region/district level + isochrone

Falls back gracefully to 'neighborhood' if sampling is not supported,
returns an unexpected classification, or throws an error — so existing
clients are unaffected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mattpodwysocki mattpodwysocki requested a review from a team as a code owner April 1, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant