Skip to main content
Glama

osm-mcp

CI npm version npm downloads node Container license Docs

一个用于 OpenStreetMap 的 MCP 服务器:提供地理编码、步行/驾车/骑行距离与时长、多点路线优化、等时线及兴趣点搜索——专为 AI 助手的旅行规划而构建。

共 11 个工具,全部为只读。所有后端均为免费的公共 OpenStreetMap 服务;无需 API 密钥。可选择性提供 OpenRouteService 密钥以切换路由引擎。

📖 完整文档:https://osm-mcp.ni-c.de

为什么需要另一个 OSM MCP 服务器?

  • 正确的步行/骑行路线。 公共 OSRM 演示服务器会忽略 OSRM URL 路径中的配置文件段,除非使用 FOSSGIS 的 routed-foot / routed-bike / routed-car 路径前缀,否则始终返回驾车路线。大多数现有的 OSM MCP 服务器在这方面都是错误的,会静默地为步行查询返回驾车时间。本服务器使用了这些前缀,其实时冒烟测试断言步行路线的速度远慢于驾车路线。

  • 符合策略要求。 按服务进行速率限制(Nominatim 和 OSRM:每秒 1 个请求),每个请求都带有标识性的 User-Agent(Nominatim 使用策略要求),响应缓存,限制 Overpass 并发数(2 个槽位),并在遇到 429/5xx 错误时自动故障转移到 Overpass 镜像。

  • 支持 Photon。 通过 komoot 的 Photon 提供可选的容错地理编码,该服务专为交互式使用而设计——比频繁调用 Nominatim 更适合 LLM 驱动的查询。

Related MCP server: Geo MCP Worker

系统要求

  • Node.js ≥ 22

  • 能够访问公共 OpenStreetMap 服务(见下表)

配置

所有变量均为可选——服务器开箱即用。

变量

默认值

描述

OSM_USER_AGENT

