Skip to main content
Glama

get-station-code-of-citys

Convert Chinese city names to station codes for railway ticket queries. Use this tool to prepare station_code parameters when searching for train tickets with city names as departure or destination points.

Instructions

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

Input Schema

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

Implementation Reference

  • The handler function that processes the input 'citys' string (cities separated by '|'), queries the precomputed CITY_CODES map for each city, and returns a JSON object with station codes or errors.
    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 schema defining the input parameter 'citys' as a string describing cities, supporting multiple via '|' separator.
    { citys: z .string() .describe( '要查询的城市,比如"北京"。若要查询多个城市,请用|分割,比如"北京|上海"。' ), },
  • src/index.ts:609-632 (registration)
    Full registration of the tool using McpServer.tool(), including 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) }], }; } );
  • Helper constant CITY_CODES that maps Chinese city names to their representative station's code and name, built from CITY_STATIONS by finding the station whose name matches the city.
    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