Skip to main content
Glama

get-station-code-of-citys

Retrieve the station code for one or multiple Chinese cities by entering their names. This tool prepares the required station_code parameter for APIs when users specify cities as departure or arrival points.

Instructions

通过中文城市名查询代表该城市的 station_code。此接口主要用于在用户提供城市名作为出发地或到达地时,为接口准备 station_code 参数。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
citysYes要查询的城市,比如"北京"。若要查询多个城市,请用|分割,比如"北京|上海"。

Implementation Reference

  • The main handler function that processes one or more city names (separated by '|'), checks CITY_CODES map for representative station code, compiles results or errors into a JSON object, and returns it as tool response content.
    async ({ citys }) => { let result: Record<string, object> = {}; for (const city of citys.split('|')) { if (!(city in CITY_CODES)) { result[city] = { error: '未检索到城市。' }; } else { result[city] = CITY_CODES[city]; } } return { content: [{ type: 'text', text: JSON.stringify(result) }], }; }
  • Zod input schema defining the 'citys' parameter as a string supporting multiple cities separated by '|'.
    citys: z .string() .describe( '要查询的城市,比如"北京"。若要查询多个城市,请用|分割,比如"北京|上海"。' ), },
  • src/index.ts:609-632 (registration)
    The McpServer.tool registration call defining the tool name, description, input schema, and inline handler function.
    server.tool( 'get-station-code-of-citys', '通过中文城市名查询代表该城市的 `station_code`。此接口主要用于在用户提供**城市名**作为出发地或到达地时,为接口准备 `station_code` 参数。', { citys: z .string() .describe( '要查询的城市,比如"北京"。若要查询多个城市,请用|分割,比如"北京|上海"。' ), }, async ({ citys }) => { let result: Record<string, object> = {}; for (const city of citys.split('|')) { if (!(city in CITY_CODES)) { result[city] = { error: '未检索到城市。' }; } else { result[city] = CITY_CODES[city]; } } return { content: [{ type: 'text', text: JSON.stringify(result) }], }; } );
  • Supporting constant CITY_CODES mapping each city name to its primary station (where station_name matches city), derived from CITY_STATIONS. This is the key data structure queried by the handler.
    const CITY_CODES: Record< string, { station_code: string; station_name: string } > = (() => { const result: Record<string, { station_code: string; station_name: string }> = {}; for (const [city, stations] of Object.entries(CITY_STATIONS)) { for (const station of stations) { if (station.station_name == city) { result[city] = station; break; } } } return result; })(); //以城市名名为键的Station记录

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/freestylefly/12306-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server