Skip to main content
Glama
KallivdH

NS Travel Information Server

by KallivdH

get_prices

Retrieve domestic train journey pricing with options for travel classes, ticket types, discounts, and passenger counts. Provides detailed fare information including conditions and validity.

Instructions

Get price information for domestic train journeys, including different travel classes, ticket types, and discounts. Returns detailed pricing information with conditions and validity.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fromStationYesUicCode or station code of the origin station
toStationYesUicCode or station code of the destination station
travelClassNoTravel class to return the price for
travelTypeNoReturn the price for a single or return tripsingle
isJointJourneyNoSet to true to return the price including joint journey discount
adultsNoNumber of adults to return the price for
childrenNoNumber of children to return the price for
routeIdNoSpecific identifier for the route to take between the two stations. This routeId is returned in the /api/v3/trips call.
plannedDepartureTimeNoFormat - date-time (as date-time in RFC3339). Used to find the correct route if multiple routes are possible.
plannedArrivalTimeNoFormat - date-time (as date-time in RFC3339). Used to find the correct route if multiple routes are possible.

Implementation Reference

  • Core handler function that executes the get_prices tool logic by calling the NS API prices endpoint with axios and returning the response data.
    async getPrices(args: GetPricesArgs): Promise<PricesResponse> { this.ensureApiKeyConfigured(); const response = await this.axiosInstance.get<PricesResponse>( NSApiService.ENDPOINTS.PRICES, { params: { fromStation: args.fromStation, toStation: args.toStation, travelClass: args.travelClass, travelType: args.travelType, isJointJourney: args.isJointJourney, adults: args.adults, children: args.children, routeId: args.routeId, plannedDepartureTime: args.plannedDepartureTime, plannedArrivalTime: args.plannedArrivalTime }, } ); return response.data; }
  • Type definitions for GetPricesArgs input interface, PricesResponse output, and isValidPricesArgs type guard for input validation.
    export interface PricesResponse { payload: { prices: Price[]; }; } export interface GetPricesArgs { fromStation?: string; toStation?: string; travelClass?: 'FIRST_CLASS' | 'SECOND_CLASS'; travelType?: 'single' | 'return'; isJointJourney?: boolean; adults?: number; children?: number; routeId?: string; plannedDepartureTime?: string; plannedArrivalTime?: string; } export function isValidPricesArgs(args: unknown): args is GetPricesArgs { if (!args || typeof args !== "object") { return false; } const typedArgs = args as Record<string, unknown>; // Check station fields: should be undefined or string if (typedArgs.fromStation !== undefined && typeof typedArgs.fromStation !== "string") { return false; } if (typedArgs.toStation !== undefined && typeof typedArgs.toStation !== "string") { return false; } // Check travelClass: should be undefined or one of the allowed values if (typedArgs.travelClass !== undefined && !["FIRST_CLASS", "SECOND_CLASS"].includes(typedArgs.travelClass as string)) { return false; } // Check travelType: should be undefined or one of the allowed values if (typedArgs.travelType !== undefined && !["single", "return"].includes(typedArgs.travelType as string)) { return false; } // Check isJointJourney: should be undefined or boolean if (typedArgs.isJointJourney !== undefined && typeof typedArgs.isJointJourney !== "boolean") { return false; } // Check adults: should be undefined or integer if (typedArgs.adults !== undefined && (typeof typedArgs.adults !== "number" || !Number.isInteger(typedArgs.adults))) { return false; } // Check children: should be undefined or integer if (typedArgs.children !== undefined && (typeof typedArgs.children !== "number" || !Number.isInteger(typedArgs.children))) { return false; } // Check routeId: should be undefined or string if (typedArgs.routeId !== undefined && typeof typedArgs.routeId !== "string") { return false; } // Check time fields: should be undefined or string if (typedArgs.plannedDepartureTime !== undefined && typeof typedArgs.plannedDepartureTime !== "string") { return false; } if (typedArgs.plannedArrivalTime !== undefined && typeof typedArgs.plannedArrivalTime !== "string") { return false; } return true; }
  • src/index.ts:222-277 (registration)
    Tool registration in listTools handler for the stdio MCP server, defining name, description, and inputSchema for get_prices.
    name: 'get_prices', description: 'Get price information for domestic train journeys, including different travel classes, ticket types, and discounts. Returns detailed pricing information with conditions and validity.', inputSchema: { type: 'object', properties: { fromStation: { type: 'string', description: 'UicCode or station code of the origin station', }, toStation: { type: 'string', description: 'UicCode or station code of the destination station', }, travelClass: { type: 'string', description: 'Travel class to return the price for', enum: ['FIRST_CLASS', 'SECOND_CLASS'] }, travelType: { type: 'string', description: 'Return the price for a single or return trip', enum: ['single', 'return'], default: 'single' }, isJointJourney: { type: 'boolean', description: 'Set to true to return the price including joint journey discount', default: false }, adults: { type: 'integer', description: 'Number of adults to return the price for', minimum: 1, default: 1 }, children: { type: 'integer', description: 'Number of children to return the price for', minimum: 0, default: 0 }, routeId: { type: 'string', description: 'Specific identifier for the route to take between the two stations. This routeId is returned in the /api/v3/trips call.' }, plannedDepartureTime: { type: 'string', description: 'Format - date-time (as date-time in RFC3339). Used to find the correct route if multiple routes are possible.' }, plannedArrivalTime: { type: 'string', description: 'Format - date-time (as date-time in RFC3339). Used to find the correct route if multiple routes are possible.' } }, required: ['fromStation', 'toStation'] }
  • src/index.ts:361-370 (registration)
    CallTool handler case for get_prices in stdio MCP server: validates args and delegates to NSApiService.getPrices.
    case 'get_prices': { if (!isValidPricesArgs(rawArgs)) { throw ResponseFormatter.createMcpError( ErrorCode.InvalidParams, 'Invalid arguments for get_prices' ); } const data = await this.nsApiService.getPrices(rawArgs); return ResponseFormatter.formatSuccess(data); }
  • Tool registration in listTools handler for the HTTP MCP server, defining name, description, and inputSchema for get_prices.
    name: 'get_prices', description: 'Get price information for domestic train journeys, including different travel classes, ticket types, and discounts. Returns detailed pricing information with conditions and validity.', inputSchema: { type: 'object', properties: { fromStation: { type: 'string', description: 'UicCode or station code of the origin station', }, toStation: { type: 'string', description: 'UicCode or station code of the destination station', }, travelClass: { type: 'string', description: 'Travel class to return the price for', enum: ['FIRST_CLASS', 'SECOND_CLASS'] }, travelType: { type: 'string', description: 'Return the price for a single or return trip', enum: ['single', 'return'], default: 'single' }, isJointJourney: { type: 'boolean', description: 'Set to true to return the price including joint journey discount', default: false }, adults: { type: 'integer', description: 'Number of adults to return the price for', minimum: 1, default: 1 }, children: { type: 'integer', description: 'Number of children to return the price for', minimum: 0, default: 0 }, routeId: { type: 'string', description: 'Specific identifier for the route to take between the two stations. This routeId is returned in the /api/v3/trips call.' }, plannedDepartureTime: { type: 'string', description: 'Format - date-time (as date-time in RFC3339). Used to find the correct route if multiple routes are possible.' }, plannedArrivalTime: { type: 'string', description: 'Format - date-time (as date-time in RFC3339). Used to find the correct route if multiple routes are possible.' } }, required: ['fromStation', 'toStation'] } },

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/KallivdH/ns-mcp-server'

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