一个使用OpenStreetMap Nominatim API提供城市和地点经纬度坐标的Model Context Protocol (MCP)服务器。
uvx geocode-mcp进行安装从PyPI使用uvx(推荐)安装包:
uvx geocode-mcp
或者使用pip安装:
pip install geocode-mcp
添加到您的MCP客户端配置中:
{
"mcpServers": {
"geocoding": {
"command": "uvx",
"args": ["geocode-mcp"]
}
}
}
查看config/目录以获取不同工具的具体示例。
mcp_geocoding_get_coordinates获取城市或地点的经纬度坐标。
参数:
location(必需):城市名称、地址或位置(例如:"New York","Paris, France","123 Main St, Seattle")limit(可选):返回结果的最大数量(默认值:1,最大值:10)示例用法:
获取东京,日本的坐标
查找伦敦,英国的纬度和经度
纽约市的坐标是什么?
获取“1600 Pennsylvania Avenue, Washington DC”的坐标,限制为5
响应格式:
{
"query": "Tokyo, Japan",
"results_count": 1,
"coordinates": [
{
"latitude": 35.6762,
"longitude": 139.6503,
"display_name": "Tokyo, Japan",
"place_id": "282885117",
"type": "city",
"class": "place",
"importance": 0.9,
"bounding_box": {
"south": 35.619,
"north": 35.739,
"west": 139.619,
"east": 139.682
}
}
]
}
将配置从config/cursor-mcp.json复制到您的Cursor MCP设置中。
将配置从config/vscode-mcp.json复制到您的VS Code MCP设置中。
将配置从config/claude-desktop.json复制到您的Claude Desktop配置文件中。
查看config README以获取详细的设置说明。
# 克隆仓库
git clone https://github.com/X-McKay/geocode-mcp.git
cd geocode-mcp
# 使用开发依赖项安装
pip install -e ".[dev]"
# 运行所有测试
pytest
# 带覆盖率运行
pytest --cov=src/geocode_mcp --cov-report=html
# 运行特定测试文件
pytest tests/test_geocoding.py -v
pytest tests/test_mcp_server.py -v
# 格式化代码
ruff format
# 检查代码
ruff check
# 运行所有检查
ruff check && ruff format --check
对于本地开发和测试,您可以直接运行服务器:
python -m geocode_mcp.server
或者在您的MCP客户端中使用开发配置:
{
"mcpServers": {
"geocoding": {
"command": "python",
"args": ["-m", "geocode_mcp.server"],
"cwd": "/path/to/geocode-mcp",
"env": {
"PYTHONPATH": "/path/to/geocode-mcp/src"
}
}
}
}
geocode-mcp/
├── src/geocode_mcp/ # 主源代码
│ └── server.py # MCP服务器实现
├── tests/ # 测试套件
│ ├── test_geocoding.py # 地理编码功能测试
│ ├── test_mcp_server.py # MCP服务器集成测试
│ ├── test_mcp.py # MCP协议测试
│ └── test_vscode.py # VS Code集成测试
├── config/ # 配置示例
│ ├── cursor-mcp.json # Cursor配置
│ ├── vscode-mcp.json # VS Code配置
│ ├── claude-desktop.json # Claude Desktop配置
│ └── README.md # 配置指南
├── docs/ # 文档
├── pyproject.toml # 项目配置
├── requirements.txt # 生产依赖项
├── requirements-dev.txt # 开发依赖项
└── README.md # 本文件
async def geocode_location(location: str, limit: int = 1) -> dict[str, Any]:
"""
使用OpenStreetMap Nominatim API对位置进行地理编码。
参数:
location: 要地理编码的位置
limit: 结果的最大数量(1-10)
返回:
包含查询、结果计数和坐标的字典
"""
该服务器实现了模型上下文协议,并提供了mcp_geocoding_get_coordinates工具,用于在兼容MCP的应用程序中使用。
git checkout -b feature/amazing-feature)pytest)ruff check && ruff format)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)查看CONTRIBUTING.md以获取更多详细信息。
该项目根据MIT许可证授权 - 查看LICENSE文件以获取详细信息。
创建项目文件夹:
mkdir mcp-geocoding-server-python
cd mcp-geocoding-server-python
复制文件: 将上述每个文件部分复制到相应命名的文件中
安装依赖项:
pip install -r requirements.txt
运行服务器:
python geocoding_server.py
配置MCP客户端: 添加到您的MCP客户端(如Claude Desktop)配置中:
{
"mcpServers": {
"geocoding": {
"command": "python",
"args": ["/full/path/to/mcp-geocoding-server-python/geocoding_server.py"]
}
}
}