How to Use the Mapbox MCP in Pydantic AI
Build correct, type-safe location agents with Pydantic AI and Mapbox. Get validated routes, geocoded addresses, and reliable map data.
Works with every AI agent you already use
…and any MCP-compatible client
Connect Mapbox MCP to Pydantic AI
Create your Vinkius account to connect Mapbox to Pydantic AI and route execution through our secure gateway. The platform manages server hosting, runtime updates, and security layers. Configuration requires no manual server provisioning.
Prevent Bad Location Data
Pydantic AI validates every response from the Mapbox server against a Pydantic model. If the `geocode` tool returns a malformed address or `get_elevation` returns a non-numeric value, your agent raises a `ValidationError` on the spot. This means no silent data corruption. Your application won't get a `None` where it expects coordinates or a string where it expects a float. You build with confidence, knowing the location data your agent uses is always correct and properly structured.
Work with Any LLM, Get Consistent Results
Pydantic AI is model-agnostic, so you can use OpenAI, Anthropic, Gemini, or a local model to run your agent. The code for calling the Mapbox tools doesn't change. Your agent's capabilities are decoupled from the brain powering it. Using the `MCPToolset` standardizes how your agent calls the `get_directions` or `search_nearby` tools. This lets you swap the underlying LLM to find the best balance of cost and performance, all without rewriting your tool-handling logic.
Define Your Own Data Structures
While the MCP Server provides a default output structure, Pydantic AI lets you define your own models for the results. You can create a custom `Route` model that only includes the `distance` and `duration` fields from the `get_directions` tool's output. The framework automatically parses the full response and populates your specific object. This keeps your business logic clean and separated from the raw API response of tools like `get_distance_matrix` or `get_isochrone`.
Set up Mapbox MCP in Pydantic AI
Prerequisites
- Python 3.10+ installed
-
pydantic-ai-slim[fastmcp]package - Active Vinkius subscription with a valid endpoint token
- 1
Install Pydantic AI with FastMCP
Run
pip install "pydantic-ai-slim[fastmcp]". The FastMCP toolset replaces the deprecatedMCPServerHTTPclass with full protocol support. - 2
Configure the FastMCPToolset
Pass a JSON-style config dict to
FastMCPToolsetwith your Vinkius URL. Replace[YOUR_TOKEN_HERE]with your token from cloud.vinkius.com. Supports Streamable HTTP, SSE, and Stdio transports. - 3
Create and run your agent
Pass the toolset to
Agent(toolsets=[toolset])and callagent.run(). Swapopenai:gpt-4ofor any supported model — Anthropic, Google, Mistral, or Groq.
from pydantic_ai import Agent
from pydantic_ai.toolsets.fastmcp import FastMCPToolset
toolset = FastMCPToolset({
"mcpServers": {
"mapbox-mcp": {
"url": "https://edge.vinkius.com/[YOUR_TOKEN_HERE]/mcp"
}
}
})
agent = Agent(
"openai:gpt-4o",
toolsets=[toolset],
system_prompt="You have access to Mapbox tools.",
)
result = await agent.run("List recent Mapbox transactions")
print(result.output) Independent Platform Disclaimer: Vinkius is an independent platform and is not affiliated with, endorsed by, sponsored by, verified by, or otherwise authorized by Mapbox. All third-party trademarks, logos, and brand names are the property of their respective owners. Their use on this website is strictly for informational purposes to identify service compatibility and interoperability.
Why Choose Vinkius
Vinkius connects your tools to AI with real-time monitoring and automatic cost savings — all from one dashboard.
Real-time monitoring
Live
visibility into every interaction
Connect your favorite tools to your AI and see exactly what's happening — every request, every response, in real time.
Built-in savings
60%
lower AI costs
Vinkius compresses data between your apps and your AI automatically. Lower bills every month — no configuration required.
Single dashboard
One
place for every integration
Every tool your AI connects to, managed from a single screen. One account, complete control.
Common questions about Mapbox MCP in Pydantic AI
Use it with your favorite AI tools
Connect this server to Cursor, Claude, VS Code, and more.
Start using the Mapbox MCP today
We host it, we monitor it, we maintain it. You just paste one token.