Skip to content

Conversation

@mattpodwysocki
Copy link
Contributor

@mattpodwysocki mattpodwysocki commented Dec 18, 2025

Problem

The Mapbox Search Box API returns country as a top-level property in feature.properties, but the output schema didn't include it.

This causes validation warnings when using the MCP server:

✗ Validation Error: data.features[0].properties should NOT have additional properties

Real API Response Example

Testing search_and_geocode_tool(q="Paris") returns:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [2.348392, 48.853495]
      },
      "properties": {
        "name": "Paris",
        "place_formatted": "France",
        "feature_type": "place",
        "coordinates": {
          "longitude": 2.348392,
          "latitude": 48.853495
        },
        "maki": "marker",
        "country": "France"  // ← This property was missing from schema
      }
    }
  ]
}

Note that country appears at the top level of properties, not just nested in context.country.name.

Solution

  1. Added country: z.string().optional() to SearchBoxFeaturePropertiesSchema
  2. Added .passthrough() to allow future API additions without breaking

The API returns country in both places:

  • properties.country: "France" (top-level, for convenience)
  • properties.context.country.name: "France" (nested, full context)

Now the schema accepts both structures without validation warnings.

Testing

✅ All 31 existing tests pass
✅ Validated against real API responses
✅ No breaking changes

mattpodwysocki and others added 5 commits December 17, 2025 15:51
Adds optional 'compact' parameter (default: true) to reverse_geocode_tool
that significantly reduces response size while maintaining valid GeoJSON
structure and all useful information.

Changes:
- Added 'compact' boolean parameter to input schema (default: true)
- Implemented compactGeoJsonResponse() that:
  - Removes verbose 'attribution' field
  - Flattens nested 'context' object to simple properties
  - Removes internal mapbox_ids and metadata
  - Keeps all useful location data (name, address, coordinates, hierarchy)
- Updated execute() to use compact format for structuredContent
- Both json_string and formatted_text formats use compact data

Benefits:
- ~90% reduction in response size (100+ lines → ~20 lines)
- Valid GeoJSON maintained (type: FeatureCollection + features: [])
- All useful information preserved (name, address, coordinates, hierarchy)
- Easier for AI agents to parse (flatter structure)
- Backward compatible (set compact: false for full response)

Example compact output:
{
  "type": "FeatureCollection",
  "features": [{
    "type": "Feature",
    "geometry": { "type": "Point", "coordinates": [-76.998, 36.003] },
    "properties": {
      "name": "620 Mardre Road",
      "full_address": "620 Mardre Road, Windsor, NC 27983, US",
      "feature_type": "address",
      "coordinates": { "longitude": -76.998, "latitude": 36.003 },
      "address": "620 Mardre Road",
      "postcode": "27983",
      "place": "Windsor",
      "district": "Bertie County",
      "region": "North Carolina",
      "country": "United States"
    }
  }]
}

Tests:
- Added test for compact format (default behavior)
- Updated existing test to use compact: false
- All 393 tests passing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Adds compact parameter (default: true) to search_and_geocode_tool to reduce
response size by ~90% while maintaining valid GeoJSON structure.

- Removes attribution, external_ids, mapbox_id, metadata
- Flattens nested context object into direct properties
- Keeps essential fields: name, address, coordinates, poi_category, brand, maki
- Maintains valid GeoJSON structure for use in geojson.io and other tools
- Backward compatible with compact: false for full verbose response

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Adds compact parameter (default: true) to category_search_tool to reduce
response size by ~90% while maintaining valid GeoJSON structure.

- Removes attribution, external_ids, mapbox_id, metadata
- Flattens nested context object into direct properties
- Keeps essential fields: name, address, coordinates, poi_category, brand, maki
- Maintains valid GeoJSON structure for use in geojson.io and other tools
- Backward compatible with compact: false for full verbose response

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Mapbox Search Box API returns 'country' as a top-level property in
feature.properties, but the output schema didn't include it.

This causes validation warning when using the MCP server:
✗ Validation Error: data.features[0].properties should NOT have
  additional properties

Changes:
1. Added country: z.string().optional() to SearchBoxFeaturePropertiesSchema
2. Added .passthrough() to allow future API additions without breaking

The API returns both:
- properties.country: "France" (top-level, for convenience)
- properties.context.country.name: "France" (nested, full context)

Now schema accepts both structures without validation warnings.

Testing:
✓ All 31 tests pass
✓ Validated against real API responses
@mattpodwysocki mattpodwysocki requested a review from a team as a code owner December 18, 2025 19:36
@mattpodwysocki mattpodwysocki merged commit 2f63f77 into main Dec 18, 2025
5 checks passed
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.

2 participants