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

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

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

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.1.tar.gz (6.4 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.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: geocode_mcp_hubei-0.1.1.tar.gz
  • Upload date:
  • Size: 6.4 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.1.tar.gz
Algorithm Hash digest
SHA256 79a3a48d12f440f0e0932fc9caa36e0fc08ddfd837b1656043d136d24e324fa8
MD5 3546da9253697a998aae18b0ebfccc5a
BLAKE2b-256 aee034885a3cec98cd1b1320a77da9ec3d078ee6470695660f0e23583b1dd3a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for geocode_mcp_hubei-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f76705dcbdc11445a7b0543a8e8c9bd85c5faea887d03720074a251672f3524c
MD5 e3a58a63aa3bbe8d7046cb24ea167f67
BLAKE2b-256 5418021b9fc644bc3925e85b64fdbbbf86772a20fcdcbff5041f22eedaffb904

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