octahaidra/google-maps-MCP
If you are the rightful owner of google-maps-MCP and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A Model Context Protocol (MCP) server implementation for Google Maps APIs, providing geocoding, place search, directions, and other mapping functionalities.
Google Maps MCP Server
A Model Context Protocol (MCP) server implementation for Google Maps APIs, providing geocoding, place search, directions, and other mapping functionalities.
Prerequisites
- Node.js 18 or higher
- Docker (for containerized deployment)
- Google Maps API key with the following APIs enabled:
- Geocoding API
- Places API
- Distance Matrix API
- Elevation API
- Directions API
Environment Setup
- Create a
.env
file in the project root:
GOOGLE_MAPS_API_KEY=your_api_key_here
- Install dependencies:
npm install
Development
Running the Server Locally
- Build the TypeScript files:
npm run build
- Start the server:
node dist/server.js
Testing
Running Tests Locally
- Make sure the server is built:
npm run build
- Run the test script:
node test-server.js
The test script will:
- Start the server
- Run test cases for geocoding, reverse geocoding, and place search
- Verify responses
- Clean up by stopping the server
Running Tests with Docker
- Make the test script executable:
chmod +x test-docker.sh
- Run the Docker test script:
./test-docker.sh
This will:
- Build the Docker image
- Start a container with your server
- Run the test script inside the container
- Clean up by stopping and removing the container
Docker Deployment
Building the Docker Image
docker build -t mcp-google-maps-server .
Running the Docker Container
docker run -d --env-file .env mcp-google-maps-server
API Endpoints
The server provides the following MCP endpoints:
Geocoding
- Endpoint:
/trpc/geocode
- Method: POST
- Request Body:
{ "address": "1600 Amphitheatre Parkway, Mountain View, CA" }
Reverse Geocoding
- Endpoint:
/trpc/reverse_geocode
- Method: POST
- Request Body:
{ "location": { "latitude": 49.26046, "longitude": 11.04339 } }
Place Search
- Endpoint:
/trpc/searchPlaces
- Method: POST
- Request Body:
{ "query": "restaurants in Nürnberg", "location": { "latitude": 49.26046, "longitude": 11.04339 } }
Place Details
- Endpoint:
/trpc/placeDetails
- Method: POST
- Request Body:
{ "place_id": "ChIJN1t_tDeuEmsRUsoyG83frY4" }
Distance Matrix
- Endpoint:
/trpc/distanceMatrix
- Method: POST
- Request Body:
{ "origins": ["New York, NY"], "destinations": ["Boston, MA"], "mode": "driving" }
Elevation
- Endpoint:
/trpc/elevation
- Method: POST
- Request Body:
{ "locations": [ { "latitude": 49.26046, "longitude": 11.04339 } ] }
Directions
- Endpoint:
/trpc/directions
- Method: POST
- Request Body:
{ "origin": "New York, NY", "destination": "Boston, MA", "mode": "driving" }
Error Handling
The server includes comprehensive error handling for:
- Invalid API keys
- API request failures
- Invalid input parameters
- Network issues
Troubleshooting
Docker Build Issues
If you encounter issues during the Docker build:
- Make sure you have the latest version of Docker installed
- Try clearing Docker's build cache:
docker builder prune
- If npm install fails in the container:
- Check your package.json for any dependency issues
- Try running
npm install --legacy-peer-deps
locally first - Make sure all dependencies are compatible with Node.js 18
Container Issues
If the container fails to start:
- Check the container logs:
docker logs <container_id>
-
Verify your .env file:
- Make sure it exists
- Check that GOOGLE_MAPS_API_KEY is set correctly
- Ensure there are no extra spaces or quotes
-
Test the container interactively:
docker run -it --env-file .env mcp-google-maps-server /bin/sh
Test Failures
If tests are failing:
- Check the test output for specific error messages
- Verify that your Google Maps API key has all required APIs enabled
- Try running the tests locally first:
npm run build
node test-server.js
- Check the server logs for any API-related errors
Contributing
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.