All skills
mapbox avatar

/mapbox-mcp-runtime-patterns

@7cac917 official
by mapboxmapbox/mapbox-agent-skills80 stars
17

Integration patterns for Mapbox MCP Server in AI applications and agent frameworks. Covers runtime integration with pydantic-ai, mastra, LangChain, and custom agents. Use when building AI-powered applications that need geospatial capabilities.

Use this Skill: https://skilld.dev/gh/mapbox/mapbox-agent-skills/mapbox-mcp-runtime-patterns

This session only. Nothing lands on disk.

examplesREADME.md

≈1.9k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Mapbox MCP Runtime Integration Examples

Working, compilable examples showing how to integrate Mapbox MCP Server with popular agent frameworks.

Prerequisites

  1. Mapbox Access Token: Get one at mapbox.com/account/access-tokens
  2. OpenAI API Key (or other LLM provider)
  3. HuggingFace Token (for smolagents)

Python Examples

Setup

cd python
pip install -r requirements.txt

# Set environment variables
export MAPBOX_ACCESS_TOKEN="your_token_here"
export OPENAI_API_KEY="your_openai_key"
export HF_TOKEN="your_huggingface_token"  # For smolagents

1. Pydantic AI Example

Framework: Pydantic AI - Type-safe agents with validation

python pydantic_ai_example.py

Features:

  • Type-safe tool definitions
  • Environment variable support
  • Hosted MCP server integration
  • Real-world examples (restaurant finder, route planning)

Best for: Production applications requiring type safety and validation


2. CrewAI Example

Framework: CrewAI - Multi-agent orchestration

python crewai_example.py

Features:

  • Multi-agent crews with specialized roles
  • Task dependencies and context passing
  • Location Analyst + Route Planner agents
  • Real-world examples (restaurant crew, property search)

Best for: Complex workflows requiring multiple specialized agents

Agents included:

  • Location Analyst: Finds places, analyzes areas
  • Route Planner: Calculates routes and travel times

3. Smolagents Example

Framework: Smolagents - Hugging Face's lightweight agents

python smolagents_example.py

Features:

  • Method 1: Direct MCP connection (recommended, minimal code)
  • Method 2: Custom tools with @tool decorator
  • Lightweight and fast
  • Real-world example (property search agent)

Best for: Production deployment with minimal overhead

Note: Smolagents has native MCP support via MCPClient!


TypeScript Examples

Setup

cd typescript
npm install

# Set environment variables
export MAPBOX_ACCESS_TOKEN="your_token_here"
export OPENAI_API_KEY="your_openai_key"

1. Mastra Example

Framework: Mastra 1.x - Modern TypeScript agent framework

npm run mastra

Features:

  • Type-safe tool creation with Zod schemas
  • Hosted MCP server integration
  • Multiple Mapbox tools (directions, POI search, distance, isochrone)
  • Real-world examples

Best for: TypeScript applications with strong typing

Tools included:

  • get-directions: Driving directions with traffic
  • search-poi: Find restaurants, hotels, etc.
  • calculate-distance: Offline distance calculation
  • get-isochrone: Reachable area analysis

Verify it compiles:

npm run build  # TypeScript type-check

2. LangChain Example

Framework: LangChain - Conversational AI framework

npm run langchain

Features:

  • Conversational interface
  • Tool chaining
  • Memory and context management
  • Multi-step workflows

Best for: Conversational applications with complex tool chains

Tools included:

  • Directions, POI search, distance calculation, isochrones
  • All tools use hosted Mapbox MCP server

Framework Comparison

Framework Language Best For Complexity Type Safety
Pydantic AI Python Production apps Medium ⭐⭐⭐
CrewAI Python Multi-agent systems High ⭐⭐
Smolagents Python Lightweight agents Low ⭐⭐
Mastra TypeScript Typed agents Medium ⭐⭐⭐
LangChain TypeScript Conversational AI High ⭐⭐

Common Use Cases

1. Restaurant Finder

Find restaurants near a location with distances:

  • Pydantic AI: pydantic_ai_example.py (Example 1)
  • CrewAI: crewai_example.py (Example 1)
  • LangChain: langchain-example.ts (Example 3)

2. Route Planning

Calculate driving time with traffic:

  • Pydantic AI: pydantic_ai_example.py (Example 2)
  • Mastra: mastra-example.ts (Example 2)

3. Property Search

