Skip to main content
Glama

get-station-code-by-names

Find station codes for Chinese railway stations by entering 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

  • The handler function processes one or more Chinese station names (split by '|'), optionally strips trailing '站', looks them up in the NAME_STATIONS dictionary, and returns a JSON object with station codes or error messages.
    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' as a string parameter with description for querying station codes by Chinese names.
    {
      stationNames: z
        .string()
        .describe(
          '具体的中文车站名称,例如:"北京南", "上海虹桥"。若要查询多个站点,请用|分割,比如"北京南|上海虹桥"。'
        ),
    },
  • src/index.ts:634-660 (registration)
    Registers the 'get-station-code-by-names' tool on the MCP server, including name, description, input schema, and 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) }],
        };
      }
    );
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool is for querying ('查询'), implying a read-only operation, and mentions its primary use case for preparing parameters. However, it lacks details on error handling, rate limits, authentication needs, or what happens with invalid inputs, leaving gaps in behavioral context.

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 with two sentences that are front-loaded and efficient. The first sentence states the core purpose, and the second adds usage context without redundancy. Every sentence earns its place by contributing essential information.

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 (1 parameter, no output schema, no annotations), the description is somewhat complete but has gaps. It explains the purpose and usage context adequately, but without annotations or output schema, it should ideally provide more behavioral details (e.g., response format, error cases) to fully compensate for the lack of structured data.

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'. The description adds minimal value beyond the schema by reinforcing that it accepts Chinese station names and is for preparing parameters, but does not provide additional syntax, format details, or examples beyond what the schema specifies.

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 with specific verbs ('查询' - query) and resources ('station_code' and station name), explicitly distinguishing it from sibling tools by focusing on querying by Chinese station names rather than telecodes, cities, or other parameters. It directly addresses what the tool does without tautology.

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 station names as departure or arrival points), but does not explicitly mention when not to use it or name specific alternatives among the sibling tools. The guidance is helpful but lacks explicit exclusions.

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

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