Skip to main content
Glama

get-station-code-by-names

Find station codes for Chinese railway stations by providing their Chinese names. Use this tool to get the required station_code parameter when booking tickets through 12306.

Instructions

通过具体的中文车站名查询其 station_code 和车站名。此接口主要用于在用户提供具体车站名作为出发地或到达地时,为接口准备 station_code 参数。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
stationNamesYes具体的中文车站名称,例如:"北京南", "上海虹桥"。若要查询多个站点,请用|分割,比如"北京南|上海虹桥"。

Implementation Reference

  • Inline async handler function for the 'get-station-code-by-names' tool. It processes multiple station names separated by '|', optionally strips trailing '站', looks up in NAME_STATIONS map, and returns JSON results 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) }],
        };
    }
  • Zod input schema defining 'stationNames' parameter as a string supporting multiple names separated by '|'.
    {
        stationNames: z
            .string()
            .describe(
                '具体的中文车站名称,例如:"北京南", "上海虹桥"。若要查询多个站点,请用|分割,比如"北京南|上海虹桥"。'
            ),
    },
  • src/index.ts:886-912 (registration)
    Registration of the tool using server.tool(), including name, description, schema, and inline 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) }],
            };
        }
    );
  • Constant NAME_STATIONS map generated from STATIONS data, mapping station names to {station_code, station_name}, used by the tool handler.
    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记录
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It describes the tool's function but lacks behavioral details like whether it's read-only (implied by '查询' but not explicit), error handling, rate limits, authentication needs, or response format. For a tool with no annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, with two concise sentences that directly convey purpose and usage without wasted words. Every sentence earns its place by providing essential information efficiently.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (single parameter, no output schema, no annotations), the description covers basic purpose and usage but lacks details on behavioral aspects and output. It's adequate as a minimum viable description but has clear gaps in transparency and completeness for a tool with no structured support.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already fully documents the single parameter 'stationNames' with examples and format details. The description adds no additional parameter information beyond what's in the schema, maintaining the baseline score of 3 for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: querying station codes and names using Chinese station names. It specifies the verb '查询' (query) and resource 'station_code' and station names. However, it doesn't explicitly differentiate from sibling tools like 'get-station-by-telecode' or 'get-station-code-of-citys', which likely serve similar but distinct purposes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool: when users provide specific Chinese station names as departure or arrival locations to prepare the 'station_code' parameter for other interfaces. It mentions the specific use case but doesn't explicitly state when NOT to use it or name alternatives among siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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