Smolagent Integration
Smolagents Integration Guide
This guide explains how to configure smolagents to the TomTom MCP Server for location-based queries. Keep in mind the size of the models you're using for inference before running this locally.
Prerequisites
- Node.js 22+ (For STDIO)
- Docker Setup Required (For HTTP)
- Python 3.10+
- A valid TomTom API key
- Smolagents installed (
pip install smolagents[toolkit]) - Hugging Face User Access Token available
Setup: Option 1 - Using Stdio Mode
-
Personalize the configuration from line 36 to line 41 in smolagents_example.py:
1# Run server with node2server_parameters = StdioServerParameters(3 command="npx",4 args=["-y", "@tomtom-org/tomtom-mcp@latest"],5 env={6 "TOMTOM_API_KEY": "<your_API_KEY>"}, # replace with your TomTom API key7) -
Run
python3 smolagents_example.py
Setup: Option 2 - Using HTTP Mode (Recommended)
This approach allows you to run the TomTom 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 MCP in HTTP mode using Docker:
1# Run using Docker in the background2docker run -d -p 3000:3000 ghcr.io/tomtom-international/tomtom-mcp:latest34# Or with Docker Compose (after cloning the repository)5docker compose up -d -
Create a Python script to connect to the HTTP server:
1from smolagents import ToolCollection23# Connect to the MCP server running on localhost:30004with ToolCollection.from_mcp(5 {"url": "http://localhost:3000/mcp",6 "headers": {"tomtom-api-key": "your_api_key_here"},7 "transport": "streamable-http"},8 trust_remote_code=True9) as collection:10 # List all available tools11 for tool in collection.tools:12 print(tool.name)1314 # Use the tools in your agent15 # Example: Use geocoding16 # result = collection.tools_dict["tomtom-geocode"].call({"query": "Amsterdam Central Station"})17 # print(result) -
Run your Python script.
If configured correctly, the MCP server will fetch results from TomTom APIs.
Troubleshooting
- 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)