Skip to main content
Glama

get-stations-code-in-city

Retrieve all railway stations and their codes within a specified Chinese city using a Chinese city name. Outputs a list of station details for easy reference.

Instructions

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

Input Schema

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

Implementation Reference

  • Handler function that takes a Chinese city name, checks if the city exists in the precomputed CITY_STATIONS map, and returns a JSON string of all stations in that city with their names and codes, or an error message if 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]) }, ], }; }
  • Zod input schema defining the 'city' parameter as a required string representing the Chinese city name.
    { city: z.string().describe('中文城市名称,例如:"北京", "上海"'), },
  • src/index.ts:841-859 (registration)
    MCP server.tool registration call that defines the tool name, description, input schema, and 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]) }, ], }; } );
  • Precomputed constant mapping Chinese city names to arrays of station objects containing station_code and station_name, built from the global STATIONS data. This is the core data source used by the tool handler.
    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列表的记录

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