OpenStreetMap MCP server

Provides direct access to OpenStreetMap geospatial data through SQL queries, enabling location-based analysis and extraction of structured information about geographic features from the complete OSM dataset.
Back to servers
Setup instructions
Provider
John Wiseman
Release date
Mar 12, 2025
Language
Python
Stats
26 stars

This MCP-OSM server integrates OpenStreetMap with MCP, enabling you to query and visualize map data through a user-friendly interface. The package provides a web-based map viewer and offers various tools for interacting with map data through the MCP protocol.

Installation and Setup

Prerequisites

Before using MCP-OSM, you need to have:

  • A PostgreSQL database with PostGIS extension for OpenStreetMap data
  • Python with uv package manager installed

Configuration

To configure the MCP-OSM server, you can use environment variables in an .env file:

FLASK_HOST=127.0.0.1
FLASK_PORT=8889
PGHOST=localhost
PGPORT=5432
PGDB=osm
PGUSER=postgres
PGPASSWORD=postgres

Setting Up in Claude Desktop

To use MCP-OSM with Claude Desktop, add it to your claude_desktop_config.json:

{
  "mcpServers": {
    "OSM PostgreSQL Server": {
      "command": "/Users/yourusername/.local/bin/uv",
      "args": [
        "run",
        "--env-file",
        ".env",
        "--with",
        "mcp[cli]",
        "--with",
        "psycopg2",
        "--with-editable",
        "/path/to/mcp-osm",
        "--directory",
        "/path/to/mcp-osm",
        "mcp",
        "run",
        "mcp.py"
      ]
    }
  }
}

Make sure to replace the paths with your actual installation paths.

Using MCP-OSM

When you start the MCP server, it automatically launches a web server at http://localhost:8889/ with the map interface.

Available MCP Tools

Viewing and Setting Map Data

  • Get the current map view:

    get_map_view
    
  • Set the map view:

    set_map_view(center=[lat, lng], zoom=12)
    

    or

    set_map_view(bounds=[[lat1, lng1], [lat2, lng2]])
    
  • Set a map title:

    set_map_title("My Custom Map")
    

Adding Map Elements

  • Add a marker:

    add_map_marker([lat, lng], popup="Label text")
    
  • Add a line:

    add_map_line([[lat1, lng1], [lat2, lng2], ...], color="red")
    
  • Add a polygon:

    add_map_polygon([[lat1, lng1], [lat2, lng2], [lat3, lng3], ...], color="blue", fillColor="lightblue")
    

Querying OpenStreetMap Data

  • Execute SQL queries against OpenStreetMap database:
    query_osm_postgres("SELECT name, ST_AsText(way) FROM planet_osm_point WHERE amenity='restaurant' LIMIT 10")
    

Example Usage Workflow

  1. Start the MCP server
  2. Open the web interface at http://localhost:8889/
  3. Set the initial view of the map:
    set_map_view(center=[37.7749, -122.4194], zoom=13)
    
  4. Add markers for points of interest:
    add_map_marker([37.7749, -122.4194], popup="San Francisco")
    
  5. Query for nearby restaurants:
    results = query_osm_postgres("SELECT name, ST_AsText(way) FROM planet_osm_point WHERE amenity='restaurant' AND ST_DWithin(way, ST_SetSRID(ST_MakePoint(-122.4194, 37.7749), 3857), 1000)")
    
  6. Add the results to the map:
    for result in results:
        # Process coordinates from result
        add_map_marker([lat, lng], popup=result["name"])
    

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "OSM-PostgreSQL-Server" '{"command":"/Users/wiseman/.local/bin/uv","args":["run","--env-file",".env","--with","mcp[cli]","--with","psycopg2","--with-editable","/Users/wiseman/src/mcp-osm","--directory","/Users/wiseman/src/mcp-osm","mcp","run","mcp.py"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "OSM PostgreSQL Server": {
            "command": "/Users/wiseman/.local/bin/uv",
            "args": [
                "run",
                "--env-file",
                ".env",
                "--with",
                "mcp[cli]",
                "--with",
                "psycopg2",
                "--with-editable",
                "/Users/wiseman/src/mcp-osm",
                "--directory",
                "/Users/wiseman/src/mcp-osm",
                "mcp",
                "run",
                "mcp.py"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "OSM PostgreSQL Server": {
            "command": "/Users/wiseman/.local/bin/uv",
            "args": [
                "run",
                "--env-file",
                ".env",
                "--with",
                "mcp[cli]",
                "--with",
                "psycopg2",
                "--with-editable",
                "/Users/wiseman/src/mcp-osm",
                "--directory",
                "/Users/wiseman/src/mcp-osm",
                "mcp",
                "run",
                "mcp.py"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later