@cyanheads/openstreetmap-mcp-server
by cyanheads
README.md
<div align="center">
<h1>@cyanheads/openstreetmap-mcp-server</h1>
<p><b>Geocode, reverse geocode, and run Overpass spatial queries on OpenStreetMap data via MCP. STDIO or Streamable HTTP.</b>
<div>6 Tools</div>
</p>
</div>
<div align="center">
[](./CHANGELOG.md) [](./LICENSE) [](https://github.com/users/cyanheads/packages/container/package/openstreetmap-mcp-server) [](https://modelcontextprotocol.io/) [](https://www.npmjs.com/package/@cyanheads/openstreetmap-mcp-server) [](https://www.typescriptlang.org/) [](https://bun.sh/)
</div>
<div align="center">
[](https://github.com/cyanheads/openstreetmap-mcp-server/releases/latest/download/openstreetmap-mcp-server.mcpb) [](https://cursor.com/en/install-mcp?name=openstreetmap-mcp-server&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBjeWFuaGVhZHMvb3BlbnN0cmVldG1hcC1tY3Atc2VydmVyIl19) [](https://vscode.dev/redirect?url=vscode:mcp/install?%7B%22name%22%3A%22openstreetmap-mcp-server%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40cyanheads%2Fopenstreetmap-mcp-server%22%5D%7D)
[](https://www.npmjs.com/package/@cyanheads/mcp-ts-core)
</div>
<div align="center">
**Public Hosted Server:** [https://openstreetmap.caseyjhand.com/mcp](https://openstreetmap.caseyjhand.com/mcp)
</div>
---
## Overview
OpenStreetMap data through Nominatim and the Overpass API. Geocode places and addresses, resolve coordinates to the nearest address, look up known OSM objects, and query features by tag around a point, inside a bounding box, or inside an OSM boundary.
### Tools
| Tool | Description |
|:---|:---|
| `openstreetmap_search_places` | Convert a place name or address to coordinates and structured place data |
| `openstreetmap_reverse_geocode` | Convert latitude/longitude to the nearest address or place name |
| `openstreetmap_lookup_objects` | Fetch address records for known OSM objects by ID |
| `openstreetmap_query_nearby` | Find OSM features within a radius of a point |
| `openstreetmap_query_bbox` | Find OSM features inside a bounding box or an OSM boundary such as a city, park, or region |
| `openstreetmap_query_raw` | Run a raw Overpass QL query for anything the other tools cannot express |
## Capability reference
The [`openstreetmap-guide`](./skills/openstreetmap-guide/SKILL.md) skill covers place resolution, spatial queries, paging, and interpreting coverage and tag results.
Argument aliases are accepted before canonical validation: `latitude` / `longitude` for `lat` / `lon` on nearby and reverse queries, `radius_m` for nearby's `radius_meters`, and `q` for search's `query`. Send either spelling, never both. `radius`, `tag`, and `tags` remain invalid; advertised schemas use canonical names.
### `openstreetmap_search_places` <sub>tool</sub>
- Free-form `query` or the structured fields `street`, `city`, `county`, `state`, `country`, `postalcode`, never both; up to 40 results (`limit`, default 5; a larger `limit` is served as 40 with a `limitNotice`), narrowed by `countrycodes`, `layer`, `featureType`, and a `viewbox` (restricting with `bounded: true`)
- `language` (here and on the reverse and lookup tools) is one language tag or a comma-separated, optionally weighted list (`en`, `zh-Hant`, `fr,en;q=0.8`), sent to Nominatim with an `_` script and region, the POSIX and ICU spelling, as `-` (`en_US` as `en-US`, `zh_Hant_TW` as `zh-Hant-TW`), its primary subtag and script in the casing OSM name keys use (`EN` as `en`, `sr-latn` as `sr-Latn`) and the rest of each tag as written, cut before its first subtag carrying a digit (`es-419` as `es`); anything else, such as the name `English` or a locale with an encoding or modifier (`en_US.UTF-8`, `sr_RS@latin`), is rejected rather than answered in the local language
- Results carry coordinates, structured `address`, `addresstype`, `boundingbox`, `importance`, and `osm_type` + `osm_id`; `addresstype` is Nominatim's address label, the level of an administrative boundary (`state`, `county`, `city`), so a state, its counties, and a same-name city tell apart; `extratags` adds contact and physical-attribute tags; an empty first page fails as `no_results`, naming any `countrycodes`, `layer`, `featureType`, or bounded `viewbox` that was sent
- Every page with results returns `nextExcludeIds` to pass back as `exclude_place_ids`, since a page shorter than `limit` can still have more; once results run out you get zero results and a notice, not an error, and a walk too long for the instance's URL limit fails as `request_too_long`
---
### `openstreetmap_reverse_geocode` <sub>tool</sub>
- `lat` / `lon` plus `zoom` from 3 (country) to 18 (building, the default); `layer` defaults to `address,poi`
- Returns the nearest indexed object with structured `address`, `addresstype`, `osm_type` + `osm_id`, and `boundingbox`; a point with no result at the zoom and layers sent fails as `no_coverage`, whose hint names zoom 18 (a lower zoom never finds a result where a higher one found none) and, when `layer` leaves it out, the `address` layer
---
### `openstreetmap_lookup_objects` <sub>tool</sub>
- Up to 500 `osm_ids` entries, each one OSM ref: `N`, `W`, or `R` plus the id (`["N240109189"]`, either case), the path `node/240109189`, or its openstreetmap.org URL; an entry in any other form, or an id above 9223372036854775807, fails the call as `invalid_id_format`
- The first 50 unique IDs are looked up; the rest come back as `deferred_ids` for the next call
- Returns address records, with `addresstype`, for the objects found and lists the rest under `not_found`, each in canonical form such as `N240109189` (including objects Nominatim does not index, such as street lamps); a `notice` carries an `openstreetmap_query_raw` query to check which exist
---
### `openstreetmap_query_nearby` <sub>tool</sub>
- `lat` / `lon` with `radius_meters` up to 50,000 (default 1,000); one primary tag, `amenity` or `tag_key` with an optional `tag_value`, plus up to five ANDed `filters`; up to 500 features per page (a larger `limit` is served as 500 with a `limitNotice`)
- `element_types` searches nodes, ways, and relations unless set; `["node", "way"]` leaves relations out
- A value matches exactly by default; `list_item` mode (`tag_value_match`, or `match` on a filter) matches one item of a semicolon list, so `cuisine` = `pizza` also finds `cuisine=pizza;italian`
- An `amenity` value that OpenStreetMap tags under another key (`amenity: "museum"`; museums are `tourism=museum`) gets a `notice` naming the key to retry with. A primary feature key or value sent capitalized or spaced (`amenity: "Fast Food"`) gets a `notice` naming the lowercase, underscored spelling (`amenity=fast_food`), since tags match exactly. An exact `name` (or `name:*`) value that matched nothing gets a `notice` carrying an `openstreetmap_search_places` call and an `openstreetmap_query_raw` query that search by name (the raw query alone when the radius crosses the antimeridian; the search call alone when the radius's bounding box covers one square degree or more, as a 50 km radius does above latitude 36° and a radius past about 300 m does at a pole; no name search when a box that crosses the antimeridian has a side that large)
- Features carry `osm_type` + `osm_id`, coordinates, `distance_meters` (to the feature's nearest point), and the full tag set unless `tag_keys` cuts it, sorted nearest-first; `effectiveTag` echoes the filter chain
- `tag_keys` (up to 50) cuts each feature's `tags` to the keys listed, matched exactly and returned in the order listed, and `effectiveTagKeys` echoes them; matching, `distance_meters`, and paging still read every tag, and a key a feature lacks is absent from its `tags`. Listing `admin_level` and `wikidata` shrinks a page of boundary relations, which can carry hundreds of tags each
- With ways or relations searched, an area containing the point, such as the park or city it lies in, matches at `distance_meters` 0 whatever the radius, and `areasTimestamp` says how old the area data is. An endpoint that cannot run the area lookup is asked again without it, and the `notice` says areas containing the point were not checked
---
### `openstreetmap_query_bbox` <sub>tool</sub>
- One scope per call: the corners `south`, `west`, `north`, `east`, or `within` and one way or relation ref: `R`/`W` plus the id (`R237385`, either case), `relation/237385`, or its openstreetmap.org URL, built from a geocoding result's `osm_type` + `osm_id`; a node is never an area, so a node ref in any form is rejected; the same tag filters, list-item matching, `tag_keys`, retry notices (stray `amenity`, capitalized or spaced keys and values, an exact name that matched nothing; for a box crossing the antimeridian, or for a zero-width or zero-height box the name search is the raw query alone, for a box of one square degree or more, height times width in degrees, it is the search call alone, and a box crossing the antimeridian with a side that large gets none; under `within` the raw query prints only while the boundary's bounds cover at most 12 Overpass index blocks, a larger boundary gets the search call alone over its bounds rounded outward to 4 decimals, and a larger boundary whose bounds cross the antimeridian gets none; that viewbox is the boundary's bounding box, not its outline, so the search can return matches just outside the boundary), and 500-per-page cap as `openstreetmap_query_nearby`
- `element_types` searches nodes, ways, and relations unless set; `["node", "way"]` leaves relations out
- Features arrive nodes, then ways, then relations, each by ascending OSM id, which is not a ranking. `sort_by: { key, order }` (`order` `desc` by default, or `asc`) ranks the whole match set by a tag's numeric value before `offset` and `limit` cut the page, so `natural=peak` with `sort_by: { key: "ele" }` returns the highest peaks first. Only plain decimals such as `4392` rank; a value with a unit, comma, range, or list (`8280ft`, `849;871`) and a feature lacking the tag follow the ranked ones in default order, counted in `unrankedCount`. The sort key need not be in `tag_keys`
- `effectiveArea` names the boundary `within` reached by its `name`, `boundary`, and `admin_level` tags, then the Overpass area it mapped to, so a mistyped ref shows; `areasTimestamp` says how old the area data is; a ref that maps to no area returns an empty page with a notice, and `effectiveArea` then reads `<ref> → no Overpass area`
- A `west` greater than `east` is a box crossing the antimeridian; `south` greater than `north` fails as `invalid_bbox`
---
### `openstreetmap_query_raw` <sub>tool</sub>
- Any Overpass QL containing `[out:json]`; `[timeout:N]` comes from `timeout_seconds` (up to 180, default 30) and `[maxsize:268435456]` (256 MiB) is added when the query sets none; up to 500 elements per page (a larger `limit` is served as 500 with a `limitNotice`)
- Returns raw elements (ways carry `nodes[]`, relations `members[]`), plus `total_elements` and the `effectiveQuery` as sent; malformed QL fails as `query_error` with Overpass's parse error
- Every element arrives whole unless `max_element_bytes` (minimum 1,000, no default) is set; an element over it has its `members`, `nodes`, or `geometry` withheld, listed under `withheld_keys`, and `withheldNotice` names the budget that returns the page whole, then `withheldElements` the offset and budget that fetch each element alone
## Features
Built on [`@cyanheads/mcp-ts-core`](https://github.com/cyanheads/mcp-ts-core): stdio and Streamable HTTP transports, pluggable auth (`none` / `jwt` / `oauth`), swappable storage (`in-memory`, `filesystem`, `Supabase`, `Cloudflare KV/R2/D1`), structured logging with optional OpenTelemetry tracing.
OpenStreetMap-specific:
- Nominatim requests are spaced 1,050 ms apart to respect its one-request-per-second policy, and each call has a 50 s budget covering its wait in line, attempts, and retries, ending as `upstream_error` when it runs out; `OSM_USER_AGENT` identifies the server to both upstreams
- Overpass queries are limited per endpoint by `OSM_OVERPASS_MAX_CONCURRENCY`, with opt-in failover across `OSM_OVERPASS_ENDPOINTS` (see [Overpass endpoint failover](#overpass-endpoint-failover))
- Overpass tools page with `limit` and `offset` and report `totalFound`, `truncated`, and `nextOffset`; results are cached for 10 minutes (Nominatim for 60), so re-paging makes no new upstream request; a result over 100,000 elements, or an unranked one whose Overpass response is over 25 MiB, is served uncached and each page re-queries
- An Overpass response over 64 MiB fails as `result_too_large`
- `OSM_NOMINATIM_BASE_URL` and `OSM_OVERPASS_BASE_URL` point the server at a self-hosted or mirror instance
Agent-friendly output:
- `effectiveQuery` and `effectiveTag` echo what was sent, and `effectiveArea` names the boundary a `within` ref reached; Overpass responses add `data_timestamp` and `servingEndpoint`, and every response carries the ODbL `attribution`
- `osm_type` + `osm_id` from any tool feed `openstreetmap_lookup_objects`, and a geocoded relation or way becomes a `within` ref for `openstreetmap_query_bbox`
- The Nominatim tools never select by tag, and `tagSelectionCaveat` says so; regex, alternation, and negation go through `openstreetmap_query_raw`
- Names, tag values, and caller text quoted in a `notice` are escaped in the Markdown output; `structuredContent` keeps the raw text
## Getting started
Connect to the hosted instance, no install:
```sh
claude mcp add --transport http openstreetmap-mcp-server https://openstreetmap.caseyjhand.com/mcp
```
Or run it locally:
```sh
claude mcp add openstreetmap-mcp-server -- npx -y @cyanheads/openstreetmap-mcp-server
```
For other clients, add this to the MCP config file:
```json
{
"mcpServers": {
"openstreetmap-mcp-server": {
"command": "npx",
"args": ["-y", "@cyanheads/openstreetmap-mcp-server"]
}
}
}
```
No API key is required. For heavy use, point `OSM_NOMINATIM_BASE_URL` and `OSM_OVERPASS_BASE_URL` at your own instances. For Docker or a source build, see [Running the server](#running-the-server).
## Configuration
| Variable | Description | Default |
|:---|:---|:---|
| `OSM_NOMINATIM_BASE_URL` | Nominatim base URL. A path prefix such as `https://maps.example.com/nominatim` is supported. | `https://nominatim.openstreetmap.org` |
| `OSM_OVERPASS_BASE_URL` | Pins every query to one Overpass endpoint and disables failover. | unset |
| `OSM_OVERPASS_ENDPOINTS` | Comma-separated, ordered Overpass endpoints; more than one enables failover. Ignored when `OSM_OVERPASS_BASE_URL` is set. | `https://overpass-api.de/api/interpreter` |
| `OSM_OVERPASS_MAX_CONCURRENCY` | Max Overpass queries in flight per endpoint. Public instances allow one per user. | `1` |
| `OSM_USER_AGENT` | User-Agent sent to Nominatim and Overpass. Required by usage policy. | `openstreetmap-mcp-server/<package version>` |
| `MCP_TRANSPORT_TYPE` | Transport: `stdio` or `http`. | `stdio` |
| `MCP_HTTP_PORT` | HTTP server port. | `3010` |
| `MCP_SESSION_MODE` | HTTP session mode: `stateless`, `stateful`, or `auto`. The server declares `stateless` in code; an explicit value overrides it. | `stateless` |
| `MCP_AUTH_MODE` | Authentication: `none`, `jwt`, or `oauth`. | `none` |
| `MCP_LOG_LEVEL` | Log level (`debug`, `info`, `warning`, `error`, etc.). | `info` |
| `STORAGE_PROVIDER_TYPE` | Storage backend: `in-memory`, `filesystem`, `supabase`, `cloudflare-kv/r2/d1`. | `in-memory` |
| `OTEL_ENABLED` | Enable [OpenTelemetry](https://github.com/cyanheads/mcp-ts-core/tree/main/docs/telemetry). | `false` |
See [`.env.example`](./.env.example) for the full list of optional overrides. An invalid value for any `OSM_*` variable stops the server at startup with a message naming the variable.
### Overpass endpoint failover
By default every Overpass query goes to one endpoint, the FOSSGIS-operated main instance. List more in `OSM_OVERPASS_ENDPOINTS` and a failed call moves to the next entry in order:
```sh
OSM_OVERPASS_ENDPOINTS="https://overpass-api.de/api/interpreter,https://overpass.private.coffee/api/interpreter"
```
- Endpoints that fail repeatedly are skipped for a while (30 seconds, doubling up to 10 minutes)
- When every endpoint fails, the call fails with `rate_limited`, `upstream_error`, `overpass_unavailable`, `endpoints_rejected`, `endpoints_exhausted`, or `endpoints_unavailable`, with each endpoint's outcome in the message; `openstreetmap_query_raw` adds `query_unsupported` when no endpoint holds the attic data a `[date:]`, `[diff:]`, or `[adiff:]` query reads or the metadata `out meta` prints, and an endpoint without that data is skipped for the call
- Endpoints are reported by origin only (`https://overpass-api.de`) in `servingEndpoint`, error messages, and logs
- Extra entries are failover only and never add concurrency. For an instance that allows parallel queries, append `|N` to its entry (`https://mirror.example/api/interpreter|4`) for N slots; write a literal `|` in a URL as `%7C`. Never size a public instance (the FOSSGIS servers, maps.mail.ru, overpass.private.coffee)
- Calls waiting for a slot fail with `pacer_shed` and a `retryAfter` of at least 30 seconds after 30 seconds in line
Adding an endpoint sends your queries to a third party. Check its usage policy on the [OSM wiki instance list](https://wiki.openstreetmap.org/wiki/Overpass_API#Public_Overpass_API_instances), confirm it holds global data (a regional instance answers out-of-extract queries with an empty HTTP 200), and expect mirrors to lag the main instance; `servingEndpoint` and `data_timestamp` show which host answered and how fresh its data was.
## Running the server
### Local development
Requires [Bun v1.4.4](https://bun.sh/) or higher (or Node.js v24+).
```sh
git clone https://github.com/cyanheads/openstreetmap-mcp-server.git
cd openstreetmap-mcp-server && bun install
cp .env.example .env
# edit .env to override endpoints or the User-Agent as needed
```
- **Build and run the production version**:
```sh
# One-time build
bun run rebuild
# Run the built server
bun run start:http
# or
bun run start:stdio
```
- **Run checks and tests**:
```sh
bun run devcheck # Lints, formats, type-checks, and more
bun run test # Runs the test suite
```
### Docker
```sh
docker run --rm -p 3010:3010 ghcr.io/cyanheads/openstreetmap-mcp-server:latest
# or build locally
docker build -t openstreetmap-mcp-server .
docker run --rm -p 3010:3010 openstreetmap-mcp-server
```
The image serves HTTP at `http://localhost:3010/mcp` in stateless session mode and logs to `/var/log/openstreetmap-mcp-server`. OpenTelemetry peer dependencies are installed by default; build with `--build-arg OTEL_ENABLED=false` to omit them. Runtime telemetry stays off until you pass `-e OTEL_ENABLED=true`.
## Project structure
| Directory | Purpose |
|:---|:---|
| `src/mcp-server/tools` | Tool definitions (`*.tool.ts`) and shared input, formatting, and escaping helpers. Six tools across Nominatim and Overpass. |
| `src/services/nominatim` | Nominatim service: paced API client for search, reverse, and lookup, plus error parsing. |
| `src/services/overpass` | Overpass service: query builder, endpoint failover and executor, element normalizer, error parsing. |
| `src/config` | Server-specific environment variable parsing and validation with Zod. |
| `tests/` | Unit and integration tests for tools, services, and security. |
## Development guide
See [`CLAUDE.md`](./CLAUDE.md) for development guidelines and architectural rules. The short version:
- Handlers throw, framework catches — no `try/catch` in tool logic
- Use `ctx.log` for logging, `ctx.state` for storage
- Register new tools in the `createApp()` arrays in `src/index.ts`
- Wrap external API calls: validate raw → normalize to domain type → return output schema; never fabricate missing fields
## Contributing
Issues are welcome. Run checks and tests before submitting:
```sh
bun run devcheck
bun run test
```
## License
Apache-2.0 — see [LICENSE](./LICENSE) for details.
Map data from [OpenStreetMap](https://www.openstreetmap.org/copyright) contributors, available under the [Open Database License (ODbL)](https://opendatacommons.org/licenses/odbl/).
This server cannot be deployed
Maintenance
ActivityActive
ResponsivenessLimited data