osm-mcp/<版本号> (+https://github.com/ni-c/osm-mcp)

发送给每个服务的 User-Agent。Nominatim 要求使用真实且可识别的 User-Agent。

NOMINATIM_BASE_URL

https://nominatim.openstreetmap.org

地理编码/反向地理编码

PHOTON_BASE_URL

https://photon.komoot.io

容错地理编码

OSRM_BASE_URL

https://routing.openstreetmap.de

路由、矩阵、行程优化。必须提供 routed-{car,bike,foot} 路径前缀(FOSSGIS 布局)。

OVERPASS_BASE_URL

https://overpass-api.de/api/interpreter,https://overpass.private.coffee/api/interpreter

逗号分隔的 Overpass 端点,在遇到 429/5xx 错误时按顺序尝试

VALHALLA_BASE_URL

https://valhalla1.openstreetmap.de

等时线

ORS_API_KEY

–

可选的 OpenRouteService 密钥(机密)。设置后,路线、矩阵和等时线将使用 ORS 而非 OSRM/Valhalla。免费套餐:每天 2000 次方向查询,每分钟 40 次。

ORS_BASE_URL

https://api.openrouteservice.org

OpenRouteService 端点

OSM_CACHE_TTL

3600

相同上游响应从内存缓存中提供的秒数(0 表示禁用缓存)

安装

claude mcp add osm -- npx -y osm-mcp

Claude Desktop(claude_desktop_config.json):

{
  "mcpServers": {
    "osm": {
      "command": "npx",
      "args": ["-y", "osm-mcp"]
    }
  }
}

Codex(~/.codex/config.toml):

[mcp_servers.osm]
command = "npx"
args = ["-y", "osm-mcp"]

容器(多架构,包含 SBOM 和构建来源):

docker run -i --rm ghcr.io/ni-c/osm-mcp

-i 是必需的——协议通过标准输入和标准输出运行。没有需要发布的端口。更多客户端配置请参见客户端指南。

工具

工具

描述

geocode

地名/地址 → 坐标(Nominatim 或 Photon)

reverse_geocode

坐标 → 最近地址

route

2 个及以上途经点之间的距离和时长,支持 foot/car/bike;可选逐段转向摘要

route_matrix

一次调用即可获取从每个起点到每个终点的旅行时间/距离

optimize_route

一组停靠点的最佳访问顺序(旅行商问题,OSRM trip)

isochrone

在时间或距离预算内可到达的区域(Valhalla,或使用密钥的 ORS)

find_nearby_pois

按类别或原始 OSM 标签查找某位置周围的兴趣点,按距离排序(Overpass)

poi_details

单个元素的完整 OSM 记录:营业时间、网站、电话……

suggest_meeting_point

为 2–8 人寻找公平的会面地点(平衡旅行时间)

straight_line_distance

大圆距离,离线计算

map_link

openstreetmap.org 标记/方向链接,离线计算

每个地点输入都接受名称/地址(自动进行地理编码)或文字坐标 "lat,lon"。

使用策略与署名

本服务器与共享的社区基础设施通信。它在客户端强制执行已发布的限制,但运营方要求用户保持整体使用量较低且非商业用途:

  • 数据: © OpenStreetMap 贡献者,根据 ODbL 1.0 许可。

  • Nominatim: 每秒最多 1 个请求,必须使用可识别的 User-Agent,结果已缓存(策略)。

  • OSRM / Valhalla (FOSSGIS): 合理的非商业用途;每秒最多 1 个请求(关于)。

  • Overpass: 每个 IP 约 2 个并发槽位,每天少于 10,000 次查询(维基)。

  • Photon: 合理使用(photon.komoot.io)。

对于大量或商业用途,请自行托管服务,并将 *_BASE_URL 变量指向您的实例。

安全性

  • 所有工具均为只读;服务器从不向 OpenStreetMap 写入数据。

  • 无需凭据;可选的 ORS_API_KEY 在加载后会从进程环境中移除,并在错误消息中被屏蔽。

  • OSM 来源的内容(名称、地址、标签)在工具结果中被标记为不可信数据,以便模型将其视为数据而非指令。

  • 上游错误正文会被截断,HTML 错误页面在到达模型上下文之前会被丢弃。

  • 从不跟随重定向;所有请求都有超时。

开发

npm install
npm run lint          # eslint + prettier
npm test              # unit tests (all upstream APIs mocked)
npm run test:coverage
npm run build
npm run smoke         # opt-in LIVE test against the real public services

发布

基于标签驱动,无需手动发布步骤:

  1. 将 [Unreleased] 条目移至 CHANGELOG.md 中新的 ## [x.y.z] - YYYY-MM-DD 部分,并更新 package.json 版本号。

  2. 运行 npm run lint && npm run build && npm run test:coverage。

  3. 提交,然后创建一个带签名的注释标签:git tag -s vx.y.z -m "vx.y.z"。

  4. 运行 git push origin main vx.y.z。

然后 release.yml 会运行测试,通过 Trusted Publishing(不涉及令牌密钥)将包发布到 npm 并附带来源信息,从 CHANGELOG 部分创建 GitHub 发布,并以 io.github.ni-c/osm-mcp 的名称发布到 MCP 注册表。ci.yml 会在同一标签上将多架构镜像推送到 GHCR。

如果注册表步骤失败,请在 main 分支上修复问题并触发 Publish to MCP Registry 工作流——不要重新运行标签作业,因为那样会检出旧的代码树。

许可证

MIT

Available Tools

11 tools
find_nearby_poisFind nearby places (POIs)A
Read-onlyIdempotent

Finds points of interest near a location, sorted by distance. Category shortcuts: restaurant, cafe, bar, pub, fast_food, ice_cream, hotel, hostel, guest_house, apartment, camp_site, attraction, museum, gallery, viewpoint, information, artwork, castle, monument, ruins, supermarket, bakery, convenience, pharmacy, hospital, doctors, police, atm, bank, fuel, charging_station, parking, toilets, drinking_water, bus_stop, train_station, tram_stop, ferry_terminal, bicycle_rental, car_rental, playground, park, beach, swimming_pool. Any other OSM tag works as "key" or "key=value" (e.g. "diet:vegan=yes"). Use poi_details for the full record of one result.

Inputs: near (required), category (required), limit, language, +1 more. Returns: near, note, count, source, +3 more

geocodeGeocode a place or addressA
Read-onlyIdempotent

Converts a place name or address into coordinates using OpenStreetMap. Returns matching places with lat/lon, a display label and the OSM id. Provider "nominatim" (default) is best for addresses; "photon" is typo-tolerant and better for fuzzy place names.

Inputs: query (required), limit, language, provider, +1 more. Returns: note, source, results, provider, +1 more

isochroneReachable area (isochrone)A
Read-onlyIdempotent

Shows how far you can get from a place within a time or distance budget ("what is reachable in 15 minutes on foot?"). Returns a compact summary of the reachable area: bounding box and reach per compass direction. Give exactly one of minutes or kilometers.

Inputs: center (required), profile (required), minutes, language, +1 more. Returns: reach, budget, center, engine, +4 more

optimize_routeOptimize stop orderA
Read-onlyIdempotent

Finds the best order to visit a set of stops (traveling-salesman optimization) and returns the optimized itinerary with total distance and time. With roundtrip (default) the tour returns to the first stop; without it the first stop is the start and the last stop the end.

Inputs: stops (required), profile (required), language, roundtrip. Returns: legs, engine, source, profile, +4 more

poi_detailsGet POI detailsA
Read-onlyIdempotent

Fetches the full OpenStreetMap record of one element — all tags (opening hours, website, phone, …), coordinates and a map link. Takes an OSM id as returned by find_nearby_pois or geocode, e.g. "node/240109189".

Inputs: osm_id (required). Returns: lat, lon, map, osm, +4 more

reverse_geocodeReverse geocode coordinatesA
Read-onlyIdempotent

Converts coordinates into the nearest address or place name (Nominatim).

Inputs: latitude (required), longitude (required), language. Returns: note, result, source, untrusted

routeRoute between placesA
Read-onlyIdempotent

Calculates the real-world travel distance and time between two or more places, walking, driving or cycling, on OpenStreetMap data. Waypoints are visited in the given order. Set include_steps for a turn-by-turn summary. Use route_matrix to compare many pairs, optimize_route to reorder stops.

Inputs: profile (required), waypoints (required), language, include_steps. Returns: legs, steps, engine, source, +8 more

route_matrixTravel time/distance matrixA
Read-onlyIdempotent

Computes travel times and distances from every origin to every destination in one call — ideal for comparing options (e.g. 5 hotels against 3 sights). Cells are null where no route exists.

Inputs: origins (required), profile (required), destinations (required), language. Returns: engine, source, origins, profile, +4 more

straight_line_distanceStraight-line distanceA
Read-onlyIdempotent

Great-circle ("as the crow flies") distance between two places. Instant and independent of any road network — use route for real travel distances.

Inputs: to (required), from (required), language. Returns: to, from, source, distance, +2 more

suggest_meeting_pointSuggest a meeting pointA
Read-onlyIdempotent

Suggests a fair place to meet for people starting from different locations: finds venues around the geographic midpoint and picks the one with the most balanced travel times for everyone.

Inputs: locations (required), profile, language, venue_category, +1 more. Returns: note, source, profile, midpoint, +4 more

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.3/5.0

    Scored across 11 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose: geocode/reverse_geocode handle place-coordinate conversion, route/route_matrix/optimize_route are tightly differentiated by use case, and find_nearby_pois/poi_details form a clear list-to-detail flow. The routing tools could feel similar at first glance, but their descriptions explicitly disambiguate single ordered routes, many-to-many matrices, and stop reordering.

    Naming Consistency4/5

    Most multi-word names use a predictable snake_case style: reverse_geocode, route_matrix, find_nearby_pois, straight_line_distance. The set does mix verb-led names like find_nearby_pois and optimize_route with noun-led names like isochrone, poi_details, and map_link, but the overall pattern is still clear and readable.

    Tool Count5/5

    With 11 tools, the server is well within the ideal range and each tool earns its place by covering a distinct geospatial capability. None of the tools feel redundant, and the count is appropriate for a domain spanning geocoding, routing, POI search, and map links.

    Completeness5/5

    The tool set covers the full common workflow for an OSM-based location server: forward and reverse geocoding, routes, matrices, route optimization, isochrones, POI discovery and details, meeting-point suggestions, straight-line distance, and shareable map links. Results from earlier tools feed naturally into later tools, such as POI ids into poi_details and places into route or map_link, leaving no obvious dead ends.

    Maintenance

    ActivityNo data
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      A comprehensive MCP server providing 30 tools for geocoding, routing, and OpenStreetMap data analysis. It enables AI assistants to search for locations, calculate travel routes, and perform quality assurance checks on map data.
      30
      6
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Free geospatial MCP server for AI agents, providing geocoding, reverse geocoding, POI search, and route planning using OpenStreetMap data via Nominatim, Overpass, and OSRM.
      GPL 3.0
    • A
      license
      Not graded
      quality
      C
      maintenance
      MCP server for geocoding, reverse geocoding, place/POI search, and distance calculation using OpenStreetMap Nominatim, with no API key required.
      89 npm
      1
      MIT