[tools] Add compact parameter to reduce response verbosity and token costs #80
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
Adds a
compactparameter (default:true) to three geocoding/search tools to reduce structured response size by ~90% while maintaining valid GeoJSON structure. This significantly reduces token costs for AI agents consuming these responses without losing any useful information.Tools Updated
reverse_geocode_toolsearch_and_geocode_toolcategory_search_toolToken Cost Savings
Before (verbose response):
{ "type": "FeatureCollection", "attribution": "© 2024 Mapbox and its suppliers...", "features": [{ "type": "Feature", "properties": { "mapbox_id": "dXJuOm1ieHBvaTpkYjc1ZmU...", "feature_type": "poi", "name": "Starbucks", "full_address": "123 Main St, New York, NY 10001", "context": { "address": { "mapbox_id": "...", "name": "123 Main St", "address_number": "123", ... }, "street": { "mapbox_id": "...", "name": "Main Street" }, "postcode": { "mapbox_id": "...", "name": "10001" }, "place": { "mapbox_id": "...", "name": "New York", ... }, "region": { "mapbox_id": "...", "name": "New York", ... }, "country": { "mapbox_id": "...", "name": "United States", ... } }, "external_ids": { "foursquare": "..." }, "metadata": { "iso_3166_1": "US", ... }, "poi_category": ["coffee", "restaurant"], "brand": "Starbucks", ... }, "geometry": { "type": "Point", "coordinates": [-74.006, 40.7128] } }] }After (compact response - default):
{ "type": "FeatureCollection", "features": [{ "type": "Feature", "properties": { "name": "Starbucks", "full_address": "123 Main St, New York, NY 10001", "feature_type": "poi", "coordinates": { "longitude": -74.006, "latitude": 40.7128 }, "poi_category": ["coffee", "restaurant"], "brand": "Starbucks", "maki": "cafe", "address": "123 Main St", "street": "Main Street", "postcode": "10001", "place": "New York", "region": "New York", "country": "United States" }, "geometry": { "type": "Point", "coordinates": [-74.006, 40.7128] } }] }Result: ~90% reduction in structured content size for typical responses with 10 results.
What Changed
Removed (verbose metadata)
attributionfieldmapbox_idin every nested objectexternal_idsobjectmetadataobjectcontexthierarchy with repeated metadataKept (essential information)
Still Valid GeoJSON ✅
The compact format maintains the correct GeoJSON structure:
type: "FeatureCollection"at rootfeaturesarray with proper Feature objectsgeometrywith correct type and coordinatespropertiesobject (can contain any metadata per spec)The compact response can be directly used in geojson.io, Mapbox GL JS, or any other GeoJSON tool.
Implementation Details
compact: booleanparameter to input schemas (default:true)compactGeoJsonResponse()private method in each toolexecute()methods to conditionally use compact formatcompact: falsefor full verbose responsestructuredContentoutput (text output unchanged)Test Coverage
compact: falseBreaking Changes
None. This is backward compatible:
compact: true(new behavior)compact: falsestructuredContent)🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com