A Go application following clean architecture principles, designed for integrating with Redbus inventory system for bus ticketing services and providing MCP (Model Context Protocol) tools for Claude Desktop integration.
This API provides endpoints to interact with the Redbus inventory system for bus ticketing. It allows querying bus routes, getting source-destination pairs, retrieving LIS IDs, fetching detailed route information with seat details, pricing, and boarding/dropping points. Additionally, it includes MCP tools that can be used with Claude Desktop for AI-assisted bus inventory queries.
The project follows a clean architecture pattern with the following structure:
- config/: Configuration management for database, Redis, and Redbus API endpoints.
config.go: Main configuration loader.type.go: Configuration type definitions.
- delivery/: Handles HTTP delivery (REST API endpoints).
api/: API response utilities.controller/: HTTP controllers (e.g.,bus_controller.gofor bus-related endpoints).middleware/: Middleware for authentication.
- manager/: Orchestrates infrastructure and business logic.
infra_manager.go: Manages infrastructure (MySQL database, Redis).repository_manager.go: Manages repository layer.usecase_manager.go: Manages usecase layer.
- model/: Data models and DTOs (Data Transfer Objects).
dto/: DTOs for request/response (e.g.,route_details_request.go,bus_query_request.go).user.go: User model definition.bus.go: Bus-related model definitions.
- repository/: Data persistence layer (e.g.,
bus_repository.gofor database operations and API calls). - usecase/: Business logic layer (e.g.,
bus_usecase.gofor bus-related use cases). - service/: MCP service integration.
- utils/: Utility functions.
app_error.go: Custom error handling.generic_sn.go: Generic utilities.json_io.go: JSON input/output helpers.app.go: Application-wide utilities.
Endpoint: POST /bus/lis-source-destination
Request:
{
"vendor_id": "34160",
"source_id": "CGK",
"destination_id": "SUB"
}Response:
{
"status": true,
"data": {
"lis_source_id": "193495",
"lis_destination_id": "194676"
},
"message": "Success"
}Function: Maps vendor-specific source and destination codes to LIS (Location Information System) IDs.
Endpoint: POST /bus/route-details-filtered
Request:
{
"vendor_id": "34188",
"lis_source_id": "194354",
"lis_destination_id": "193515",
"doj": "2025-07-30"
}Response:
{
"status": true,
"data": {
"route_details": [
{
"source_name": "Surabaya",
"destination_name": "Denpasar (bali)",
"route_id": "12745633",
"rating": 4.53483,
"available_seats": 13,
"depart_time": "2025-07-30 19:00:00",
"arrival_time": "2025-07-31 07:00:00",
"seat_details": [
{
"seat_number": "1",
"seat_type": "Seater",
"price": 300000.0,
"is_window": true,
"status": "AVAILABLE"
}
],
"bp_list": [
{
"name": "Kota Surabaya",
"address": "Jln. Letjen Sutoyo No.80 Surabaya"
}
],
"dp_list": [
{
"name": "Kantor Cokro",
"address": "Jln.HOS.Cokroaminoto No.294 Denpasar"
}
]
}
]
},
"message": "Success"
}Function: Provides comprehensive route details including seat information, pricing, and boarding/dropping points.
Endpoint: POST /bus/sd-pairs
Request:
{
"vendor_id": "34188"
}Response:
{
"status": true,
"data": [
{
"source_id": "SUB",
"source": "Surabaya",
"destination_id": "DPS",
"destination": "Denpasar"
}
],
"message": "Success"
}Function: Returns all available source-destination pairs for a specific vendor.
Endpoint: POST /bus/routesNotState
Request:
{
"vendor_id": "34188",
"source": "Surabaya",
"destination": "Denpasar",
"source_id": "SUB",
"destination_id": "DPS",
"date": "2025-07-30"
}Response:
{
"status": true,
"data": {
"buses": [
{
"service_name": "COMFORT SBY-DPS_Comfort Class",
"departure_time": "2025-07-30 19:00:00",
"arrival_time": "2025-07-31 07:00:00",
"fare": 300000.0,
"currency": "IDR",
"available_seats": 13,
"bus_type": "Super Executive"
}
]
},
"message": "Success"
}Function: Provides a summary of available buses for a specific route and date.
Endpoint: POST /bus/vendor-cities
Request:
{
"vendor_id": "34188"
}Response:
{
"status": true,
"data": {
"cities": [
{
"CityId": "193495",
"CityName": "Jakarta",
"VCityId": "CGK"
}
],
"message": "Found 150 cities for vendor 34188"
},
"message": "Success"
}Function: Returns all cities served by a specific vendor from the external Redbus API.
The application includes MCP tools that can be used with Claude Desktop for AI-assisted bus inventory queries. The following tools are available:
- busRoutes: Find available bus routes
- sdPairs: Get source-destination pairs for a vendor
- getLisSourceDestination: Get LIS Source and Destination IDs for a vendor route
- getRouteDetailsFiltered: Get detailed route information with seat details and pricing
- getVendorCities: Get all cities served by a vendor
- Go 1.18 or later
- MySQL database
- Redis for caching
- Access to Redbus integration APIs
- Claude Desktop (for MCP integration)
git clone https://github.com/Steve246/mcp-inventoryRB.git
cd mcp-inventoryRBgo mod downloadCreate a .env file in the root directory (copy from steven.env as a template):
cp steven.env .envThe .env file should contain the following variables:
# Database Configuration
DB_HOST=xxx
DB_PORT=xxx
DB_USER=xxx
DB_PASSWORD=xxx
DB_NAME=xxx
# API Configuration
API_URL=xxx
# Redis Configuration
REDIS_ADDRESS=xxx
REDIS_PASSWORD=xxx
REDIS_DB=xxx
# Redbus API Endpoints
getSdPair= getsourcedestinationpairs url
getAvRoutes= getAvRoutesObject url
getRedbusSearch= getAvRoutesObject url
getRealTime= getRealTimeUpdate url# Build the application
go build -o mcp-server .
# Or build for production
go build -ldflags="-s -w" -o mcp-server .# Run the full application (HTTP API + MCP server)
./mcp-server
# Or run MCP server only
./mcp-server --mcp-onlyThe HTTP API will be available at http://localhost:8888
- Download and install Claude Desktop from https://claude.ai/download
- Sign in with your Anthropic account
# Navigate to your project directory
cd /path/to/mcp-inventoryRB
# Build the application
go build -o mcp-server .
# Make sure it's executable
chmod +x mcp-serverCreate or copy your .env file with database credentials:
cp steven.env .env
# Edit .env with your actual database credentialsFind the correct path for your operating system:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json(usuallyC:\Users\<username>\AppData\Roaming\Claude\claude_desktop_config.json) - Linux:
~/.config/Claude/claude_desktop_config.json
If the file doesn't exist, create it. Otherwise, add to the existing mcpServers object:
{
"mcpServers": {
"mcp-inventoryRB": {
"command": "/absolute/path/to/mcp-server",
"args": ["--mcp-only"],
"env": {
"ENV_FILE": "steven.env"
}
}
}
}Important Notes:
- Use absolute paths for the
commandfield - The
--mcp-onlyflag runs only the MCP server (no HTTP API) - Simply specify
ENV_FILEwith your environment file name (defaults to "steven.env") - The MCP server will automatically load all environment variables from the specified .env file
- Completely quit Claude Desktop (Cmd+Q on Mac, Alt+F4 on Windows)
- Restart the application
- The MCP server should start automatically
Open Claude Desktop and try these test queries:
What cities does vendor 34188 serve?
Find bus routes from Jakarta to Surabaya
Show me source-destination pairs for vendor 34160
If you see responses with actual data, the integration is working!
- Check that the path to
mcp-serveris correct and executable - Verify your
.envfile exists and contains correct environment variables - Ensure the
ENV_FILEenvironment variable points to the correct .env file - Check the Claude Desktop logs for error messages
- Ensure your
.envfile has correct database credentials - Test database connectivity:
mysql -h DB_HOST -u DB_USER -p DB_NAME
- Restart Claude Desktop after configuration changes
- Check that the MCP server process is running:
ps aux | grep mcp-server - Verify JSON syntax in
claude_desktop_config.json
- On macOS/Linux, ensure the MCP server binary has execute permissions:
chmod +x mcp-server - Check file permissions on the configuration file
Once connected, Claude can use these tools:
busRoutes- Find available bus routes between locationssdPairs- Get source-destination pairs for a vendorgetLisSourceDestination- Convert vendor codes to LIS system IDsgetRouteDetailsFiltered- Get detailed route information with pricinggetVendorCities- List all cities served by a vendor
User: "What cities does vendor 34188 serve?"
Claude: [Uses getVendorCities tool] "Vendor 34188 serves 150 cities including Jakarta, Surabaya, Bali, and more..."
User: "Find bus routes from Jakarta to Bali on December 25th"
Claude: [Uses busRoutes tool] "Here are the available bus routes from Jakarta to Bali on December 25th..."
You can also run the MCP server separately for testing:
# Run only MCP server (no HTTP API)
./mcp-server --mcp-only
# Run both HTTP API and MCP server
./mcp-serverThe MCP server will listen for connections from Claude Desktop via stdio protocol.
- Gin: HTTP web framework
- GORM: ORM library with MySQL driver
- Redis: Caching and session management
- godotenv: Environment variable loading from .env files
- MCP Go Library: Model Context Protocol implementation for Claude Desktop integration
The application uses environment variables loaded from a .env file:
- Database: MySQL connection parameters (host, port, user, password, database name)
- API: Server configuration (URL, port)
- Redis: Caching configuration (address, password, database)
- Redbus APIs: External API endpoints for bus inventory integration
| Variable | Description | Default |
|---|---|---|
DB_HOST |
MySQL database host | Internal URL |
DB_PORT |
MySQL database port | Internal Port |
DB_USER |
MySQL database user | Internal URL |
DB_PASSWORD |
MySQL database password | Internal Password |
DB_NAME |
MySQL database name | Internal Name |
API_URL |
HTTP server URL | Internal URL |
REDIS_ADDRESS |
Redis server address | Internal URL |
REDIS_PASSWORD |
Redis password | Internal Password |
REDIS_DB |
Redis database number | 0 |
getSdPair |
Redbus SD pairs API endpoint | Internal URL |
getAvRoutes |
Redbus available routes API endpoint | Internal URL |
getRedbusSearch |
Redbus search API endpoint | Internal URL |
getRealTime |
Redbus real-time update API endpoint | Internal URL |
Typical usage workflow:
- Discover Cities: Use
/bus/vendor-citiesto get all cities served by a vendor - Discover Routes: Use
/bus/sd-pairsto get available source-destination pairs for a vendor - Get LIS IDs: Use
/bus/lis-source-destinationto map vendor codes to LIS system IDs - Get Route Details: Use
/bus/route-details-filteredto get comprehensive route information - Quick Search: Use
/bus/routesNotStatefor simplified route queries
Once configured with Claude Desktop, you can ask natural language questions:
- "Show me all cities served by vendor 34188"
- "Find bus routes from Jakarta to Bali on December 25th"
- "Get detailed information for route from Surabaya to Denpasar"
- "What are the source-destination pairs for vendor 34160?"
Standard HTTP status codes:
200 OK: Successful request400 Bad Request: Invalid request parameters404 Not Found: Resource not found500 Internal Server Error: Server error
mcp-inventoryRB/
├── app.go # Application entry point
├── go.mod # Go module dependencies
├── go.sum # Go module checksums
├── steven.env # Environment variables template
├── readme.md # This documentation
├── config/ # Configuration management
│ ├── config.go # Main configuration loader
│ └── type.go # Configuration type definitions
├── delivery/ # HTTP layer
│ ├── api/ # Response utilities
│ │ └── response/ # JSON response handlers
│ ├── controller/ # HTTP controllers
│ │ └── bus_controller.go
│ ├── middleware/ # Request middleware
│ │ └── auth_token_middleware.go
│ └── server.go # HTTP server setup
├── files/ # Legacy configuration files
├── manager/ # Infrastructure management
│ ├── infra_manager.go
│ ├── repository_manager.go
│ ├── service_manager.go
│ └── usecase_manager.go
├── model/ # Data models and DTOs
│ ├── bus.go # Bus-related models
│ ├── bus_mcp.go # MCP tool argument models
│ ├── user.go # User model
│ └── dto/ # Request/response DTOs
├── repository/ # Data access layer
│ └── bus_repository.go
├── service/ # MCP service integration
│ └── mcp_service.go # MCP server implementation
├── usecase/ # Business logic layer
│ └── bus_service.go
└── utils/ # Helper utilities
├── app_error.go # Custom error handling
├── change_format.go
├── generate_sn.go
├── json_io.go
└── utils.go
- Follow clean architecture principles
- Maintain separation of concerns between layers
- Add appropriate error handling
- Update documentation for new endpoints and features
- Test both HTTP API and MCP tool functionality
# Clean and build
go clean
go build -o mcp-server .
# Run tests
go test ./...# Optimized build with stripped symbols
go build -ldflags="-s -w" -o mcp-server .
# Cross-platform build (example for Linux)
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o mcp-server-linux .FROM golang:1.21-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -ldflags="-s -w" -o mcp-server .
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/mcp-server .
COPY --from=builder /app/steven.env .env
CMD ["./mcp-server"]- Database Connection Failed: Check your
.envfile database credentials - MCP Tools Not Available: Ensure Claude Desktop is configured with correct MCP server path
- API Returns Empty Results: Verify vendor IDs and external API endpoints are accessible
- Build Errors: Run
go mod tidyto clean up dependencies
For additional logging, you can modify the configuration to enable debug logging in your environment variables.
This project is proprietary software. All rights reserved.