Mapbox MCP Runtime Patterns
This skill provides patterns for integrating the Mapbox MCP Server into AI applications for production use with geospatial capabilities.
What is Mapbox MCP Server?
The Mapbox MCP Server is a Model Context Protocol (MCP) server that provides AI agents with geospatial tools:
Offline Tools (Turf.js):
- - Distance, bearing, midpoint calculations
- Point-in-polygon tests
- Area, buffer, centroid operations
- Bounding box, geometry simplification
- No API calls, instant results
Mapbox API Tools:
- - Directions and routing
- Reverse geocoding
- POI category search
- Isochrones (reachability)
- Travel time matrices
- Static map images
- GPS trace map matching
- Multi-stop route optimization
Utility Tools:
- - Server version info
- POI category list
Key benefit: Give your AI application geospatial superpowers without manually integrating multiple APIs.
Understanding Tool Categories
Before integrating, understand the key distinctions between tools to help your LLM choose correctly:
Distance: "As the Crow Flies" vs "Along Roads"
Straight-line distance (offline, instant):
- - Tools:
distance_tool, bearing_tool, INLINECODE2 - Use for: Proximity checks, "how far away is X?", comparing distances
- Example: "Is this restaurant within 2 miles?" → INLINECODE3
Route distance (API, traffic-aware):
- - Tools:
directions_tool, INLINECODE5 - Use for: Navigation, drive time, "how long to drive?"
- Example: "How long to drive there?" → INLINECODE6
Search: Type vs Specific Place
Category/type search:
- - Tool: INLINECODE7
- Use for: "Find coffee shops", "restaurants nearby", browsing by type
- Example: "What hotels are near me?" → INLINECODE8
Specific place/address:
- - Tool:
search_and_geocode_tool, INLINECODE10 - Use for: Named places, street addresses, landmarks
- Example: "Find 123 Main Street" → INLINECODE11
Travel Time: Area vs Route
Reachable area (what's within reach):
- - Tool: INLINECODE12
- Returns: GeoJSON polygon of everywhere reachable
- Example: "What can I reach in 15 minutes?" → INLINECODE13
Specific route (how to get there):
- - Tool: INLINECODE14
- Returns: Turn-by-turn directions to one destination
- Example: "How do I get to the airport?" → INLINECODE15
Cost & Performance
Offline tools (free, instant):
- - No API calls, no token usage
- Use whenever real-time data not needed
- Examples:
distance_tool, point_in_polygon_tool, INLINECODE18
API tools (requires token, counts against usage):
- - Real-time traffic, live POI data, current conditions
- Use when accuracy and freshness matter
- Examples:
directions_tool, category_search_tool, INLINECODE21
Best practice: Prefer offline tools when possible, use API tools when you need real-time data or routing.
Installation & Setup
Option 1: Hosted Server (Recommended)
Easiest integration - Use Mapbox's hosted MCP server at:
CODEBLOCK0
No installation required. Simply pass your Mapbox access token in the Authorization header.
Benefits:
- - No server management
- Always up-to-date
- Production-ready
- Lower latency (Mapbox infrastructure)
Authentication:
Use token-based authentication (standard for programmatic access):
CODEBLOCK1
Note: The hosted server also supports OAuth, but that's primarily for interactive flows (coding assistants, not production apps).
Option 2: Self-Hosted
For custom deployments or development:
CODEBLOCK2
Or use directly via npx:
CODEBLOCK3
Environment setup:
CODEBLOCK4
Reference Files
Detailed integration patterns and production guidance are organized into reference files. Load the ones relevant to your task.
- - Pydantic AI -- Type-safe Python agents
Load: INLINECODE23
- - CrewAI -- Multi-agent orchestration
Load: INLINECODE24
- - Smolagents -- Lightweight HuggingFace agents
Load: INLINECODE25
- - Mastra -- Multi-agent TypeScript systems
Load: INLINECODE26
- - LangChain -- Conversational AI with tool chaining
Load: INLINECODE27
- - Custom Agent -- Zillow/TripAdvisor/DoorDash-style patterns, architecture diagrams, hybrid approach
Load: INLINECODE28
- - Use Cases -- Real Estate, Food Delivery, Travel Planning examples
Load: INLINECODE29
- - Production Patterns -- Caching, batch operations, tool descriptions, error handling, security, rate limiting, testing
Load: INLINECODE30
Resources
When to Use This Skill
Invoke this skill when:
- - Integrating Mapbox MCP Server into AI applications
- Building AI agents with geospatial capabilities
- Architecting Zillow/TripAdvisor/DoorDash-style apps with AI
- Choosing between MCP, direct APIs, or SDKs
- Optimizing geospatial operations in production
- Implementing error handling for geospatial AI features
- Testing AI applications with geospatial tools
Mapbox MCP 运行时模式
本技能提供将 Mapbox MCP 服务器集成到具有地理空间能力的 AI 应用程序中用于生产环境的模式。
什么是 Mapbox MCP 服务器?
Mapbox MCP 服务器 是一个模型上下文协议(MCP)服务器,为 AI 代理提供地理空间工具:
离线工具(Turf.js):
- - 距离、方位角、中点计算
- 点在多边形内测试
- 面积、缓冲区、质心操作
- 边界框、几何简化
- 无需 API 调用,即时结果
Mapbox API 工具:
- - 导航和路线规划
- 反向地理编码
- POI 类别搜索
- 等时线(可达范围)
- 出行时间矩阵
- 静态地图图像
- GPS 轨迹地图匹配
- 多站点路线优化
实用工具:
主要优势: 无需手动集成多个 API,即可为您的 AI 应用程序赋予地理空间超能力。
理解工具类别
在集成之前,了解工具之间的关键区别,以帮助您的 LLM 正确选择:
距离:直线距离 vs 沿路距离
直线距离(离线,即时):
- - 工具:distancetool、bearingtool、midpointtool
- 用于:邻近检查、X 有多远?、距离比较
- 示例:这家餐厅在 2 英里范围内吗? → distancetool
路线距离(API,考虑交通):
- - 工具:directionstool、matrixtool
- 用于:导航、驾驶时间、开车需要多久?
- 示例:开车到那里需要多久? → directions_tool
搜索:类型 vs 特定地点
类别/类型搜索:
- - 工具:categorysearchtool
- 用于:找咖啡店、附近的餐厅、按类型浏览
- 示例:我附近有什么酒店? → categorysearchtool
特定地点/地址:
- - 工具:searchandgeocodetool、reversegeocodetool
- 用于:命名地点、街道地址、地标
- 示例:查找 123 Main Street → searchandgeocodetool
出行时间:区域 vs 路线
可达区域(可到达的范围):
- - 工具:isochronetool
- 返回:所有可达区域的 GeoJSON 多边形
- 示例:15 分钟内我能到达哪里? → isochronetool
特定路线(如何到达):
- - 工具:directionstool
- 返回:到达一个目的地的逐向导航
- 示例:我如何到达机场? → directionstool
成本与性能
离线工具(免费,即时):
- - 无需 API 调用,无令牌消耗
- 在不需要实时数据时使用
- 示例:distancetool、pointinpolygontool、area_tool
API 工具(需要令牌,计入使用量):
- - 实时交通、实时 POI 数据、当前状况
- 在需要准确性和新鲜度时使用
- 示例:directionstool、categorysearchtool、isochronetool
最佳实践: 尽可能优先使用离线工具,在需要实时数据或路线规划时使用 API 工具。
安装与设置
选项 1:托管服务器(推荐)
最简单的集成 - 使用 Mapbox 托管的 MCP 服务器,地址为:
https://mcp.mapbox.com/mcp
无需安装。只需在 Authorization 标头中传递您的 Mapbox 访问令牌。
优势:
- - 无需服务器管理
- 始终最新
- 生产就绪
- 更低延迟(Mapbox 基础设施)
认证:
使用基于令牌的认证(程序化访问的标准方式):
Authorization: Bearer yourmapboxtoken
注意: 托管服务器也支持 OAuth,但这主要用于交互式流程(编码助手,而非生产应用程序)。
选项 2:自托管
用于自定义部署或开发:
bash
npm install @mapbox/mcp-server
或直接通过 npx 使用:
bash
npx @mapbox/mcp-server
环境设置:
bash
export MAPBOXACCESSTOKEN=yourtokenhere
参考文件
详细的集成模式和生产指南已整理到参考文件中。加载与您的任务相关的文件。
- - Pydantic AI -- 类型安全的 Python 代理
加载:references/pydantic-ai.md
加载:references/crewai.md
- - Smolagents -- 轻量级 HuggingFace 代理
加载:references/smolagents.md
- - Mastra -- 多代理 TypeScript 系统
加载:references/mastra.md
- - LangChain -- 带工具链的对话式 AI
加载:references/langchain.md
- - 自定义代理 -- Zillow/TripAdvisor/DoorDash 风格模式、架构图、混合方法
加载:references/custom-agent.md
加载:references/use-cases.md
- - 生产模式 -- 缓存、批量操作、工具描述、错误处理、安全、速率限制、测试
加载:references/production.md
资源
何时使用本技能
在以下情况下调用本技能:
- - 将 Mapbox MCP 服务器集成到 AI 应用程序中
- 构建具有地理空间能力的 AI 代理
- 使用 AI 架构 Zillow/TripAdvisor/DoorDash 风格的应用程序
- 在 MCP、直接 API 或 SDK 之间进行选择
- 优化生产环境中的地理空间操作
- 实现地理空间 AI 功能的错误处理
- 使用地理空间工具测试 AI 应用程序