Skip to content

MCP Hub Guide

zhouning edited this page Mar 22, 2026 · 1 revision

MCP Hub 指南

GIS Data Agent v14.5 — 基于 Google ADK 的 AI 地理空间平台 仓库:https://github.com/zhouning/gisdataagent

什么是 MCP?

Model Context Protocol (MCP) 是一套标准化协议,用于将 AI 代理与外部工具和服务连接。通过 MCP,GIS Data Agent 可以动态接入第三方工具服务器,扩展代理可用的工具集,而无需修改代码或重启应用。

MCP 的核心价值:

  • 标准化接口:统一的工具发现和调用协议
  • 动态扩展:运行时添加/移除工具服务器
  • 生态互通:接入任何符合 MCP 标准的工具提供者

添加 MCP 服务器

通过数据面板

  1. 打开数据面板 → MCP Hub(MCP 中心) 标签页
  2. 点击 "Add Server"(添加服务器)
  3. 配置服务器信息:
字段 说明 示例
名称 服务器显示名称 weather-tools
传输协议 通信方式(三选一) stdio / sse / streamable-http
命令/URL 启动命令或服务地址 见下方说明

3 种传输协议

stdio(标准输入/输出)

通过子进程启动 MCP 服务器,使用 stdin/stdout 通信。适合本地工具。

命令: python weather_server.py
参数: --port 8080

SSE (Server-Sent Events)

通过 HTTP SSE 连接远程 MCP 服务器。适合长连接场景。

URL: https://mcp.example.com/sse

Streamable HTTP

通过可流式传输的 HTTP 连接。适合现代 HTTP/2 环境。

URL: https://mcp.example.com/stream

YAML 配置文件

除了通过 UI 添加,还可以在 mcp_servers.yaml 中声明持久化的服务器配置:

servers:
  - name: weather-tools
    transport: stdio
    command: python
    args:
      - /path/to/weather_server.py
    env:
      API_KEY: your-api-key

  - name: geocoding-service
    transport: sse
    url: https://geocoding-mcp.example.com/sse

  - name: data-converter
    transport: streamable-http
    url: https://converter-mcp.example.com/stream

YAML 中定义的服务器在应用启动时自动加载。

工具发现

MCP Hub 连接到服务器后,自动执行 工具发现

  1. 向 MCP 服务器发送 tools/list 请求
  2. 服务器返回可用工具列表(名称、描述、参数定义)
  3. 工具自动注册到代理的可用工具集中

发现的工具会显示在 MCP Hub 标签页中,包括:

  • 工具名称和描述
  • 输入参数定义
  • 所属服务器信息
  • 连接状态

使用 MCP 工具

MCP 工具一旦被发现,即与内置工具并列,代理可以无缝调用:

使用天气工具查询北京今天的天气
Use the weather tool to check Beijing's weather today

将这个文件转换为GeoJSON格式
Convert this file to GeoJSON format

代理会根据用户请求自动选择最合适的工具——无需指定工具来源是内置还是 MCP。

热重载

MCP Hub 支持 热重载——在不重启应用的情况下动态管理服务器:

添加服务器

  • 通过 UI 添加 → 即时生效
  • 修改 mcp_servers.yaml → 触发重载

移除服务器

  • 通过 UI 删除 → 断开连接,移除工具
  • 不影响其他已连接的服务器

重新连接

  • 服务器断线后可一键重连
  • 重连后自动重新发现工具

MCP Hub API 端点

MCP Hub 提供 10 个 REST API 端点用于程序化管理:

端点 方法 功能
/api/mcp/servers GET 列出所有 MCP 服务器
/api/mcp/servers POST 添加新服务器
/api/mcp/servers/{id} PUT 更新服务器配置
/api/mcp/servers/{id} DELETE 删除服务器
/api/mcp/servers/{id}/tools GET 列出服务器的工具
/api/mcp/servers/{id}/connect POST 连接服务器
/api/mcp/servers/{id}/disconnect POST 断开服务器
/api/mcp/servers/{id}/status GET 获取连接状态
/api/mcp/tools GET 列出所有已发现的工具
/api/mcp/reload POST 重载 YAML 配置

