Skip to main content
Glama

get-stations-code-in-city

Find all railway stations and their codes in a Chinese city to identify departure or arrival points for train travel planning.

Instructions

通过中文城市名查询该城市 所有 火车站的名称及其对应的 station_code,结果是一个包含多个车站信息的列表。当用户想了解一个城市有哪些火车站,或者不确定具体从哪个车站出发/到达时可以使用此接口。

Input Schema

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

Implementation Reference

  • The core handler function for the 'get-stations-code-in-city' tool. It validates the city exists in CITY_STATIONS map and returns a JSON string of the city's stations with their codes and names, or an error message.
    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]) }],
      };
    }
  • src/index.ts:591-607 (registration)
    The server.tool registration call that defines the tool name, description, input schema (city: string), and inline handler function.
    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]) }],
        };
      }
    );
  • Zod schema for the input parameter 'city', a required string describing the Chinese city name.
    city: z.string().describe('中文城市名称,例如:"北京", "上海"'),
  • Helper constant CITY_STATIONS: Maps Chinese city names to arrays of {station_code, station_name} for all stations in that city, built dynamically from the STATIONS data.
    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列表的记录
  • Helper function getStations() that fetches and parses all station data from 12306 website, used to populate STATIONS which feeds into CITY_STATIONS.
    async function getStations(): Promise<Record<string, StationData>> {
      const html = await make12306Request<string>(WEB_URL);
      if (html == null) {
        throw new Error('Error: get 12306 web page failed.');
      }
      const match = html.match('.(/script/core/common/station_name.+?.js)');
      if (match == null) {
        throw new Error('Error: get station name js file failed.');
      }
      const stationNameJSFilePath = match[0];
      const stationNameJS = await make12306Request<string>(
        new URL(stationNameJSFilePath, WEB_URL)
      );
      if (stationNameJS == null) {
        throw new Error('Error: get station name js file failed.');
      }
      const rawData = eval(stationNameJS.replace('var station_names =', ''));
      const stationsData = parseStationsData(rawData);
      // 加上缺失的车站信息
      for (const station of MISSING_STATIONS) {
        if (!stationsData[station.station_code]) {
          stationsData[station.station_code] = station;
        }
      }
      return stationsData;
    }
Behavior3/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 output format ('结果是一个包含多个车站信息的列表' - result is a list containing multiple station information) and scope ('所有' - all stations), but lacks details on error handling, rate limits, authentication needs, or whether the query is case-sensitive for Chinese city names. It adequately describes core behavior but misses operational nuances.

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 efficiently structured in two sentences: the first explains what the tool does and its output, the second provides usage guidelines. Every sentence adds value without redundancy, and it's appropriately sized for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/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 annotations, no output schema), the description is mostly complete: it covers purpose, usage, output format, and parameter context. However, it lacks details on error cases (e.g., invalid city names) and exact return structure, which would be helpful since there's no output schema. It's sufficient but has minor gaps.

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%, so the baseline is 3. The description adds value by emphasizing the parameter must be a '中文城市名' (Chinese city name) and providing context that it's used to query '所有' (all) stations, which clarifies the parameter's role beyond the schema's basic type and example. However, it doesn't add syntax or format details beyond what the schema provides.

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 specific action ('查询' - query) and resource ('火车站的名称及其对应的 station_code'), explicitly distinguishes scope ('所有' - all stations in the city), and differentiates from siblings like 'get-station-by-telecode' (which uses telecode) and 'get-station-code-by-names' (which uses station names).

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

Usage Guidelines5/5

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

The description explicitly states when to use this tool ('当用户想了解一个城市有哪些火车站,或者不确定具体从哪个车站出发/到达时' - when users want to know which stations a city has or are unsure about departure/arrival stations), providing clear context for its application without needing to mention specific alternatives since the sibling tools serve different purposes.

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