This guide explains how to configure smolagents to the TomTom Maps MCP Server for location-based queries. Keep in mind the size of the models you're using for inference before running this locally.
- Node.js 22+
- Python 3.10+
- A valid TomTom API key
- Smolagents installed (
pip install smolagents[toolkit]) - Hugging Face User Access Token available
-
Personalize the configuration from line 36 to line 41 in smolagents_example.py:
# Run server with node server_parameters = StdioServerParameters( command="npx", args=["-y", "@tomtom-org/tomtom-mcp@latest"], env={ "TOMTOM_API_KEY": "<your_API_KEY>"}, # replace with your TomTom API key )
-
Run
python3 smolagents_example.py
This approach allows you to run the TomTom Maps MCP server independently from your smolagents code, offering better stability and flexibility.
-
Install the required package for HTTP mode:
pip install 'smolagents[mcp]' -
Run TomTom Maps MCP in HTTP mode using Docker:
# Run using Docker in the background docker run -d -p 3000:3000 ghcr.io/tomtom-international/tomtom-maps-mcp:latest # Or with Docker Compose (after cloning the repository) docker compose up -d
-
Create a Python script to connect to the HTTP server:
from smolagents import ToolCollection # Connect to the MCP server running on localhost:3000 with ToolCollection.from_mcp( {"url": "http://localhost:3000/mcp", "headers": {"tomtom-api-key": "<your_API_KEY>"}, "transport": "streamable-http"}, trust_remote_code=True ) as collection: # List all available tools for tool in collection.tools: print(tool.name) # Use the tools in your agent # Example: Use geocoding # result = collection.tools_dict["tomtom-geocode"].call({"query": "Amsterdam Central Station"}) # print(result)
-
Run your Python script.
If configured correctly, the MCP server will fetch results from TomTom APIs.
- Ensure
TOMTOM_API_KEYis valid and active - Check that the MCP server is accessible locally
- When using HTTP mode, verify your connection URL and port are correct
- When using Docker, make sure the container is running with
docker ps - Ensure that you have access to the smolagents (most models require their own key or a huggingface CLI login)