osm工具
OpenStreetMap MCP服务器提供地理编码、反向地理编码、POI搜索和路由功能。
特性
- 地理编码:正向地理编码-按地址/地名搜索
- 逆地理编码:从坐标中获取地址
- POI搜索:使用天桥API搜索兴趣点
- 路线:使用OSRM计算两点之间的路线
安装
npm install
npm run build用法
作为MCP服务器(stdio)
npm start
# or
node dist/cli.js --transport stdio作为HTTP服务器
node dist/cli.js --transport http --port 3000配置
可以通过环境变量或命令行参数设置配置:
| 环境变量 | CLI标志 | 默认值 | 描述 |
|---|---|---|---|
OSM_TRANSPORT | --transport | stdio | 运输方式: stdio 或 http |
OSM_HTTP_PORT | --port | 3000 | HTTP服务器端口 |
OSM_USER_AGENT | - | osm-tools-mcp/1.0.0 | API请求的用户代理 |
OSM_THROTTLE_MS | - | 1000 | API请求之间的延迟(ms) |
OSM_NOMINATIM_URL | - | https://nominatim.openstreetmap.org | API名称URL |
OSM_OVERPASS_URL | - | https://overpass-api.de/api/interpreter | 天桥API URL |
OSM_OSRM_URL | - | https://router.project-osrm.org | OSRM API URL |
工具
地理编码
正向地理编码:通过地址或地名搜索位置。
输入:
{
"query": "Empire State Building, New York",
"bbox": [-74.1, 40.7, -73.9, 40.8],
"country": "US"
}输出:
{
"ok": true,
"data": [
{
"lat": 40.7484,
"lon": -73.9857,
"display_name": "Empire State Building, 350, 5th Avenue, Manhattan, New York, NY 10118, USA",
"type": "attraction",
"importance": 0.825,
"place_id": 123456
}
],
"meta": {
"source": "nominatim",
"retrieved_at": "2024-01-15T12:00:00.000Z",
"pagination": { "next_cursor": null },
"warnings": []
}
}反向geocode
反向地理编码:从坐标中获取地址。
输入:
{
"lat": 40.7484,
"lon": -73.9857
}输出:
{
"ok": true,
"data": {
"lat": 40.7484,
"lon": -73.9857,
"display_name": "Empire State Building, 350, 5th Avenue, Manhattan, New York, NY 10118, USA",
"address": {
"house_number": "350",
"road": "5th Avenue",
"city": "New York",
"state": "New York",
"postcode": "10118",
"country": "United States",
"country_code": "us"
},
"place_id": 123456
},
"meta": {
"source": "nominatim",
"retrieved_at": "2024-01-15T12:00:00.000Z",
"pagination": { "next_cursor": null },
"warnings": []
}
}poi_search
使用OpenStreetMap天桥API搜索兴趣点。
输入(使用bbox):
{
"center_or_bbox": {
"bbox": [40.7, -74.1, 40.8, -73.9]
},
"tags": {
"amenity": "restaurant",
"cuisine": "italian"
},
"limit": 10
}输入(带中心点,半径1km):
{
"center_or_bbox": {
"center": [40.7484, -73.9857]
},
"tags": {
"amenity": "cafe"
}
}输出:
{
"ok": true,
"data": [
{
"id": 123456789,
"name": "Little Italy Restaurant",
"lat": 40.7195,
"lon": -73.9973,
"tags": {
"amenity": "restaurant",
"cuisine": "italian",
"name": "Little Italy Restaurant"
},
"type": "node"
}
],
"meta": {
"source": "overpass",
"retrieved_at": "2024-01-15T12:00:00.000Z",
"pagination": { "next_cursor": null },
"warnings": []
}
}路线
使用OSRM计算两点之间的路线。
输入:
{
"start": [40.7128, -74.006],
"end": [40.7484, -73.9857],
"mode": "walking"
}输出:
{
"ok": true,
"data": {
"distance_km": 4.2,
"duration_minutes": 52,
"geometry": "encoded_polyline_string",
"steps": [
{
"instruction": "Depart",
"distance_m": 150,
"duration_s": 108,
"name": "Broadway"
},
{
"instruction": "Turn right",
"distance_m": 500,
"duration_s": 360,
"name": "5th Avenue"
},
{
"instruction": "Arrive at destination",
"distance_m": 0,
"duration_s": 0,
"name": ""
}
],
"summary": "Broadway, 5th Avenue"
},
"meta": {
"source": "osrm",
"retrieved_at": "2024-01-15T12:00:00.000Z",
"pagination": { "next_cursor": null },
"warnings": []
}
}MCP客户端配置
克劳德桌面版
添加到您的Claude Desktop配置中:
{
"mcpServers": {
"osm-tools": {
"command": "node",
"args": ["/path/to/osm-tools/dist/cli.js"]
}
}
}API使用策略
此服务器使用公共OpenStreetMap API。请尊重他们的使用政策:
- 提名:每秒最多1个请求,包括适当的用户代理
- 天桥:注意查询的复杂性和频率
- OSRM:公共演示服务器有速率限制
服务器内置了节流功能(请求之间的默认间隔为1000ms),以符合这些策略。
发展
# Install dependencies
npm install
# Build
npm run build
# Run tests
npm test
# Watch mode for development
npm run dev测试
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage许可证
麻省理工学院
