npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

mcp-emtrafesa

v1.0.1

Published

A Model Context Protocol (MCP) server for accessing Emtrafesa bus transportation services in Peru

Readme

MCP Logo MCP Emtrafesa

A Model Context Protocol (MCP) server for accessing Emtrafesa bus transportation services in Peru

TypeScript Bun MCP License: MIT

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": "bun",
      "args": ["run", "index.ts"],
      "cwd": "/path/to/mcp-emtrafesa"
    }
  }
}

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: "[email protected]",
});

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

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Format your code (bun run format)
  4. Commit your changes (git commit -m 'Add amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Support