searchTrainStations
Find train stations by entering a keyword, such as '北京西', to quickly locate relevant station information for planning trips or transfers.
Instructions
Search for train stations by keyword.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Keyword to search for train stations (e.g. 北京西) |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"query": {
"description": "Keyword to search for train stations (e.g. 北京西)",
"type": "string"
}
},
"required": [
"query"
],
"type": "object"
}
Implementation Reference
- dist/index.js:273-291 (handler)The MCP tool handler function for 'searchTrainStations' that invokes the service method and handles response/error formatting.}, async ({ query }) => { try { const trainStations = await flightService.searchTrainStations(query); return { content: [ { type: "text", text: JSON.stringify(trainStations, null, 2) } ] }; } catch (error) { console.error('Error searching train stations:', error); return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; }
- dist/index.js:272-272 (schema)Zod input schema defining the 'query' parameter as a string for the searchTrainStations tool.query: z.string().describe("Keyword to search for train stations (e.g. 北京西)"),
- dist/index.js:271-292 (registration)Registration of the 'searchTrainStations' MCP tool with server.tool, including name, description, schema, and handler.server.tool("searchTrainStations", "Search for train stations by keyword.", { query: z.string().describe("Keyword to search for train stations (e.g. 北京西)"), }, async ({ query }) => { try { const trainStations = await flightService.searchTrainStations(query); return { content: [ { type: "text", text: JSON.stringify(trainStations, null, 2) } ] }; } catch (error) { console.error('Error searching train stations:', error); return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; } });
- dist/services/openalService.js:87-91 (helper)Helper method in OpenAlService class that performs the actual API request for searching train stations.async searchTrainStations(query) { return this.makeRequest('searchTrainStations', { query }); }
- dist/services/openalService.js:3-21 (helper)Core helper method in OpenAlService for making POST requests to the backend API endpoints, used by searchTrainStations.async makeRequest(endpoint, params) { const url = new URL(config.api.baseUrl); const request_body = { endpoint: endpoint, params: params }; const response = await fetch(url.toString(), { method: 'post', headers: { 'X-VARIFLIGHT-KEY': config.api.apiKey || '', 'Content-Type': 'application/json', }, body: JSON.stringify(request_body), }); if (!response.ok) { throw new Error(`API request failed: ${response.status} ${response.statusText}`); } return response.json(); }