MCP Hub Guide

GIS Data Agent v14.5 — AI geospatial platform on Google ADK Repository: https://github.com/zhouning/gisdataagent

What Is MCP?

Model Context Protocol (MCP) is a standardized protocol for connecting AI agents to external tools and services. Through MCP, GIS Data Agent can dynamically connect to third-party tool servers, extending the agent's available toolset without modifying code or restarting the application.

Core values of MCP:

  • Standardized interface: Unified tool discovery and invocation protocol
  • Dynamic extension: Add/remove tool servers at runtime
  • Ecosystem interoperability: Connect to any MCP-compliant tool provider

Adding MCP Servers

Via Data Panel

  1. Open the Data Panel → MCP Hub tab
  2. Click "Add Server"
  3. Configure server information:
Field Description Example
Name Server display name weather-tools
Transport Communication method (choose one) stdio / sse / streamable-http
Command/URL Launch command or service address See details below

3 Transport Protocols

stdio (Standard I/O)

Launch an MCP server as a subprocess, communicating via stdin/stdout. Best for local tools.

Command: python weather_server.py
Args: --port 8080

SSE (Server-Sent Events)

Connect to a remote MCP server via HTTP SSE. Best for long-lived connections.

URL: https://mcp.example.com/sse

Streamable HTTP

Connect via streamable HTTP transport. Best for modern HTTP/2 environments.

URL: https://mcp.example.com/stream

YAML Configuration

In addition to adding servers via UI, you can declare persistent server configurations in mcp_servers.yaml:

servers:
  - name: weather-tools
    transport: stdio
    command: python
    args:
      - /path/to/weather_server.py
    env:
      API_KEY: your-api-key

  - name: geocoding-service
    transport: sse
    url: https://geocoding-mcp.example.com/sse

  - name: data-converter
    transport: streamable-http
    url: https://converter-mcp.example.com/stream

Servers defined in YAML are automatically loaded at application startup.

Tool Discovery

After connecting to a server, MCP Hub automatically performs tool discovery:

  1. Sends a tools/list request to the MCP server
  2. Server returns available tools (names, descriptions, parameter definitions)
  3. Tools are automatically registered into the agent's available toolset

Discovered tools are displayed in the MCP Hub tab, including:

  • Tool name and description
  • Input parameter definitions
  • Parent server information
  • Connection status

Using MCP Tools

Once discovered, MCP tools appear alongside built-in tools, and agents can call them seamlessly:

使用天气工具查询北京今天的天气
Use the weather tool to check Beijing's weather today

将这个文件转换为GeoJSON格式
Convert this file to GeoJSON format

The agent automatically selects the most appropriate tool based on the user's request — no need to specify whether the tool is built-in or from MCP.

Hot Reload

MCP Hub supports hot reload — dynamically managing servers without restarting the application:

Adding Servers

  • Add via UI → takes effect immediately
  • Modify mcp_servers.yaml → triggers reload

Removing Servers

  • Delete via UI → disconnects and removes tools
  • Does not affect other connected servers

Reconnecting

  • One-click reconnect after server disconnection
  • Tools are automatically re-discovered after reconnection

MCP Hub API Endpoints

MCP Hub provides 10 REST API endpoints for programmatic management:

Endpoint Method Function
/api/mcp/servers GET List all MCP servers
/api/mcp/servers POST Add a new server
/api/mcp/servers/{id} PUT Update server configuration
/api/mcp/servers/{id} DELETE Delete a server
/api/mcp/servers/{id}/tools GET List a server's tools
/api/mcp/servers/{id}/connect POST Connect to a server
/api/mcp/servers/{id}/disconnect POST Disconnect from a server
/api/mcp/servers/{id}/status GET Get connection status
/api/mcp/tools GET List all discovered tools
/api/mcp/reload POST Reload YAML configuration

Clone this wiki locally