get-station-code-by-names
Retrieve station codes from Chinese station names to prepare parameters for ticket API queries. Input one or multiple station names separated by |.
Instructions
通过具体的中文车站名查询其 station_code 和车站名。此接口主要用于在用户提供具体车站名作为出发地或到达地时,为接口准备 station_code 参数。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| stationNames | Yes | 具体的中文车站名称,例如:"北京南", "上海虹桥"。若要查询多个站点,请用|分割,比如"北京南|上海虹桥"。 |
Implementation Reference
- src/index.ts:896-911 (handler)The handler function that processes the input station names, normalizes them by removing trailing '站', looks up in NAME_STATIONS map, and returns JSON of station_code and station_name or error.async ({ stationNames }) => { let result: Record<string, object> = {}; for (let stationName of stationNames.split('|')) { stationName = stationName.endsWith('站') ? stationName.substring(0, -1) : stationName; if (!(stationName in NAME_STATIONS)) { result[stationName] = { error: '未检索到城市。' }; } else { result[stationName] = NAME_STATIONS[stationName]; } } return { content: [{ type: 'text', text: JSON.stringify(result) }], }; }
- src/index.ts:889-895 (schema)Zod schema defining the input parameter 'stationNames' as a string that can contain multiple station names separated by '|'.{ stationNames: z .string() .describe( '具体的中文车站名称,例如:"北京南", "上海虹桥"。若要查询多个站点,请用|分割,比如"北京南|上海虹桥"。' ), },
- src/index.ts:886-912 (registration)The server.tool registration that registers the tool with name, description, schema, and handler function.server.tool( 'get-station-code-by-names', '通过具体的中文车站名查询其 `station_code` 和车站名。此接口主要用于在用户提供**具体车站名**作为出发地或到达地时,为接口准备 `station_code` 参数。', { stationNames: z .string() .describe( '具体的中文车站名称,例如:"北京南", "上海虹桥"。若要查询多个站点,请用|分割,比如"北京南|上海虹桥"。' ), }, async ({ stationNames }) => { let result: Record<string, object> = {}; for (let stationName of stationNames.split('|')) { stationName = stationName.endsWith('站') ? stationName.substring(0, -1) : stationName; if (!(stationName in NAME_STATIONS)) { result[stationName] = { error: '未检索到城市。' }; } else { result[stationName] = NAME_STATIONS[stationName]; } } return { content: [{ type: 'text', text: JSON.stringify(result) }], }; } );
- src/index.ts:88-104 (helper)The NAME_STATIONS constant, a map from station_name to {station_code, station_name}, built from the global STATIONS data. Used by the handler for lookups.const NAME_STATIONS: Record< string, { station_code: string; station_name: string } > = (() => { const result: Record< string, { station_code: string; station_name: string } > = {}; for (const station of Object.values(STATIONS)) { const station_name = station.station_name; result[station_name] = { station_code: station.station_code, station_name: station.station_name, }; } return result; })(); //以车站名为键的Station记录