Skip to main content

MCP geocode tool wrapping 湖北POI 要素定位器 (findAddressCandidates)

Project description

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 的客户端通信。

工具调用示例(伪 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 工具调用)
  • 增加缓存与错误重试
  • 添加单元测试

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geocode_mcp_hubei-0.1.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

geocode_mcp_hubei-0.1.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file geocode_mcp_hubei-0.1.0.tar.gz.

File metadata

  • Download URL: geocode_mcp_hubei-0.1.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for geocode_mcp_hubei-0.1.0.tar.gz
Algorithm Hash digest
SHA256 636d74d8888a1ef9c37507003a1c2501a5a8ed456a44fb59bd3a53681c9369f6
MD5 489759b427d82b2584c4bcffab6a5dc3
BLAKE2b-256 6d654dcb899abacd2570fb4d5453dc1bbf593148ce72dd0a851cad93bf2e3562

See more details on using hashes here.

File details

Details for the file geocode_mcp_hubei-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for geocode_mcp_hubei-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9371c17819ae45d843d68f9da10cbe415f8055d2f12d6a3405b26b317ee97a0a
MD5 ffd620d9de189fd30daf10c2d0706ec8
BLAKE2b-256 9806ff84b701bf978f767e420e2bd2877e046934be0d7f94ac3ef30282278fee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page