@siva-sub/mcp-public-transport
Version:
A Model Context Protocol server for Singapore transport data with real-time information and routing
102 lines (101 loc) • 2.63 kB
TypeScript
/**
* Instruction parsing service for OneMap routing responses
*/
export interface ParsedInstruction {
step: number;
type: 'direct' | 'transit' | 'transit_walk';
mode: 'WALK' | 'BUS' | 'TRAIN' | 'SUBWAY' | 'TAXI';
direction?: string;
streetName?: string;
distance: number;
duration?: number;
coordinates: {
lat: number;
lng: number;
} | null;
instruction: string;
service?: string;
operator?: string;
from?: {
name: string;
stopCode?: string;
coordinates: {
lat: number;
lng: number;
};
};
to?: {
name: string;
stopCode?: string;
coordinates: {
lat: number;
lng: number;
};
};
intermediateStops?: Array<{
name: string;
stopCode?: string;
coordinates: {
lat: number;
lng: number;
};
}>;
estimatedContext?: {
area: string;
timeOfDay: string;
weatherNote: string;
landmark?: string;
safetyNote?: string;
accessibilityInfo?: string;
};
}
export interface RouteSummary {
responseType: 'PUBLIC_TRANSPORT' | 'DIRECT_ROUTING' | 'ERROR';
totalTime?: number;
totalDistance?: number;
totalCost?: number;
walkDistance?: number;
transfers?: number;
fare?: string;
instructionCount: number;
polylineCount: number;
}
export declare class InstructionParserService {
/**
* Parse instructions from OneMap response
*/
parseInstructions(response: any): ParsedInstruction[];
/**
* Parse direct routing instructions (walk/drive/cycle)
*/
private parseDirectInstructions;
/**
* Parse public transport instructions
*/
private parseTransitInstructions;
/**
* Generate route summary
*/
generateSummary(response: any, instructions: ParsedInstruction[], polylineCount: number): RouteSummary;
/**
* Enhance instructions with contextual information
*/
enhanceInstructions(instructions: ParsedInstruction[]): ParsedInstruction[];
/**
* Format instructions for human reading
*/
formatInstructionsForDisplay(instructions: ParsedInstruction[]): string[];
/**
* Helper methods
*/
private getResponseType;
private parseCoordinates;
private mapDirectMode;
private mapTransitMode;
private generateBasicContext;
private getAreaFromCoordinates;
private getCurrentTimeContext;
private findNearbyLandmark;
private getSafetyNote;
private getAccessibilityInfo;
}