googleMapsMCPServer

muddassir-lateef/googleMapsMCPServer

3.3

If you are the rightful owner of googleMapsMCPServer and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

The Google Maps MCP Server is a Model Context Protocol server that provides tools for interacting with the Google Maps API, built using FastMCP.

Tools
2
Resources
0
Prompts
0

Google Maps MCP Server

This project provides a Model Context Protocol (MCP) server that exposes tools for interacting with the Google Maps API. It's built using FastMCP and can be used as an example for creating your own MCP servers.

Features

The server exposes the following MCP features:

  • Tools:

    • geocode: Geocodes an address string and returns the latitude and longitude.
    • get_map: Returns a URL to a static map image for a given latitude and longitude.
  • Prompts:

    • get_map_for_address: A template that generates a user-friendly prompt to ask for a map of a specific address.

Project Structure

.
├── src
│   └── googlemaps_mcp_server
│       └── main.py         # The MCP server implementation
├── tests
│   └── __init__.py
├── .gitignore
├── poetry.lock
├── pyproject.toml
├── README.md
└── test_client.py          # An example client to test the server

Setup and Installation

Prerequisites

  • Python 3.10+
  • Poetry for dependency management.

Installation

Use Poetry to install the project dependencies from the `poetry.lock` file.
```bash
poetry install
```

Configuration

This server requires a Google Maps API key to function.

  1. Create a .env file: Create a file named .env in the root of the project.

    touch .env
    
  2. Add your API key: Open the .env file and add your Google Maps API key in the following format:

    GOOGLE_MAPS_API_KEY="YOUR_GOOGLE_MAPS_API_KEY"
    

    Replace "YOUR_GOOGLE_MAPS_API_KEY" with your actual key. The server loads this key from the environment.

Running the Server

To start the MCP server, run the main.py script:

poetry run python src/googlemaps_mcp_server/main.py

The server will start and listen on http://0.0.0.0:8000/mcp.

Using the Client

An example client is provided in test_client.py to demonstrate how to connect to the server and use its tools.

To run the client:

poetry run python test_client.py

The client will:

  1. Call the geocode tool.
  2. Use the result to call the get_map tool for several zoom levels.
  3. List and use the get_map_for_address prompt.

Example Output

Geocoding 'University of Passau, Germany'...
Geocode Result: {
  "latitude": 48.5677779,
  "longitude": 13.4527974
}
Getting map for lat=48.5677779, lon=13.4527974 at zoom=18...
Map Result (zoom=18): { "map_url": "https://maps.googleapis.com/maps/api/staticmap?center=48.5677779%2C13.4527974&zoom=18&size=1024x1024&maptype=hybrid&scale=2&key=..." }
...

--- Testing Prompts ---
Available Prompts: ['get_map_for_address']
Generated Prompt: You are a maps assistant that is supposed to first use geocode tool to get geo coordinates of the address. Then use get_map tool to get a url of the map snippet of the address.By default show map of hybrid type.Now Show me a map of University of Passau, Germany.
--- Prompt Test Complete ---

staticmap

Endpoints

  • /mcp/geocode?address=<address>: Geocodes an address string and returns the latitude and longitude.
  • /mcp/get_map?lat=<latitude>&lon=<longitude>&maptype=<maptype>: Returns a URL to a static map image. maptype can be one of roadmap, satellite, hybrid, terrain.