Skip to main content
Glama

get-station-code-of-citys

Retrieve railway station codes for Chinese cities by name. Use this to convert city names to station codes required for 12306 ticket search queries.

Instructions

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

Input Schema

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

Implementation Reference

  • The handler function for the 'get-station-code-of-citys' tool. It accepts a 'citys' string (pipe-separated city names), looks up each city in the CITY_CODES map, and returns the station_code for each city. If a city is not found, it returns an error.
    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) }],
        };
    }
  • The input schema for the 'get-station-code-of-citys' tool, defining the 'citys' parameter as a Zod string with a description about pipe-separated city names.
    {
        citys: z
            .string()
            .describe(
                '要查询的城市,比如"北京"。若要查询多个城市,请用|分割,比如"北京|上海"。'
            ),
    },
  • src/index.ts:876-899 (registration)
    The registration of the 'get-station-code-of-citys' tool using server.tool(), with its name, description, schema, and handler.
    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) }],
            };
        }
    );
  • The CITY_CODES constant - an IIFE that builds a map from city name to the station that shares the city's name (e.g., '北京' -> { station_code: 'BJP', station_name: '北京' }). This is the data source used by the handler.
    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 must carry the full burden. It does not disclose behavioral traits such as return format, error handling, or effects. The tool can query multiple cities but the description does not explain the response structure (e.g., if it returns a list or mapping). This lack of detail harms 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 composed of two concise sentences that convey the core functionality and usage context. It is front-loaded and contains no unnecessary words, achieving high efficiency.

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?

With no output schema, the description does not explain return values, which is a gap. The tool has one required parameter and is relatively simple, so the description covers the essential context but lacks details on output format and error conditions. It is adequate but not fully complete.

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% coverage with a clear description of the 'citys' parameter, including format and examples. The description adds little beyond the schema, only reiterating the purpose. The baseline is 3, and while the description provides context, it does not significantly enhance parameter understanding.

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

Purpose5/5

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

The description clearly states the tool queries `station_code` by Chinese city name, using the verb 'query'. It specifies the resource (station_code) and differentiates from siblings by mentioning multiple cities via pipe. The title, though misspelled, does not detract.

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 explicitly states when to use: when the user provides a city name as departure or arrival. It implies the context for preparing the station_code parameter but does not explicitly mention alternatives or when not to use it, which is acceptable given sibling tool names suggest different criteria.

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