Skip to main content
Glama

get-station-code-of-citys

Find station codes for Chinese cities to prepare departure or destination parameters for 12306 ticket booking interfaces.

Instructions

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

Input Schema

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

Implementation Reference

  • The core handler function that processes input city names (separated by '|'), queries the CITY_CODES map for representative station codes, returns error for unknown cities, and formats the result as JSON text 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-based input schema defining the 'citys' parameter as a string supporting multiple cities separated by '|'.
    {
        citys: z
            .string()
            .describe(
                '要查询的城市,比如"北京"。若要查询多个城市,请用|分割,比如"北京|上海"。'
            ),
    },
  • src/index.ts:861-884 (registration)
    Full MCP server.tool registration including name, description, input schema using Zod, and the async 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 city names to representative stations (where station_name equals city name), built from CITY_STATIONS data.
    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记录
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 of behavioral disclosure. While it mentions the tool is for querying and preparing parameters, it doesn't describe important behavioral aspects such as error handling (e.g., what happens if a city name is invalid), response format, rate limits, authentication requirements, or whether it's a read-only operation. The description is functional but lacks operational 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 concise and well-structured in two sentences. The first sentence states the core purpose, and the second provides usage context. There is no wasted language, and information is front-loaded appropriately for quick understanding.

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 low complexity (single parameter, no nested objects) and high schema coverage, the description is somewhat complete for basic use. However, with no annotations and no output schema, it lacks details on behavioral traits and return values, which are important for a query tool. The description covers purpose and usage but misses operational context, making it adequate but with clear gaps.

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?

The input schema has 100% description coverage, with the 'citys' parameter fully documented in the schema (including format for single and multiple cities). The description adds no additional parameter semantics beyond what's in the schema—it doesn't explain the parameter's role, constraints, or examples further. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but also doesn't need to.

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: '通过中文城市名查询代表该城市的 station_code' (query station_code representing a city via Chinese city name). It specifies the verb '查询' (query) and resource 'station_code', and mentions the context of departure/arrival locations. However, it doesn't explicitly differentiate from sibling tools like 'get-station-code-by-names' or 'get-stations-code-in-city', which appear related.

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: '在用户提供城市名作为出发地或到达地时,为接口准备 station_code 参数' (when users provide city names as departure/arrival locations, to prepare station_code parameters for interfaces). This gives practical guidance on its intended use case. However, it doesn't explicitly state when NOT to use it or mention alternatives among the sibling tools.

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