This project calculates the distance between two locations using the Google Distance Matrix API.
-
Install the dependencies:
uv sync
-
Configure your Google Maps API key:
Environment Variable (Recommended)
export GOOGLE_API_KEY=your_google_maps_api_key_hereOr create a .env file:
cp .env.example .env # Edit .env and replace your_google_maps_api_key_here with your actual key -
Get your Google Maps API Key:
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the "Distance Matrix API"
- Create credentials (API key)
- Copy the API key for use in step 2
# Build the Docker image
docker build -t distance-calculator .
# Run MCP Server (default)
docker run -p 8001:8001 -e GOOGLE_API_KEY=your_api_key distance-calculator
# Run REST API Server
docker run -p 8000:8000 -e GOOGLE_API_KEY=your_api_key distance-calculator uv run python scripts/run_rest_server.py
# Or use docker-compose for both services
docker-compose up# REST API Server
uv run python scripts/run_rest_server.py
# MCP Server
uv run python scripts/run_mcp_server.py# REST API Server
uv run python -m src.distance_calculator.servers.rest_server
# MCP Server
uv run python -m src.distance_calculator.servers.mcp_serverThe REST API will be available at http://127.0.0.1:8000.
Add this to your Claude Desktop configuration file:
MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"distance-calculator": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"GOOGLE_API_KEY=<YOUR_GOOGLE_MAPS_API_KEY>",
"distance-calculator"
]
}
}
}Add this to your Cursor MCP settings:
- Open Cursor Settings
- Go to "Features" → "Model Context Protocol"
- Add a new server with this configuration:
{
"distance-calculator": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"GOOGLE_API_KEY=<YOUR_GOOGLE_MAPS_API_KEY>",
"distance-calculator"
]
}
}Note: Replace <YOUR_GOOGLE_MAPS_API_KEY> with your actual Google Maps API key.
Send a POST request to /distance with a JSON payload like this:
{
"origin": {
"location": "90210"
},
"destination": {
"location": "New York, NY"
}
}# Run all tests
uv run pytest
# Run tests with coverage
uv run pytest --cov=src
# Run specific test file
uv run pytest tests/test_distance_service.py -v# Format code
uv run black src/ tests/ scripts/
# Check code style
uv run flake8 src/ tests/ scripts/
# Type checking
uv run mypy src/