Find properties with good commute:

  • CrewAI: crewai_example.py (Example 2)
  • Smolagents: smolagents_example.py (Example 3)

Mapbox MCP Tools Available

All examples connect to the hosted Mapbox MCP Server at https://mcp.mapbox.com/mcp.

API Tools (require Mapbox token):

  • directions_tool: Driving directions with traffic
  • category_search_tool: Find POIs by category
  • search_and_geocode_tool: Search for specific places or addresses
  • reverse_geocode_tool: Coordinates to address
  • isochrone_tool: Reachable area within time
  • matrix_tool: Travel time matrix
  • static_map_image_tool: Static map images
  • map_matching_tool: Match GPS traces to roads
  • optimization_tool: Optimize multi-stop routes

Offline Tools (free, instant):

  • distance_tool: Distance between points
  • bearing_tool: Compass direction
  • midpoint_tool: Midpoint between points
  • point_in_polygon_tool: Point containment test
  • area_tool: Polygon area
  • centroid_tool: Polygon center
  • buffer_tool: Create buffer zones
  • bbox_tool: Calculate bounding boxes
  • simplify_tool: Simplify geometries

Utility Tools:

  • version_tool: Get MCP server version
  • category_list_tool: List available POI categories

Testing Examples

Python

# Run all Python examples
cd python
python pydantic_ai_example.py
python crewai_example.py
python smolagents_example.py

TypeScript

# Type-check all TypeScript examples
cd typescript
npm run build

# Run individual examples
npm run mastra
npm run langchain

Troubleshooting

Missing MAPBOX_ACCESS_TOKEN

Error: MAPBOX_ACCESS_TOKEN is required

Solution: Export the environment variable

export MAPBOX_ACCESS_TOKEN="pk.ey..."

MCP Connection Failed

Error: MCP request failed: Unauthorized

Solution: Check your token has proper scopes at mapbox.com/account/access-tokens

Import Errors (Python)

ModuleNotFoundError: No module named 'crewai'

Solution: Install requirements

pip install -r requirements.txt

TypeScript Compilation Errors

Cannot find module '@mastra/core'

Solution: Install dependencies

npm install

Resources

Contributing

Found an issue or want to add more examples? Please open a PR!

License

These examples are provided as-is for educational purposes.

Source: SKILL.md on GitHub

1 warning17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    The skill provides legitimate integration patterns and code examples for using Mapbox geospatial tools with various AI agent frameworks. It uses standard developer practices for package management, environment configuration, and API interaction with official vendor services.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer6mo

    2/12 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 7cac917. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 9 hours ago.

Activeupdated 6 months ago
  • MCP
  • TypeScript
  • mapbox
  • geospatial
  • routing
  • geocoding
  • pydantic-ai
  • langchain
  • mastra
  • agents

README badge

README badge for mapbox/mapbox-agent-skills/mapbox-mcp-runtime-patterns

Demonstrates runtime integration patterns for the Mapbox MCP Server across pydantic-ai, mastra, LangChain, and custom agents, covering offline tools (Turf.js), API-backed geospatial features (routing, geocoding, isochrones), and production considerations. Use this when building AI applications that need to query maps, calculate distances, search POIs, or optimize routes without manual API integration.

Generated from the current SKILL.md.

What's the difference between offline tools like distance_tool and API tools like directions_tool?
Offline tools (distance, bearing, point-in-polygon) use Turf.js, return instant results, and have no API cost. API tools (directions, geocoding, isochrones) call Mapbox APIs, return real-time data like traffic-aware routing, and count against your token usage.
Can I use the hosted Mapbox MCP server or do I need to self-host?
The hosted server at https://mcp.mapbox.com/mcp is recommended for production — no server management, always up-to-date, and lower latency. Self-hosting via npm is available for custom deployments or development.
Which frameworks does this skill cover?
Integration patterns for Pydantic AI, Mastra, LangChain, CrewAI, Smolagents, and custom agent architectures. Real-estate, food-delivery, and travel-planning use cases are included.
When should I use category_search_tool vs search_and_geocode_tool?
Use category_search_tool to browse by type (e.g. 'find coffee shops nearby'). Use search_and_geocode_tool for specific places or street addresses (e.g. '123 Main Street').
Does this skill include production guidance like caching, rate limiting, and error handling?
Yes. The skill references a production-patterns file covering caching, batch operations, tool descriptions, error handling, security, rate limiting, and testing.

Generated from the current SKILL.md. These answers refresh after source changes.