Skip to main content
Glama

get-station-code-of-citys

Convert Chinese city names to station codes for railway ticket queries. Use this tool to prepare station_code parameters when searching for train tickets with city names as departure or destination points.

Instructions

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

Input Schema

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

Implementation Reference

  • The handler function that processes the input 'citys' string (cities separated by '|'), queries the precomputed CITY_CODES map for each city, and returns a JSON object with station codes or errors.
    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 schema defining the input parameter 'citys' as a string describing cities, supporting multiple via '|' separator.
    {
      citys: z
        .string()
        .describe(
          '要查询的城市,比如"北京"。若要查询多个城市,请用|分割,比如"北京|上海"。'
        ),
    },
  • src/index.ts:609-632 (registration)
    Full registration of the tool using McpServer.tool(), including name, description, input schema, and inline 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) }],
        };
      }
    );
  • Helper constant CITY_CODES that maps Chinese city names to their representative station's code and name, built from CITY_STATIONS by finding the station whose name matches the city.
    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. It describes the basic query functionality but lacks behavioral details such as error handling (e.g., what happens with invalid city names), rate limits, authentication requirements, or response format. For a tool with no annotation coverage, this leaves significant gaps in understanding how it behaves beyond the core purpose.

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 states the purpose, and the second provides usage context. Every sentence adds value without redundancy, making it easy to understand quickly.

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 no annotations and no output schema, the description covers the purpose and usage adequately but lacks details on behavior, error handling, and output format. For a simple query tool with one parameter, it's minimally viable but could be more complete by addressing missing behavioral aspects.

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 parameter 'citys' fully documented in the schema (including format for single/multiple cities). The description doesn't add any parameter-specific information beyond what's in the schema, so it meets the baseline of 3 where the schema does the heavy lifting.

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 the 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 usage context: '此接口主要用于在用户提供城市名作为出发地或到达地时,为接口准备 station_code 参数' (this interface is mainly used when users provide city names as departure or arrival locations to prepare station_code parameters for other interfaces). This indicates when to use it (for city-to-code mapping in travel contexts) but doesn't explicitly mention when not to use it or name specific 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/freestylefly/12306-mcp'

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