Skip to main content
Glama

get-stations-code-in-city

Find all railway stations and their codes in a Chinese city to simplify ticket booking and travel planning on 12306.

Instructions

通过中文城市名查询该城市 所有 火车站的名称及其对应的 station_code,结果是一个包含多个车站信息的列表。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYes中文城市名称,例如:"北京", "上海"

Implementation Reference

  • Handler function that retrieves all stations in the given city from precomputed CITY_STATIONS data and returns them as a JSON string in the response content, or an error if the city is not found.
    async ({ city }) => {
        if (!(city in CITY_STATIONS)) {
            return {
                content: [{ type: 'text', text: 'Error: City not found. ' }],
            };
        }
        return {
            content: [
                { type: 'text', text: JSON.stringify(CITY_STATIONS[city]) },
            ],
        };
    }
  • Input schema defined using Zod, specifying a required 'city' parameter as a string with description.
    {
        city: z.string().describe('中文城市名称,例如:"北京", "上海"'),
    },
  • src/index.ts:841-859 (registration)
    Registration of the tool using McpServer's server.tool() method, providing name, description, input schema, and handler.
    server.tool(
        'get-stations-code-in-city',
        '通过中文城市名查询该城市 **所有** 火车站的名称及其对应的 `station_code`,结果是一个包含多个车站信息的列表。',
        {
            city: z.string().describe('中文城市名称,例如:"北京", "上海"'),
        },
        async ({ city }) => {
            if (!(city in CITY_STATIONS)) {
                return {
                    content: [{ type: 'text', text: 'Error: City not found. ' }],
                };
            }
            return {
                content: [
                    { type: 'text', text: JSON.stringify(CITY_STATIONS[city]) },
                ],
            };
        }
    );
  • Precomputed CITY_STATIONS map from city name to list of stations in that city ({station_code, station_name}), derived from global STATIONS data loaded earlier.
    const CITY_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 city = station.city;
            if (!result[city]) {
                result[city] = [];
            }
            result[city].push({
                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 full burden. It discloses the query behavior and output format (list of stations with names and codes), but doesn't mention potential limitations like rate limits, error conditions (e.g., invalid city names), authentication requirements, or whether the data is cached/live. For a read-only query tool with zero annotation coverage, this leaves significant behavioral gaps.

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 a single, well-structured sentence that efficiently conveys purpose, input requirement, and output format without unnecessary words. It's front-loaded with the core functionality and every element serves a clear informational purpose.

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, read-only query), 100% schema coverage, and no output schema, the description is adequate but not complete. It covers the basic operation but lacks details on error handling, data freshness, or example outputs that would help an agent use it correctly. The absence of annotations means more behavioral context would be beneficial.

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

Parameters4/5

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

Schema description coverage is 100% (the single parameter 'city' has a clear description in the schema), so baseline is 3. The description adds value by emphasizing the parameter must be a '中文城市名' (Chinese city name) and providing context that this is what drives the query for '所有' (all) stations. This enhances understanding beyond the schema's technical specification.

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's purpose: '通过中文城市名查询该城市所有火车站的名称及其对应的station_code' (Query all train stations in a Chinese city by city name, returning station names and their station_code). It specifies the verb ('查询' - query), resource ('火车站' - train stations), scope ('所有' - all), and output format ('包含多个车站信息的列表' - list containing multiple station information). This distinguishes it from sibling tools like get-station-by-telecode or get-station-code-by-names.

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

Usage Guidelines3/5

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

The description implies usage context by specifying '通过中文城市名' (by Chinese city name) and that it returns '所有' (all) stations, but doesn't explicitly state when to use this tool versus alternatives like get-station-code-of-citys (which appears similar based on name) or get-station-code-by-names. It provides basic input requirements but no explicit guidance on tool selection 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