Mapbox Geospatial Operations Skill
Expert guidance for AI assistants on choosing the right geospatial tools from the Mapbox MCP Server. Focuses on selecting tools based on what the problem requires - geometric calculations vs routing, straight-line vs road network, and accuracy needs.
Core Principle: Problem Type Determines Tool Choice
The Mapbox MCP Server provides two categories of geospatial tools:
- 1. Offline Geometric Tools - Use Turf.js for pure geometric/spatial calculations
- Routing & Navigation APIs - Use Mapbox APIs when you need real-world routing, traffic, or travel times
The key question: What does the problem actually require?
Decision Framework
| Problem Characteristic | Tool Category | Why |
|---|
| Straight-line distance (as the crow flies) | Offline geometric | Accurate for geometric distance |
| Road/path distance (as the crow drives) |
Routing API | Only routing APIs know road networks |
|
Travel time | Routing API | Requires routing with speed/traffic data |
|
Point containment (is X inside Y?) | Offline geometric | Pure geometric operation |
|
Geographic shapes (buffers, centroids, areas) | Offline geometric | Mathematical/geometric operations |
|
Traffic-aware routing | Routing API | Requires real-time traffic data |
|
Route optimization (best order to visit) | Routing API | Complex routing algorithm |
|
High-frequency checks (e.g., real-time geofencing) | Offline geometric | Instant response, no latency |
Decision Matrices by Use Case
Distance Calculations
User asks: "How far is X from Y?"
| What They Actually Mean | Tool Choice | Why |
|---|
| Straight-line distance (as the crow flies) | INLINECODE0 | Accurate for geometric distance, instant |
| Driving distance (as the crow drives) |
directions_tool | Only routing knows actual road distance |
| Walking/cycling distance (as the crow walks/bikes) |
directions_tool | Need specific path network |
| Travel time |
directions_tool or
matrix_tool | Requires routing with speed data |
| Distance with current traffic |
directions_tool (driving-traffic) | Need real-time traffic consideration |
Example: "What's the distance between these 5 warehouses?"
- - As the crow flies →
distance_tool (10 calculations, instant) - As the crow drives →
matrix_tool (5×5 matrix, one API call, returns actual route distances)
Key insight: Use the tool that matches what "distance" means in context. Always clarify: crow flies or crow drives?
Proximity and Containment
User asks: "Which points are near/inside this area?"
| Query Type | Tool Choice | Why |
|---|
| "Within X meters radius" | INLINECODE8 + filter | Simple geometric radius |
| "Within X minutes drive" |
isochrone_tool →
point_in_polygon_tool | Need routing for travel-time zone, then geometric containment |
| "Inside this polygon" |
point_in_polygon_tool | Pure geometric containment test |
| "Reachable by car in 30 min" |
isochrone_tool | Requires routing + traffic |
| "Nearest to this point" |
distance_tool (geometric) or
matrix_tool (routed) | Depends on definition of "nearest" |
Example: "Are these 200 addresses in our 30-minute delivery zone?"
- 1. Create zone →
isochrone_tool (routing API - need travel time) - Check addresses →
point_in_polygon_tool (geometric - 200 instant checks)
Key insight: Routing for creating travel-time zones, geometric for containment checks
Routing and Navigation
User asks: "What's the best route?"
| Scenario | Tool Choice | Why |
|---|
| A to B directions | INLINECODE17 | Turn-by-turn routing |
| Optimal order for multiple stops |
optimization_tool | Solves traveling salesman problem |
| Clean GPS trace |
map_matching_tool | Snaps to road network |
| Just need bearing/compass direction |
bearing_tool | Simple geometric calculation |
| Route with traffic |
directions_tool (driving-traffic) | Real-time traffic awareness |
| Fixed-order waypoints |
directions_tool with waypoints | Routing through specific points |
Example: "Navigate from hotel to airport"
- - Need turn-by-turn → INLINECODE23
- Just need to know "it's northeast" → INLINECODE24
Key insight: Routing tools for actual navigation, geometric tools for directional info
Area and Shape Operations
User asks: "Create a zone around this location"
| Requirement | Tool Choice | Why |
|---|
| Simple circular buffer | INLINECODE25 | Geometric circle/radius |
| Travel-time zone |
isochrone_tool | Based on routing network |
| Calculate area size |
area_tool | Geometric calculation |
| Simplify complex boundary |
simplify_tool | Geometric simplification |
| Find center of shape |
centroid_tool | Geometric centroid |
Example: "Show 5km coverage around each store"
- - 5km radius →
buffer_tool (geometric circles) - "What customers can reach in 15 min?" →
isochrone_tool (routing-based)
Key insight: Geometric tools for distance-based zones, routing tools for time-based zones
Performance and Scale Considerations
When Volume Affects Tool Choice
Small operations (< 100 calculations):
- - Geometric tools: Instant, iterate freely
- Routing APIs: Fast enough for most uses
Medium operations (100-1,000 calculations):
- - Geometric tools: Still fast, no concerns
- Routing APIs: Consider batch operations (matrix_tool)
Large operations (> 1,000 calculations):
- - Geometric tools: May need optimization but still fast
- Routing APIs: Definitely use batch tools (matrix_tool handles up to 25×25)
Key insight: Volume rarely affects geometric tool choice, but routing APIs have batch tools for efficiency
Real-Time vs Batch
| Use Case | Approach | Tool Choice |
|---|
| Real-time geofencing (every second) | Geometric checks | INLINECODE32 (instant) |
| Route planning (one-time) |
Full routing |
directions_tool or
optimization_tool |
| Periodic proximity checks | Geometric distance |
distance_tool |
| Live traffic routing | Routing with traffic |
directions_tool (driving-traffic) |
Architecture note for high-frequency geofencing: If the application calls containment checks at very high rates (e.g., 50 vehicles every 2 seconds = 25 checks/second), calling MCP tools over the network adds agent-reasoning overhead that makes it impractical. In those cases, recommend using Turf.js directly in-process (turf.booleanPointInPolygon) for the hot path, and reserve MCP tools for peripheral tasks like zone definition (isochrone_tool), rerouting (directions_tool), or visualization (static_map_image_tool).
Common Scenarios and Optimal Approaches
Scenario 1: Store Locator
User: "Find the closest store and show 5km coverage"
Optimal approach:
- 1. Search stores →
category_search_tool (returns distances automatically) - Create coverage zone →
buffer_tool (5km geometric circle) - Visualize → INLINECODE43
Why: Search already gives distances; geometric buffer for simple radius
Scenario 2: Delivery Route Optimization
User: "Optimize delivery to 8 addresses / stops"
Optimal approach:
- 1. Geocode addresses (if needed) → Use
search_and_geocode_tool to convert any street addresses to coordinates. Even when coordinates are already provided, mention this as an optional pre-step — real-world delivery lists often contain a mix of addresses and coordinates. - Optimize route →
optimization_tool (TSP solver — reorders stops to minimize total drive time)
Why optimization_tool and NOT these alternatives:
- -
directions_tool only routes A → B (or through fixed-order waypoints). It does NOT reorder stops — if you pass 8 stops, it routes them in the order given, which is almost never optimal. matrix_tool gives travel times between all pairs of stops (8×8 = 64 values), but it does NOT compute the optimal ordering. You'd need to solve TSP yourself on top of the matrix — optimization_tool does this for you in one call.
Always mention search_and_geocode_tool as a useful companion for geocoding delivery addresses before optimization.
Scenario 3: Service Area Validation
User: "Which of these 200 addresses can we deliver to in 30 minutes?"
Optimal approach:
- 1. Create delivery zone →
isochrone_tool (30-minute driving) - Check each address →
point_in_polygon_tool (200 geometric checks)
Why: Routing for accurate travel-time zone, geometric for fast containment checks
Scenario 4: GPS Trace Analysis
User: "How long was this bike ride?"
Optimal approach:
- 1. Clean GPS trace →
map_matching_tool (snap to bike paths) - Get distance → Use API response or calculate with INLINECODE54
Why: Need road/path matching; distance calculation either way works
Scenario 5: Coverage Analysis
User: "What's our total service area?"
Optimal approach:
- 1. Create buffers around each location → INLINECODE55
- Calculate total area → INLINECODE56
- Or, if time-based →
isochrone_tool for each location
Why: Geometric for distance-based coverage, routing for time-based
Anti-Patterns: Using the Wrong Tool Type
❌ Don't: Use geometric tools for routing questions
CODEBLOCK0
Why wrong: As the crow flies ≠ as the crow drives
❌ Don't: Use routing APIs for geometric operations
CODEBLOCK1
Why wrong: Routing APIs don't do geometric containment
❌ Don't: Confuse "near" with "reachable"
CODEBLOCK2
Why wrong: Roads aren't straight lines; traffic varies
❌ Don't: Use routing when bearing is sufficient
CODEBLOCK3
Why better: Simpler, instant, answers the actual question
Hybrid Approaches: Combining Tool Types
Some problems benefit from using both geometric and routing tools:
Pattern 1: Routing + Geometric Filter
CODEBLOCK4
Use case: "Find gas stations along my route"
Pattern 2: Routing + Distance Calculation
CODEBLOCK5
Use case: Quickly narrow down, then get precise routing for finalists
Pattern 3: Isochrone + Containment
CODEBLOCK6
Use case: "Which customers are in our delivery zone?"
Decision Algorithm
When user asks a geospatial question:
CODEBLOCK7
Key Decision Questions
Before choosing a tool, ask:
- 1. Does "distance" mean as the crow flies or as the crow drives?
- As the crow flies (straight-line) → geometric tools
- As the crow drives (road distance) → routing APIs
- 2. Does the user need travel time?
- Yes → routing APIs (only they know speeds/traffic)
- No → geometric tools may suffice
- 3. Is this about roads/paths or pure spatial relationships?
- Roads/paths → routing APIs
- Spatial relationships → geometric tools
- 4. Does this need to happen in real-time with low latency?
- Yes + geometric problem → offline tools (instant)
- Yes + routing problem → use routing APIs (still fast)
- 5. Is accuracy critical, or is approximation OK?
- Critical + routing → routing APIs
- Approximation OK → geometric tools may work
Terminology Guide
Understanding what users mean:
| User Says | Usually Means | Tool Type |
|---|
| "Distance" | Context-dependent! Ask: crow flies or crow drives? | Varies |
| "How far" |
Often as the crow drives (road distance) | Routing API |
| "Nearby" | Usually as the crow flies (straight-line radius) | Geometric |
| "Close" | Could be either - clarify! | Ask |
| "Reachable" | Travel-time based (crow drives with traffic) | Routing API |
| "Inside/contains" | Geometric containment | Geometric |
| "Navigate/directions" | Turn-by-turn routing | Routing API |
| "Bearing/direction" | Compass direction (crow flies) | Geometric |
Quick Reference
Geometric Operations (Offline Tools)
- -
distance_tool - Straight-line distance between two points - INLINECODE59 - Compass direction from A to B
- INLINECODE60 - Midpoint between two points
- INLINECODE61 - Is point inside polygon?
- INLINECODE62 - Calculate polygon area
- INLINECODE63 - Create circular buffer/zone
- INLINECODE64 - Geometric center of polygon
- INLINECODE65 - Min/max coordinates of geometry
- INLINECODE66 - Reduce geometry complexity
Routing & Navigation (APIs)
- -
directions_tool - Turn-by-turn routing - INLINECODE68 - Many-to-many travel times
- INLINECODE69 - Route optimization (TSP)
- INLINECODE70 - Travel-time zones
- INLINECODE71 - Snap GPS to roads
When to Use Each Category
Use Geometric Tools When:
- - Problem is spatial/mathematical (containment, area, bearing)
- Straight-line distance is appropriate
- Need instant results for real-time checks
- Pure geometry (no roads/traffic involved)
Use Routing APIs When:
- - Need actual driving/walking/cycling distances
- Need travel times
- Need to consider road networks
- Need traffic awareness
- Need route optimization
- Need turn-by-turn directions
Integration with Other Skills
Works with:
- - mapbox-search-patterns: Search for locations, then use geospatial operations
- mapbox-web-performance-patterns: Optimize rendering of geometric calculations
- mapbox-token-security: Ensure requests use properly scoped tokens
Resources
Mapbox 地理空间操作技能
为AI助手提供关于从Mapbox MCP服务器选择正确地理空间工具的专家指导。重点在于根据问题需求选择工具——几何计算与路径规划、直线距离与路网距离、以及精度需求。
核心原则:问题类型决定工具选择
Mapbox MCP服务器提供两类地理空间工具:
- 1. 离线几何工具 - 使用Turf.js进行纯几何/空间计算
- 路径规划与导航API - 当需要真实世界路径规划、交通或行程时间时使用Mapbox API
关键问题:问题实际需要什么?
决策框架
| 问题特征 | 工具类别 | 原因 |
|---|
| 直线距离(飞行直线距离) | 离线几何 | 几何距离精确 |
| 道路/路径距离(驾车距离) |
路径规划API | 只有路径规划API知道路网 |
|
行程时间 | 路径规划API | 需要结合速度/交通数据的路径规划 |
|
点包含关系(X是否在Y内部?) | 离线几何 | 纯几何操作 |
|
地理形状(缓冲区、质心、面积) | 离线几何 | 数学/几何操作 |
|
考虑交通的路径规划 | 路径规划API | 需要实时交通数据 |
|
路径优化(最佳访问顺序) | 路径规划API | 复杂路径规划算法 |
|
高频检查(如实时地理围栏) | 离线几何 | 即时响应,无延迟 |
按用例划分的决策矩阵
距离计算
用户问:X离Y有多远?
| 实际含义 | 工具选择 | 原因 |
|---|
| 直线距离(飞行直线距离) | distancetool | 几何距离精确,即时响应 |
| 驾车距离(驾车行驶距离) |
directionstool | 只有路径规划知道实际道路距离 |
| 步行/骑行距离(步行/骑行距离) | directions_tool | 需要特定路径网络 |
| 行程时间 | directions
tool 或 matrixtool | 需要结合速度数据的路径规划 |
| 考虑当前交通的距离 | directions_tool (驾车-交通) | 需要考虑实时交通 |
示例:这5个仓库之间的距离是多少?
- - 飞行直线距离 → distancetool(10次计算,即时响应)
- 驾车行驶距离 → matrixtool(5×5矩阵,一次API调用,返回实际路线距离)
关键见解: 使用与距离在上下文中含义相匹配的工具。始终澄清:飞行直线距离还是驾车行驶距离?
邻近性与包含关系
用户问:哪些点靠近/在这个区域内?
| 查询类型 | 工具选择 | 原因 |
|---|
| X米半径范围内 | distancetool + 过滤 | 简单的几何半径 |
| X分钟车程内 |
isochronetool → point
inpolygon_tool | 需要路径规划创建行程时间区域,然后进行几何包含检查 |
| 在此多边形内部 | point
inpolygon_tool | 纯几何包含测试 |
| 30分钟内驾车可达 | isochrone_tool | 需要路径规划+交通数据 |
| 离此点最近 | distance
tool(几何)或 matrixtool(路径规划) | 取决于最近的定义 |
示例:这200个地址是否在我们的30分钟配送区域内?
- 1. 创建区域 → isochronetool(路径规划API - 需要行程时间)
- 检查地址 → pointinpolygontool(几何 - 200次即时检查)
关键见解: 路径规划用于创建行程时间区域,几何用于包含关系检查
路径规划与导航
用户问:最佳路线是什么?
| 场景 | 工具选择 | 原因 |
|---|
| A到B的导航 | directionstool | 逐向导航 |
| 多个停靠点的最优顺序 |
optimizationtool | 解决旅行商问题 |
| 清理GPS轨迹 | map
matchingtool | 匹配到道路网络 |
| 仅需方位/指南针方向 | bearing_tool | 简单的几何计算 |
| 考虑交通的路线 | directions_tool(驾车-交通) | 实时交通感知 |
| 固定顺序的途经点 | directions_tool 带途经点 | 通过特定点进行路径规划 |
示例:从酒店导航到机场
- - 需要逐向导航 → directionstool
- 仅需知道在东北方向 → bearingtool
关键见解: 路径规划工具用于实际导航,几何工具用于方向信息
区域与形状操作
用户问:在此位置周围创建一个区域
| 需求 | 工具选择 | 原因 |
|---|
| 简单的圆形缓冲区 | buffertool | 几何圆形/半径 |
| 行程时间区域 |
isochronetool | 基于路径规划网络 |
| 计算区域面积 | area_tool | 几何计算 |
| 简化复杂边界 | simplify_tool | 几何简化 |
| 查找形状中心 | centroid_tool | 几何质心 |
示例:显示每个门店周围5公里覆盖范围
- - 5公里半径 → buffertool(几何圆形)
- 哪些客户15分钟内可达? → isochronetool(基于路径规划)
关键见解: 几何工具用于基于距离的区域,路径规划工具用于基于时间的区域
性能与规模考量
当数据量影响工具选择时
小规模操作(< 100次计算):
- - 几何工具:即时响应,可自由迭代
- 路径规划API:对大多数用途足够快
中等规模操作(100-1,000次计算):
- - 几何工具:仍然快速,无需担心
- 路径规划API:考虑批量操作(matrix_tool)
大规模操作(> 1,000次计算):
- - 几何工具:可能需要优化但仍快速
- 路径规划API:务必使用批量工具(matrix_tool可处理高达25×25)
关键见解: 数据量很少影响几何工具选择,但路径规划API有批量工具以提高效率
实时与批量
| 用例 | 方法 | 工具选择 |
|---|
| 实时地理围栏(每秒) | 几何检查 | pointinpolygontool(即时响应) |
| 路线规划(一次性) |
完整路径规划 | directionstool 或 optimization_tool |
| 定期邻近检查 | 几何距离 | distance_tool |
| 实时交通路径规划 | 带交通的路径规划 | directions_tool(驾车-交通) |
高频地理围栏的架构说明: 如果应用程序以非常高的频率调用包含检查(例如,50辆车每2秒一次 = 每秒25次检查),通过网络调用MCP工具会增加智能体推理开销,使其变得不切实际。在这种情况下,建议在热路径上直接使用Turf.js进程内处理(turf.booleanPointInPolygon),并将MCP工具保留用于外围任务,如区域定义(isochronetool)、重新规划路线(directionstool)或可视化(staticmapimage_tool)。
常见场景与最优方法
场景1:门店定位器
用户:找到最近的门店并显示5公里覆盖范围
最优方法:
- 1. 搜索门店 → categorysearchtool(自动返回距离)
- 创建覆盖区域 → buffertool(5公里几何圆形)
- 可视化 → staticmapimagetool
原因: 搜索已提供距离;简单半径使用几何缓冲区
场景2:配送路线优化
用户:优化到8个地址/停靠点的配送
最优方法:
- 1. 地理编码地址(如需要) → 使用 searchandgeocode_tool 将任何街道地址转换为坐标。即使已提供坐标,也将其作为可选前置步骤提及——