Skip to main content
Glama

osm-mcp

CI npm version npm downloads node Container license Docs

一个用于 OpenStreetMapMCP 服务器:提供地理编码、步行/驾车/骑行距离与时长、多点路线优化、等时线及兴趣点搜索——专为 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

Install Server
A
license - permissive license
A
quality
A
maintenance

Maintenance

Maintainers
Response time
Release cycle
1Releases (12mo)
Commit activity

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
    3
    MIT
  • A
    license
    -
    quality
    B
    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.
    1
    GPL 3.0
  • A
    license
    -
    quality
    A
    maintenance
    MCP server for geocoding, reverse geocoding, place/POI search, and distance calculation using OpenStreetMap Nominatim, with no API key required.
    183
    MIT

View all related MCP servers

Related MCP Connectors

  • MCP server for Japan geodata: cadastral lot numbers (chiban) and reverse geocoding, for AI agents.

  • Hosted MCP server for LLM cost estimation, model comparison, and budget-aware routing.

  • AI marketplace — flights, tours, activities, transport & more via MCP. No auth required.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ni-c/osm-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server