Skip to main content

Geocode MCP Service

一个基于 Python + uv 的 Model Context Protocol (MCP) 服务,封装湖北 POI 要素定位器地理编码接口。

远程底层服务: GET https://geosc41.aakle.cn/server/rest/services/湖北POI_要素定位器/GeocodeServer/findAddressCandidates

功能

  • 暴露一个 MCP 工具:geocode_poi(可自定义)
  • 输入:address (字符串)
  • 内部映射为远程接口 SingleLine
  • 固定参数:maxLocations=8, f=pjson, outSR=4326, outFields=*
  • 输出:简化的候选列表(名称、坐标、得分、原始 JSON)

快速开始

# 创建并激活虚拟环境 (可选)
python -m venv .venv
.\.venv\Scripts\activate

# 安装依赖 (使用 uv 或 pip)
pip install -r requirements.txt
# 或者
uv pip install -r requirements.txt

# 运行本地测试脚本
python src/test_geocode.py "中国地质大学"

作为 MCP 服务器运行

python -m geocode_mcp.server

服务器会通过标准输入输出与支持 MCP 的客户端通信。

安装为可执行脚本后也可直接运行(两种等价):

geocode-mcp
# 或使用别名脚本
geocode-poi-server

百炼 / uvx 托管配置示例

mcpServers JSON:

{
  "mcpServers": {
    "geocode_poi": {
      "type": "stdio",
      "command": "uvx",
      "args": ["geocode-mcp-hubei>=0.1.0,<0.2", "geocode-mcp"]
    }
  }
}

或使用新增的别名脚本(省去显式写第二个参数):

{
  "mcpServers": {
    "geocode_poi": {
      "type": "stdio",
      "command": "uvx",
      "args": ["geocode-mcp-hubei>=0.1.0,<0.2", "geocode-poi-server"]
    }
  }
}

工具调用示例(伪 JSON-RPC)

{
  "method": "tools/call",
  "params": {
    "name": "geocode_poi",
    "arguments": {"address": "中国地质大学"}
  }
}

部署到阿里云

  1. 选择部署方式:
    • 函数计算(推荐无服务器)
    • ECS 容器/实例
  2. 函数计算示例:
    • Runtime: Python 3.11
    • 入口:fc_handler.handler
  3. 打包:
Compress-Archive -Path src,requirements.txt -DestinationPath package.zip
  1. 上传并在启动代码里调用 from geocode_mcp.server import run_server,需要改造成 HTTP 触发器包装。

MCP 典型运行基于长连接/标准 IO,若在函数计算上使用,需要将协议桥接为 HTTP:可创建一个简单的 HTTP 转 MCP 工具适配层(后续 TODO)。

TODO

  • 阿里云 HTTP 适配层 (把 HTTP 请求映射为 geocode 工具调用)
  • 增加缓存与错误重试
  • 添加单元测试

Metadata

Release files for geocode-mcp-hubei 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for geocode-mcp-hubei 0.1.1
File Size Uploaded Provenance
geocode_mcp_hubei-0.1.1.tar.gz 6.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for geocode-mcp-hubei 0.1.1
File Interpreter ABI Platform
geocode_mcp_hubei-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 13.6 kB

Release files / geocode_mcp_hubei-0.1.1.tar.gz

Download URL geocode_mcp_hubei-0.1.1.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
79a3a48d12f440f0e0932fc9caa36e0fc08ddfd837b1656043d136d24e324fa8
BLAKE2b-256 checksum
How to use checksums
aee034885a3cec98cd1b1320a77da9ec3d078ee6470695660f0e23583b1dd3a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.5

Release files / geocode_mcp_hubei-0.1.1-py3-none-any.whl

Download URL geocode_mcp_hubei-0.1.1-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f76705dcbdc11445a7b0543a8e8c9bd85c5faea887d03720074a251672f3524c
BLAKE2b-256 checksum
How to use checksums
5418021b9fc644bc3925e85b64fdbbbf86772a20fcdcbff5041f22eedaffb904
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.5

Security for geocode-mcp-hubei 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page