Skip to main content
Glama

get-train-route-stations

Retrieve detailed stop information for specific train routes, including stations, arrival/departure times, and duration at each stop between departure and arrival stations.

Instructions

查询特定列车车次在指定区间内的途径车站、到站时间、出发时间及停留时间等详细经停信息。当用户询问某趟具体列车的经停站时使用此接口。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
trainNoYes要查询的实际车次编号 `train_no`,例如 "240000G10336",而非"G1033"。此编号通常可以从 `get-tickets` 的查询结果中获取,或者由用户直接提供。
fromStationTelecodeYes该列车行程的**出发站**的 `station_telecode` (3位字母编码`)。通常来自 `get-tickets` 结果中的 `telecode` 字段,或者通过 `get-station-code-by-name` 得到。
toStationTelecodeYes该列车行程的**到达站**的 `station_telecode` (3位字母编码)。通常来自 `get-tickets` 结果中的 `telecode` 字段,或者通过 `get-station-code-by-name` 得到。
departDateYes列车从 `fromStationTelecode` 指定的车站出发的日期 (格式: yyyy-MM-dd)。如果用户提供的是相对日期,请务必先调用 `get-current-date` 解析。

Implementation Reference

  • The core handler function that implements the tool logic. It makes an API request to 12306.cn for the train's route stations between specified from/to stations on the departure date, handles cookies, parses the response, and returns the list of stations with times.
    async ({
      trainNo: trainNo,
      fromStationTelecode,
      toStationTelecode,
      departDate,
    }) => {
      const queryParams = new URLSearchParams({
        train_no: trainNo,
        from_station_telecode: fromStationTelecode,
        to_station_telecode: toStationTelecode,
        depart_date: departDate,
      });
      const queryUrl = `${API_BASE}/otn/czxx/queryByTrainNo`;
      const cookies = await getCookie(API_BASE);
      if (cookies == null) {
        return {
          content: [{ type: 'text', text: 'Error: get cookie failed. ' }],
        };
      }
      const queryResponse = await make12306Request<RouteQueryResponse>(
        queryUrl,
        queryParams,
        { Cookie: formatCookies(cookies) }
      );
      if (queryResponse == null || queryResponse.data == undefined) {
        return {
          content: [
            { type: 'text', text: 'Error: get train route stations failed. ' },
          ],
        };
      }
      const routeStationsInfo = parseRouteStationsInfo(queryResponse.data.data);
      if (routeStationsInfo.length == 0) {
        return {
          content: [{ type: 'text', text: '未查询到相关车次信息。' }],
        };
      }
      return {
        content: [{ type: 'text', text: JSON.stringify(routeStationsInfo) }],
      };
    }
  • Zod input schema defining the parameters for the tool: trainNo (internal train number), fromStationTelecode, toStationTelecode, and departDate.
    {
      trainNo: z
        .string()
        .describe(
          '要查询的实际车次编号 `train_no`,例如 "240000G10336",而非"G1033"。此编号通常可以从 `get-tickets` 的查询结果中获取,或者由用户直接提供。'
        ),
      fromStationTelecode: z
        .string()
        .describe(
          '该列车行程的**出发站**的 `station_telecode` (3位字母编码`)。通常来自 `get-tickets` 结果中的 `telecode` 字段,或者通过 `get-station-code-by-name` 得到。'
        ),
      toStationTelecode: z
        .string()
        .describe(
          '该列车行程的**到达站**的 `station_telecode` (3位字母编码)。通常来自 `get-tickets` 结果中的 `telecode` 字段,或者通过 `get-station-code-by-name` 得到。'
        ),
      departDate: z
        .string()
        .length(10)
        .describe(
          '列车从 `fromStationTelecode` 指定的车站出发的日期 (格式: yyyy-MM-dd)。如果用户提供的是相对日期,请务必先调用 `get-current-date` 解析。'
        ),
    },
  • src/index.ts:959-1027 (registration)
    Registers the 'get-train-route-stations' tool on the MCP server with name, description, input schema, and handler function.
    server.tool(
      'get-train-route-stations',
      '查询特定列车车次在指定区间内的途径车站、到站时间、出发时间及停留时间等详细经停信息。当用户询问某趟具体列车的经停站时使用此接口。',
      {
        trainNo: z
          .string()
          .describe(
            '要查询的实际车次编号 `train_no`,例如 "240000G10336",而非"G1033"。此编号通常可以从 `get-tickets` 的查询结果中获取,或者由用户直接提供。'
          ),
        fromStationTelecode: z
          .string()
          .describe(
            '该列车行程的**出发站**的 `station_telecode` (3位字母编码`)。通常来自 `get-tickets` 结果中的 `telecode` 字段,或者通过 `get-station-code-by-name` 得到。'
          ),
        toStationTelecode: z
          .string()
          .describe(
            '该列车行程的**到达站**的 `station_telecode` (3位字母编码)。通常来自 `get-tickets` 结果中的 `telecode` 字段,或者通过 `get-station-code-by-name` 得到。'
          ),
        departDate: z
          .string()
          .length(10)
          .describe(
            '列车从 `fromStationTelecode` 指定的车站出发的日期 (格式: yyyy-MM-dd)。如果用户提供的是相对日期,请务必先调用 `get-current-date` 解析。'
          ),
      },
      async ({
        trainNo: trainNo,
        fromStationTelecode,
        toStationTelecode,
        departDate,
      }) => {
        const queryParams = new URLSearchParams({
          train_no: trainNo,
          from_station_telecode: fromStationTelecode,
          to_station_telecode: toStationTelecode,
          depart_date: departDate,
        });
        const queryUrl = `${API_BASE}/otn/czxx/queryByTrainNo`;
        const cookies = await getCookie(API_BASE);
        if (cookies == null) {
          return {
            content: [{ type: 'text', text: 'Error: get cookie failed. ' }],
          };
        }
        const queryResponse = await make12306Request<RouteQueryResponse>(
          queryUrl,
          queryParams,
          { Cookie: formatCookies(cookies) }
        );
        if (queryResponse == null || queryResponse.data == undefined) {
          return {
            content: [
              { type: 'text', text: 'Error: get train route stations failed. ' },
            ],
          };
        }
        const routeStationsInfo = parseRouteStationsInfo(queryResponse.data.data);
        if (routeStationsInfo.length == 0) {
          return {
            content: [{ type: 'text', text: '未查询到相关车次信息。' }],
          };
        }
        return {
          content: [{ type: 'text', text: JSON.stringify(routeStationsInfo) }],
        };
      }
    );
  • Helper function used by the handler to parse raw RouteStationData into user-friendly RouteStationInfo, handling the first station specially (using start_time as arrive_time).
    function parseRouteStationsInfo(
      routeStationsData: RouteStationData[]
    ): RouteStationInfo[] {
      const result: RouteStationInfo[] = [];
      routeStationsData.forEach((routeStationData, index) => {
        if (index == 0) {
          result.push({
            arrive_time: routeStationData.start_time,
            station_name: routeStationData.station_name,
            stopover_time: routeStationData.stopover_time,
            station_no: parseInt(routeStationData.station_no),
          });
        } else {
          result.push({
            arrive_time: routeStationData.arrive_time,
            station_name: routeStationData.station_name,
            stopover_time: routeStationData.stopover_time,
            station_no: parseInt(routeStationData.station_no),
          });
        }
      });
      return result;
    }
  • TypeScript type definition for the output RouteStationInfo used in the tool's response.
    export type RouteStationInfo = {
      arrive_time: string;
      station_name: string;
      stopover_time: string;
      station_no: number;
    };
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 clearly describes what the tool returns (stop stations, arrival/departure times, dwell times) but doesn't mention error conditions, rate limits, authentication needs, or response format. For a query tool with no annotation coverage, this provides basic behavioral information but lacks operational details.

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?

Two well-structured sentences with zero waste. First sentence defines the tool's purpose and scope, second sentence provides clear usage guidance. Every word earns its place with no redundancy or unnecessary elaboration.

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?

For a query tool with 4 required parameters, 100% schema coverage, but no annotations and no output schema, the description provides adequate purpose and usage context. However, it doesn't describe the return format or structure, which would be helpful given the absence of an output schema. The description is complete enough for basic understanding but lacks output details.

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 all 4 parameters. The description doesn't add any parameter-specific information beyond what's in the schema descriptions. Baseline 3 is appropriate when the schema does all the parameter documentation work.

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 verb ('查询' - query) and resource ('特定列车车次在指定区间内的途径车站、到站时间、出发时间及停留时间等详细经停信息' - detailed stop information for specific train routes). It distinguishes from siblings by specifying it's for '具体列车的经停站' (specific train stop stations), unlike general ticket or station lookup tools.

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?

Explicitly states '当用户询问某趟具体列车的经停站时使用此接口' (use this interface when users ask about specific train stop stations), providing clear when-to-use guidance. It distinguishes from alternatives by specifying it's for detailed stop information rather than ticket availability or station codes.

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