Skip to content

Conversation

@mattpodwysocki
Copy link
Contributor

Problem

The Mapbox Search Box API can return metadata (including primary_photo and Japanese reading information) for various feature types in forward geocoding results, not just category searches. Currently, SearchAndGeocodeTool.output.schema.ts doesn't include a metadata field, which could lead to validation errors when the API returns this data.

Solution

Added the metadata field to SearchBoxFeaturePropertiesSchema with the same structure used in CategorySearchTool:

  • primary_photo: Accepts both string and array of strings using z.union([z.string(), z.array(z.string())])
  • reading: Optional Japanese reading information (ja_kana, ja_latin)

This matches the existing fix in CategorySearchTool (PR #77) and prevents validation failures.

Testing

  • ✅ All 397 tests pass
  • ✅ Build succeeds
  • ✅ Schema correctly handles both string and array formats for primary_photo

Related

🤖 Generated with Claude Code

mattpodwysocki and others added 4 commits January 2, 2026 14:05
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>
The Mapbox Search Box API can return metadata (including primary_photo
and Japanese reading information) for various feature types returned by
forward geocoding searches, not just category searches.

This change adds the metadata field to SearchAndGeocodeTool.output.schema
to match the existing implementation in CategorySearchTool, which already
handles the primary_photo field as a union type (string or array).

Fixes potential validation errors when the API returns metadata for POI
features in forward geocoding results.

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@mattpodwysocki mattpodwysocki requested a review from a team as a code owner January 2, 2026 19:10
@mattpodwysocki mattpodwysocki added ai and removed ai labels Jan 2, 2026
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