Skip to content

Conversation

@mattpodwysocki
Copy link
Contributor

Problem

The Mapbox Search Box API can return metadata fields (including primary_photo and Japanese reading information) for various feature types in forward geocoding results. 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 (fixed in PR #77):

metadata: z
  .object({
    // API sometimes returns string, sometimes array - accept both
    primary_photo: z.union([z.string(), z.array(z.string())]).optional(),
    reading: z
      .object({
        ja_kana: z.string().optional(),
        ja_latin: z.string().optional()
      })
      .optional()
  })
  .optional()

This prevents validation failures when the Mapbox API returns metadata for POIs and other features.

Testing

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

Related

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.5 [email protected]

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

This fix adds the metadata field with the same structure used in
CategorySearchTool (fixed in PR #77):
- primary_photo: Accepts both string and array of strings
- reading: Optional Japanese reading information (ja_kana, ja_latin)

This prevents validation failures when the API returns metadata fields.

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

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@mattpodwysocki mattpodwysocki merged commit b616c0a into main Jan 5, 2026
5 checks passed
@mattpodwysocki mattpodwysocki deleted the fix-search-geocode-metadata-schema branch January 5, 2026 15:11
mattpodwysocki added a commit that referenced this pull request Jan 5, 2026
This commit resolves critical installation failures that prevented users
from running the package via `npx @mapbox/mcp-server`.

## Issues Fixed

When users ran `npx @mapbox/mcp-server`, they encountered:
```
sh: mcp-server: command not found
```

This was caused by multiple installation script failures that prevented
npm from properly setting up the binary.

## Changes

### 1. Fixed patch-package Dependency Issue

**Problem:** The postinstall script runs patch-package, but it was only
in devDependencies. End users don't get dev dependencies, causing
postinstall to fail.

**Solution:**
- Moved patch-package from devDependencies to dependencies
- Added patches/ directory to files array in package.json
- Ensures patches are included in published package

### 2. Updated MCP SDK and Regenerated Patches

**Problem:** Patch was for @modelcontextprotocol/[email protected], but the ^
version allowed 1.25.1 to be installed, causing patch failures.

**Solution:**
- Updated SDK dependency to ^1.25.1
- Regenerated patches for new SDK version
- Removed old 1.21.1 patch file
- Updated src/tools/BaseTool.ts with type annotations required by new SDK

### 3. Fixed prepare Script for End Users

**Problem:** The prepare script checked for .git directory, but when
users installed the package in THEIR git repo, it found their .git and
tried to run husky (which wasn't installed), causing failures.

**Solution:** Changed check from .git to .husky/setup-hooks.js:
```javascript
// Before: Checks .git (exists in any git repo)
"prepare": "... require('fs').accessSync('.git') ..."

// After: Checks for actual setup file (only in dev environment)
"prepare": "... require('fs').accessSync('.husky/setup-hooks.js') ..."
```

This ensures prepare only runs in the development environment of this
package, not when installed as a dependency.

## Testing

Verified the package works correctly:

```bash
# Clean install test
cd /tmp
npx --yes "@mapbox/[email protected]"
# ✅ Server starts successfully
```

Integration tests confirm:
- ✅ All dependencies install correctly
- ✅ MCP SDK patches apply successfully
- ✅ mcp-server binary created and executable
- ✅ Server runs without errors
- ✅ All tools (SearchAndGeocode, CategorySearch, ReverseGeocode) working
- ✅ Schema validation working with metadata fields (PR #86)
- ✅ Non-fatal validation working (PR #73)

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

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
mattpodwysocki added a commit that referenced this pull request Jan 5, 2026
This commit resolves critical installation failures that prevented users
from running the package via `npx @mapbox/mcp-server`.

When users ran `npx @mapbox/mcp-server`, they encountered:
```
sh: mcp-server: command not found
```

This was caused by multiple installation script failures that prevented
npm from properly setting up the binary.

**Problem:** The postinstall script runs patch-package, but it was only
in devDependencies. End users don't get dev dependencies, causing
postinstall to fail.

**Solution:**
- Moved patch-package from devDependencies to dependencies
- Added patches/ directory to files array in package.json
- Ensures patches are included in published package

**Problem:** Patch was for @modelcontextprotocol/[email protected], but the ^
version allowed 1.25.1 to be installed, causing patch failures.

**Solution:**
- Updated SDK dependency to ^1.25.1
- Regenerated patches for new SDK version
- Removed old 1.21.1 patch file
- Updated src/tools/BaseTool.ts with type annotations required by new SDK

**Problem:** The prepare script checked for .git directory, but when
users installed the package in THEIR git repo, it found their .git and
tried to run husky (which wasn't installed), causing failures.

**Solution:** Changed check from .git to .husky/setup-hooks.js:
```javascript
// Before: Checks .git (exists in any git repo)
"prepare": "... require('fs').accessSync('.git') ..."

// After: Checks for actual setup file (only in dev environment)
"prepare": "... require('fs').accessSync('.husky/setup-hooks.js') ..."
```

This ensures prepare only runs in the development environment of this
package, not when installed as a dependency.

Verified the package works correctly:

```bash
cd /tmp
npx --yes "@mapbox/[email protected]"
```

Integration tests confirm:
- ✅ All dependencies install correctly
- ✅ MCP SDK patches apply successfully
- ✅ mcp-server binary created and executable
- ✅ Server runs without errors
- ✅ All tools (SearchAndGeocode, CategorySearch, ReverseGeocode) working
- ✅ Schema validation working with metadata fields (PR #86)
- ✅ Non-fatal validation working (PR #73)

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

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
mattpodwysocki added a commit that referenced this pull request Jan 5, 2026
This commit resolves critical installation failures that prevented users
from running the package via `npx @mapbox/mcp-server`.

When users ran `npx @mapbox/mcp-server`, they encountered:
```
sh: mcp-server: command not found
```

This was caused by multiple installation script failures that prevented
npm from properly setting up the binary.

**Problem:** The postinstall script runs patch-package, but it was only
in devDependencies. End users don't get dev dependencies, causing
postinstall to fail.

**Solution:**
- Moved patch-package from devDependencies to dependencies
- Removed duplicate patch-package entry in devDependencies (caused by rebase)
- Added patches/ directory to files array in package.json
- Ensures patches are included in published package

**Problem:** Patch was for @modelcontextprotocol/[email protected], but the ^
version allowed 1.25.1 to be installed, causing patch failures.

**Solution:**
- Updated SDK dependency to ^1.25.1
- Regenerated patches for new SDK version
- Removed old 1.21.1 patch file
- Updated src/tools/BaseTool.ts with type annotations required by new SDK

**Problem:** The prepare script checked for .git directory, but when
users installed the package in THEIR git repo, it found their .git and
tried to run husky (which wasn't installed), causing failures.

**Solution:** Changed check from .git to .husky/setup-hooks.js:
```javascript
// Before: Checks .git (exists in any git repo)
"prepare": "... require('fs').accessSync('.git') ..."

// After: Checks for actual setup file (only in dev environment)
"prepare": "... require('fs').accessSync('.husky/setup-hooks.js') ..."
```

This ensures prepare only runs in the development environment of this
package, not when installed as a dependency.

**Problem:** TypeScript "Type instantiation is excessively deep" errors
after rebasing onto PR #73 with SDK 1.25.1.

**Solution:** Added type assertions (`as any`) to break complex type
inference chains in:
- src/tools/BaseTool.ts (registerTool call)
- src/index.ts (setRequestHandler call)

These assertions are necessary workarounds for TypeScript's limitations
with deeply nested generic types in the MCP SDK.

Verified the package works correctly:

```bash
cd /tmp
npx --yes "@mapbox/[email protected]"
```

Integration tests confirm:
- ✅ All dependencies install correctly
- ✅ MCP SDK patches apply successfully
- ✅ mcp-server binary created and executable
- ✅ Server runs without errors
- ✅ All tools (SearchAndGeocode, CategorySearch, ReverseGeocode) working
- ✅ Schema validation working with metadata fields (PR #86)
- ✅ Non-fatal validation working (PR #73)

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

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
mattpodwysocki added a commit that referenced this pull request Jan 5, 2026
This commit resolves critical installation failures that prevented users
from running the package via `npx @mapbox/mcp-server`.

When users ran `npx @mapbox/mcp-server`, they encountered:
```
sh: mcp-server: command not found
```

This was caused by multiple installation script failures that prevented
npm from properly setting up the binary.

**Problem:** The postinstall script runs patch-package, but it was only
in devDependencies. End users don't get dev dependencies, causing
postinstall to fail.

**Solution:**
- Moved patch-package from devDependencies to dependencies
- Removed duplicate patch-package entry in devDependencies (caused by rebase)
- Added patches/ directory to files array in package.json
- Ensures patches are included in published package

**Problem:** Patch was for @modelcontextprotocol/[email protected], but the ^
version allowed 1.25.1 to be installed, causing patch failures.

**Solution:**
- Updated SDK dependency to ^1.25.1
- Regenerated patches for new SDK version
- Removed old 1.21.1 patch file
- Updated src/tools/BaseTool.ts with type annotations required by new SDK

**Problem:** The prepare script checked for .git directory, but when
users installed the package in THEIR git repo, it found their .git and
tried to run husky (which wasn't installed), causing failures.

**Solution:** Changed check from .git to .husky/setup-hooks.js:
```javascript
// Before: Checks .git (exists in any git repo)
"prepare": "... require('fs').accessSync('.git') ..."

// After: Checks for actual setup file (only in dev environment)
"prepare": "... require('fs').accessSync('.husky/setup-hooks.js') ..."
```

This ensures prepare only runs in the development environment of this
package, not when installed as a dependency.

**Problem:** TypeScript "Type instantiation is excessively deep" errors
after rebasing onto PR #73 with SDK 1.25.1.

**Solution:** Added type assertions (`as any`) to break complex type
inference chains in:
- src/tools/BaseTool.ts (registerTool call)
- src/index.ts (setRequestHandler call)

These assertions are necessary workarounds for TypeScript's limitations
with deeply nested generic types in the MCP SDK.

Verified the package works correctly:

```bash
cd /tmp
npx --yes "@mapbox/[email protected]"
```

Integration tests confirm:
- ✅ All dependencies install correctly
- ✅ MCP SDK patches apply successfully
- ✅ mcp-server binary created and executable
- ✅ Server runs without errors
- ✅ All tools (SearchAndGeocode, CategorySearch, ReverseGeocode) working
- ✅ Schema validation working with metadata fields (PR #86)
- ✅ Non-fatal validation working (PR #73)

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

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
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