Skip to main content
Glama

get-station-by-telecode

Retrieve detailed station information, including name, pinyin, and city, using the 3-letter station telecode. Ideal for debugging or accessing complete station data when the telecode is known.

Instructions

通过车站的 station_telecode 查询车站的详细信息,包括名称、拼音、所属城市等。此接口主要用于在已知 telecode 的情况下获取更完整的车站数据,或用于特殊查询及调试目的。一般用户对话流程中较少直接触发。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
stationTelecodeYes车站的 `station_telecode` (3位字母编码)

Implementation Reference

  • The core handler function for the 'get-station-by-telecode' tool. It takes stationTelecode as input, checks if it exists in the global STATIONS map (a Record<string, StationData>), and returns the JSON-stringified station details or an error message if not found.
    async ({ stationTelecode }) => { if (!STATIONS[stationTelecode]) { return { content: [{ type: 'text', text: 'Error: Station not found. ' }], }; } return { content: [ { type: 'text', text: JSON.stringify(STATIONS[stationTelecode]), }, ], }; } );
  • The Zod input schema for the tool, defining a single required string parameter 'stationTelecode' with description.
    { stationTelecode: z .string() .describe('车站的 `station_telecode` (3位字母编码)'), },
  • src/index.ts:914-937 (registration)
    The full registration of the 'get-station-by-telecode' tool on the MCP server using server.tool(name, description, schema, handler). Includes the tool name, Chinese description, input schema, and inline handler function.
    server.tool( 'get-station-by-telecode', '通过车站的 `station_telecode` 查询车站的详细信息,包括名称、拼音、所属城市等。此接口主要用于在已知 `telecode` 的情况下获取更完整的车站数据,或用于特殊查询及调试目的。一般用户对话流程中较少直接触发。', { stationTelecode: z .string() .describe('车站的 `station_telecode` (3位字母编码)'), }, async ({ stationTelecode }) => { if (!STATIONS[stationTelecode]) { return { content: [{ type: 'text', text: 'Error: Station not found. ' }], }; } return { content: [ { type: 'text', text: JSON.stringify(STATIONS[stationTelecode]), }, ], }; } );
  • Global STATIONS map populated asynchronously from getStations(), used by the tool handler to lookup station data by telecode (station_code).
    const STATIONS: Record<string, StationData> = await getStations(); //以Code为键
  • Helper function getStations() that fetches, parses, and returns the full stations data from 12306 website, used to populate the STATIONS map for lookups.
    async function getStations(): Promise<Record<string, StationData>> { const html = await make12306Request<string>(WEB_URL); if (html == null) { throw new Error('Error: get 12306 web page failed.'); } const match = html.match('.(/script/core/common/station_name.+?.js)'); if (match == null) { throw new Error('Error: get station name js file failed.'); } const stationNameJSFilePath = match[0]; const stationNameJS = await make12306Request<string>( new URL(stationNameJSFilePath, WEB_URL) ); if (stationNameJS == null) { throw new Error('Error: get station name js file failed.'); } const rawData = eval(stationNameJS.replace('var station_names =', '')); const stationsData = parseStationsData(rawData); // 加上缺失的车站信息 for (const station of MISSING_STATIONS) { if (!stationsData[station.station_code]) { stationsData[station.station_code] = station; } } return stationsData; }

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/Joooook/12306-mcp'

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