georgegiosue/mcp-emtrafesa
If you are the rightful owner of mcp-emtrafesa and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
MCP Emtrafesa is a Model Context Protocol server that provides AI assistants with seamless access to Peru's Emtrafesa bus transportation system.
MCP Emtrafesa
A Model Context Protocol (MCP) server for accessing Emtrafesa bus transportation services in Peru
- English: (You are here)
- EspaΓ±ol:
MCP Emtrafesa is a Model Context Protocol server that provides AI assistants with seamless access to Peru's Emtrafesa bus transportation system. Query terminals, schedules, tickets, and FAQs through standardized MCP tools.
π Features
- π’ Terminal Management: Access all bus terminals across Peru
- π Schedule Queries: Real-time departure and arrival schedules
- π« Ticket Lookup: Search purchased tickets by DNI and email
- β FAQ Support: Access frequently asked questions
- π Route Planning: Find available routes between terminals
- π Peru-Specific: Localized date formats and timezone handling
π¦ Installation
Prerequisites
- Bun v1.2.10 or higher
- Node.js v18+ (for TypeScript support)
Quick Start
# Clone the repository
git clone https://github.com/georgegiosue/mcp-emtrafesa.git
cd mcp-emtrafesa
# Install dependencies
bun install
# Start the MCP server
bun run index.ts
# Optional: Start with Model Context Protocol Inspector
bunx @modelcontextprotocol/inspector bun index.ts
π§ Usage
MCP Client Integration
Configure your MCP client to connect to this server:
{
"mcpServers": {
"mcp-emtrafesa": {
"command": "npx",
"args": ["mcp-emtrafesa@latest"]
}
}
}
Available Tools
Tool | Description | Parameters |
---|---|---|
get-terminals | Get all bus terminals in Peru | None |
get-arrival-terminal | Get destination terminals for origin | departureTerminalId |
get-departure-schedules | Get schedules between terminals | departureTerminalId , arrivalTerminalId , date? |
get-latest-purchased-tickets | Search tickets by user info | DNI , email |
get-frequently-asked-questions | Get FAQs about the service | None |
Example Queries
// Get all terminals
const terminals = await client.callTool("get-terminals");
// Find routes from Chiclayo to Trujillo
const schedules = await client.callTool("get-departure-schedules", {
departureTerminalId: "002",
arrivalTerminalId: "001",
date: "14/07/2025", // DD/MM/YYYY format
});
// Look up purchased tickets
const tickets = await client.callTool("get-latest-purchased-tickets", {
DNI: "12345678",
email: "user@example.com",
});
Project Structure
mcp-emtrafesa/
βββ π config/ # API configuration
β βββ api.ts # Headers and base settings
βββ π internal/ # Core business logic
β βββ emtrafesa/ # Emtrafesa-specific code
β βββ services.ts # API client functions
β βββ types.ts # TypeScript type definitions
βββ π sandbox/ # Development utilities
β βββ post-consulta.html # HTML parsing reference
βββ π index.ts # MCP server entry point
βββ π package.json # Dependencies and scripts
βββ π tsconfig.json # TypeScript configuration
βββ π biome.json # Code formatting rules
π‘οΈ API Integration
Supported Endpoints
- Terminals:
GET /Home/GetSucursales
- Destinations:
GET /Home/GetSucursalesDestino
- Schedules:
POST /Home/GetItinerario
(JSON) - Tickets:
POST /Consulta/PostConsulta
(Form-encoded) - FAQs:
GET /Home/GetPreguntasFrecuentes
Data Handling
- JSON APIs: Direct deserialization for structured data
- HTML Scraping: Cheerio-based parsing for ticket information
- Date Formats: Peru timezone (America/Lima) with DD/MM/YYYY format
- Error Handling: Graceful degradation with JSON error responses
π§ͺ Development
Code Formatting
# Format code with Biome
bun run format
# Check formatting without writing
bunx biome check
Type Safety
- Strict TypeScript configuration with
noUncheckedIndexedAccess
- Zod schemas for runtime validation
- Exact API field mapping in type definitions
Testing HTML Parsing
Use the reference file for testing changes:
# View the HTML structure reference
open sanbox/post-consulta.html
π€ Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Format your code (
bun run format
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
π License
This project is licensed under the MIT License - see the file for details.
Acknowledgments
- Emtrafesa for providing the transportation API
- Model Context Protocol for the MCP specification
- @tecncr for API endpoint insights
- Bun for the fast JavaScript runtime
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: peraldonamoc@gmail.com