-
-
Notifications
You must be signed in to change notification settings - Fork 7
Fix: Grok 4 compatibility for Mapbox MCP and model selection #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughThree files updated: Grok model references changed from Grok-3 and Grok-4-fast-non-reasoning to Grok-4; geospatial tool mappings and argument schemas refactored to align with new MCP tool identifiers while maintaining control flow. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Overall, solid and focused fixes—these should resolve recent breakages around the Grok/Mapbox tooling. |
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/agents/tools/geospatial.tsx (1)
151-216: Consider refactoring the lengthy tool description.The tool description spans 65+ lines and contains detailed documentation for all sub-tools. While comprehensive, this makes the code harder to maintain and read.
Consider one of these approaches:
- Extract to separate documentation file:
// Import description from external file import { GEOSPATIAL_TOOL_DESCRIPTION } from './descriptions/geospatial-tool-description'; export const geospatialTool = ({ uiStream }) => ({ description: GEOSPATIAL_TOOL_DESCRIPTION, parameters: geospatialQuerySchema, // ... });
- Create a concise summary with reference to external docs:
description: `Provides comprehensive location-based query capabilities including: - Static map image generation - Category search for POIs - Reverse geocoding and address lookup - Route directions and distance calculation - Isochrone analysis for reachable areas - Location search and geocoding See docs/geospatial-tools.md for detailed feature documentation.`,
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (3)
components/settings/components/model-selection-form.tsx(1 hunks)lib/agents/tools/geospatial.tsx(1 hunks)lib/utils/index.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
lib/agents/tools/geospatial.tsx (1)
components/map/map-query-handler.tsx (3)
GeospatialToolOutput(18-23)toolOutput(33-74)MapQueryHandlerProps(25-28)
🔇 Additional comments (2)
lib/utils/index.ts (1)
33-33: Model ID verified as correct.The model ID 'grok-4' is a valid alias for the xAI API's Grok 4 model (official model name: grok-4-0709). The change from 'grok-4-fast-non-reasoning' to 'grok-4' is appropriate.
components/settings/components/model-selection-form.tsx (1)
31-33: The review comment is based on an incorrect premise.The original concern about a case mismatch between "Grok-4" (UI) and "grok-4" (API) assumes that the
selectedModelform value is passed to the API. However, verification shows this is not the case:
- The form collects
selectedModelbut it is never used anywhere in the codebase (search fordata.selectedModelreturned zero results)- The
onSubmitfunction (lines 90-130) only callssaveSystemPrompt()with the system prompt;selectedModelis not passed to any function- The
getModel()function is hardcoded and called with no parameters across the entire codebase—it always returns a fixed model (currently xai('grok-4') if XAI_API_KEY is set), regardless of form selectionThe model selection form appears to be non-functional as currently implemented. There is no case sensitivity issue because the form value never reaches the API layer.
Likely an incorrect or invalid review comment.
| case 'directions': return prefer('calculate_distance') | ||
| case 'distance': return prefer('calculate_distance'); | ||
| case 'search': return prefer('search_nearby_places'); | ||
| case 'map': return prefer('generate_map_link') | ||
| case 'reverse': return prefer('geocode_location'); | ||
| case 'geocode': return prefer('geocode_location'); | ||
| } | ||
| })(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Tool name mappings updated correctly for new MCP server.
The tool name mappings have been updated to match the new MCP server identifiers. The logic correctly handles multiple query types mapping to the same underlying MCP tool (e.g., both 'directions' and 'distance' use 'calculate_distance', both 'reverse' and 'geocode' use 'geocode_location').
To confirm these tool names match the MCP server's current interface, verify the available tools by checking the server's tool listing output at lines 122-126 during runtime, or consult the Mapbox MCP server documentation.
🌐 Web query:
What are the available tool names in the Mapbox MCP server version 1.0.0?
💡 Result:
The Mapbox MCP Server exposes these tools: MatrixTool, StaticMapTool, POISearchTool, CategorySearchTool, ForwardGeocodeTool, ReverseGeocodeTool, DirectionsTool, and IsochroneTool. [1][2]
Sources:
[1] Mapbox mcp-server README (GitHub).
[2] Mapbox MCP Server docs — Tools list.
Tool name mappings are incorrect and will cause runtime failures.
The tool names in lines 253-258 do not exist in the Mapbox MCP server. The Mapbox MCP Server exposes these tools: MatrixTool, StaticMapTool, POISearchTool, CategorySearchTool, ForwardGeocodeTool, ReverseGeocodeTool, DirectionsTool, and IsochroneTool.
The code references non-existent tool names:
'calculate_distance'- does not exist'search_nearby_places'- does not exist'generate_map_link'- does not exist'geocode_location'- does not exist
These must be mapped to the correct Mapbox MCP server tool names. For example, 'directions' and 'distance' likely correspond to DirectionsTool or MatrixTool, 'search' corresponds to POISearchTool or CategorySearchTool, 'reverse' and 'geocode' correspond to ReverseGeocodeTool or ForwardGeocodeTool, etc.
🤖 Prompt for AI Agents
In lib/agents/tools/geospatial.tsx around lines 253 to 260, the case arms map to
non-existent MCP tool names and will fail at runtime; replace the incorrect
names with the actual Mapbox MCP tool names: map 'directions' ->
prefer('DirectionsTool'), map 'distance' -> prefer('MatrixTool') (or
DirectionsTool if matrix isn't available in your usage), map 'search' ->
prefer('POISearchTool') (or 'CategorySearchTool' if you need category-based
search), map 'map' -> prefer('StaticMapTool'), and map both 'reverse' and
'geocode' -> prefer('ReverseGeocodeTool') or use 'ForwardGeocodeTool' for
forward geocoding; update each return to use those exact tool names so they
match the MCP server.
| case 'directions': return { from: params.origin, to: params.destination, profile: params.mode, includeRouteMap: includeMap }; | ||
| case 'distance': return { from: params.origin, to: params.destination, profile: params.mode || 'driving', includeRouteMap: includeMap }; | ||
| case 'reverse': return { query: `${params.coordinates.latitude},${params.coordinates.longitude}`, includeMapPreview: includeMap, maxResults: params.maxResults || 5 }; | ||
| case 'search': return { location: params.location, query: params.query, radius: params.radius || 1000, limit: params.maxResults || 5, includeMapPreview: includeMap }; | ||
| case 'geocode': return { query: params.location, includeMapPreview: includeMap, maxResults: params.maxResults || 5 }; | ||
| case 'map': return { location: params.location, includeMapPreview: includeMap }; | ||
| } | ||
| })(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Verify argument schemas match the new MCP server interface.
The argument construction has been updated significantly to align with the new MCP tool interfaces. Each query type now provides tailored arguments with appropriate defaults. However, please verify that these argument names and structures match the expected input schema for the new MCP server tools.
Run the following script to check if there are any callers of geospatialTool that might need updates for the new schema:
🏁 Script executed:
#!/bin/bash
# Find all usages of geospatialTool to verify they're compatible with new schema
ast-grep --pattern 'geospatialTool($$$)'
# Also search for files that import geospatialTool
rg -n -B 2 -A 10 "import.*geospatialTool" --type=ts --type=tsxLength of output: 261
🏁 Script executed:
#!/bin/bash
# Find the geospatialTool function definition
rg -n -A 30 "export.*function.*geospatialTool|const.*geospatialTool.*=" lib/agents/tools/geospatial.tsx --type=ts --type=tsx
# Find where geospatialQueryTool is called/invoked
rg -n -B 3 -A 3 "geospatialQueryTool\(" --type=ts --type=tsxLength of output: 55
🏁 Script executed:
#!/bin/bash
# Find the geospatialTool function definition - search all tsx/ts files without type flag
rg -n -A 35 "export.*function.*geospatialTool|const.*geospatialTool.*=" -g "*.tsx" -g "*.ts"
# Find where geospatialQueryTool is called/invoked
rg -n -B 3 -A 3 "geospatialQueryTool\(" -g "*.tsx" -g "*.ts"
# Also check the full context around the argument construction in geospatial.tsx
cat lib/agents/tools/geospatial.tsx | head -300 | tail -80Length of output: 7112
🏁 Script executed:
#!/bin/bash
# Search for MCP server definitions, schemas, or configuration files
find . -type f \( -name "*schema*" -o -name "*mcp*" -o -name "*.md" \) -not -path "*/node_modules/*" | head -20
# Search for mapbox-related configuration or types
rg -n "mapbox|MCP|mcp" -g "*.json" -g "*.ts" -g "*.tsx" --max-count=5 | grep -i "schema\|tool\|interface" | head -30
# Check if there are any test files that might reveal expected argument schemas
find . -path "*/test*" -o -path "*/__tests__/*" | grep -i "geospatial\|mcp" | head -10
# Search for any inline schema or type definitions for tool arguments
rg -n "calculate_distance|search_nearby_places|geocode_location|generate_map_link" -g "*.ts" -g "*.tsx" -B 5 -A 5Length of output: 9285
🏁 Script executed:
#!/bin/bash
# Check mapbox_mcp_config.json for schema definitions
cat mapbox_mcp_config.json
# Search for generate_map_link usage
rg -n "generate_map_link" -g "*.ts" -g "*.tsx" -B 3 -A 3Length of output: 2012
Fix argument schema mismatches with MCP tool calls.
The argument construction includes parameters that don't match the verified tool call patterns in mapbox_mcp/hooks.ts:
- Lines 267 & 269 (
geocode_location): Remove unsupportedmaxResultsparameter - Line 268 (
search_nearby_places): Remove unsupportedincludeMapPreviewparameter - Line 270 (
generate_map_link): Verify expected arguments (no usage examples found in hooks)
Compare against verified implementations in mapbox_mcp/hooks.ts lines 164–206 where these tools are called successfully with different argument sets.
🤖 Prompt for AI Agents
In lib/agents/tools/geospatial.tsx around lines 265 to 272 the constructed
argument objects mismatch the MCP tool schemas: remove the unsupported
maxResults property from the geocode case (line ~267/269), remove
includeMapPreview from the search case (line ~268), and adjust/confirm the map
case (generate_map_link) to match the expected argument set (it likely only
needs location or other specific fields) — update those return objects to
exactly match the call shapes used in mapbox_mcp/hooks.ts (lines 164–206) so
each tool call passes only supported keys.
User description
This PR addresses two issues that arose after the migration to Grok 4:\n\n1. Mapbox MCP Tool Names: The tool names in
lib/agents/tools/geospatial.tsxwere updated to match the new names used by the Mapbox MCP server, which were causing the MCP calls to fail.\n2. Grok Model ID: The model ID inlib/utils/index.tsandcomponents/settings/components/model-selection-form.tsxwas updated fromGrok-3toGrok-4to ensure the correct model is being selected and used.PR Type
Bug fix, Enhancement
Description
Updated Grok model ID from
grok-4-fast-non-reasoningtogrok-4Migrated Mapbox MCP tool names to match new server API
Refactored tool argument structures for Mapbox compatibility
Updated model selection UI to reflect Grok-4 availability
Diagram Walkthrough
File Walkthrough
index.ts
Update Grok model ID to grok-4lib/utils/index.ts
grok-4-fast-non-reasoningtogrok-4getModel()functiongeospatial.tsx
Migrate Mapbox MCP tool names and argumentslib/agents/tools/geospatial.tsx
directions_tool→calculate_distance)distance, search, reverse, geocode, map)
waypoints→from/to,searchText→query)includeMapPreview→includeRouteMapfor directions/distance)model-selection-form.tsx
Update model selection UI to Grok-4components/settings/components/model-selection-form.tsx
Grok-3toGrok-4Grok-4pnpm-lock.yaml
Update dependency lock filepnpm-lock.yaml
Summary by CodeRabbit
New Features
Updates