Skip to main content
Glama
KMB Bus MCP Server

KMB Bus MCP Server

by kennyckk

九巴巴士MCP服务器

一个模型上下文协议 (MCP) 服务器,可实时访问香港九龙巴士 (KMB) 和龙运巴士 (Long Win Bus) 的路线信息和到达时间。该服务器支持语言模型查询香港公交服务信息,以解答用户关于公交路线、站点和预计到达时间的问题。

特征

  • 实时公交车到站信息(ETA)

  • 综合公交线路查询

  • 公交车站信息和搜索

  • 路线站点映射

  • 缓存系统优化 API 调用

  • 双语支持(英语和繁体中文)

Related MCP server: Hong Kong Transportation MCP Server

数据源

该项目利用 KMB/LWB 官方开放数据 API:

先决条件

  • Python 3.10 或更高版本

  • uv 包管理器

安装

  1. 首先,如果尚未安装 uv,请安装它:

curl -LsSf https://astral.sh/uv/install.sh | sh
  1. 克隆存储库:

git clone git@github.com:kennyckk/mcp_hkbus.git
cd mcp_hkbus
  1. 使用uv处理python包:

uv sync #using uv.lock

用法

  1. 在您的 MCP 客户端(例如 Claude Desktop)中编辑配置:

{
  "mcpServers": {
    "bus_service": {
      "command": "path/to/uv.exe",
      "args": ["--directory", "path/to/kmb_bus", "run", "kmb_mcp.py"],
      "background": true
    }
  }
}
  1. 服务器提供了几种可供语言模型用来查询公交车信息的工具:

  • get_route_list() :获取所有公交路线列表

  • get_stop_list() :获取所有公交车站列表

  • get_route_stops() :获取特定路线的站点

  • find_stops_by_name() :按名称搜索公交车站

  • get_all_routes_at_stop() :获取服务特定站点的所有路线

  • get_eta() :获取预计到达时间

测试

使用 pytest 运行测试套件:

pytest test/kmb-mcp-tests.py

依赖项

  • httpx :用于异步 HTTP 请求

  • fastmcp :用于 MCP 服务器实现

  • pytest :用于测试(仅限开发)

贡献

欢迎贡献代码!欢迎提交 Pull 请求。

致谢

  • 九巴/龙运巴士提供开放数据API

  • MCP 协议开发者

笔记

此服务依赖于 KMB/LWB 开放数据 API。请注意 API 的速率限制,并在生产环境中实施适当的错误处理。

Available Tools

5 tools
find_buses_to_destinationB

Find bus routes that go to a specified destination.

Args:
    destination: The destination to search for (e.g., "Central", "Mong Kok", "Airport")

Inputs: destination (required). Returns: result

find_stop_by_nameA

Find bus stops matching a name or partial name.

Args:
    stop_name: Full or partial name of the bus stop to search for

Inputs: stop_name (required). Returns: result

get_all_routes_at_stopB

Get all bus routes that pass through a specified bus stop.

Args:
    stop_name: Name of the bus stop

Inputs: stop_name (required). Returns: result

get_next_busB

Get the next arrival time for a specified bus route at a stop.

Args:
    route: The bus route number (e.g., "1A", "6", "960")
    stop_name: The name of the bus stop

Inputs: route (required), stop_name (required). Returns: result

get_route_stops_infoB

Get all stops along a specified bus route.

Args:
    route: The bus route number (e.g., "1A", "6", "960")

Inputs: route (required). Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 5 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose with no overlap: finding buses to destinations, searching stops by name, getting routes at a stop, checking next bus arrivals, and listing stops on a route. The descriptions reinforce these unique functions, making misselection unlikely.

    Naming Consistency5/5

    All tools follow a consistent verb_noun pattern with underscores (e.g., find_buses_to_destination, get_route_stops_info). The naming is uniform and predictable, using clear action verbs like 'find' and 'get' paired with descriptive nouns.

    Tool Count5/5

    With 5 tools, this server is well-scoped for a bus information system. Each tool serves a specific, necessary function in querying routes, stops, and schedules, avoiding bloat while covering core use cases effectively.

    Completeness4/5

    The tool set covers essential bus information queries: route discovery, stop lookup, schedule checking, and route details. A minor gap exists in lacking tools for broader operations like route planning or real-time updates, but agents can work around this with the provided tools.

    Related MCP Connectors

    Related MCP Servers

    Appeared in Searches