关于 Bengaluru BMTC MCP Server
Bengaluru BMTC MCP Server 为 Bengaluru 公交查询提供 BMTC 数据,涵盖实时车辆位置、线路、站点和预计到达时间,并支持附近车辆与站点的地理空间查询。
主要功能
- 01实时公交位置追踪
- 02线路信息与时刻表
- 03站点信息与预计到达时间
- 04附近车辆和站点的地理查询
适用场景
- 01查看公交车当前位置
- 02查询线路与时刻表
- 03查找附近站点和车辆
- 04估算公交到站时间
MCP 相关
该 MCP 服务向 MCP 客户端提供 BMTC 公交位置、线路、站点和预计到达时间数据。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
班加罗尔 BMTC MCP 服务
为班加罗尔大都会交通公司(BMTC)公交服务实现的模型上下文协议(MCP)服务。
架构
BMTC MCP 服务采用模块化分层架构。系统旨在处理班加罗尔大都会交通公司公交车的实时交通数据,并通过标准化 API 提供这些数据。
核心组件
- API 层:用于身份验证、路线、站点、公交车位置和预计到达时间信息的 RESTful 端点
- 服务层:业务逻辑、数据转换和预计到达时间计算
- 数据访问层:通过 Mongoose ODM 集成 MongoDB
- 缓存层:基于 Redis 的缓存,以提升性能
- 外部集成层:BMTC API 集成
功能
以下是你可以通过 MCP 客户端或聊天窗口获取的信息:
- 实时公交车位置跟踪
- 路线信息和时刻表
- 站点详情和预计到达时间(ETA)
- 支持班加罗尔 2,200 多条公交路线和 8,400 多个公交站点
- 身份验证和授权
- 数据缓存和优化
- 用于查询附近站点和公交车的地理空间查询
前置条件
- Node.js(v14 或更高版本)
- npm 或 yarn
- MongoDB
- Redis(可选,用于缓存)
- Git
安装和设置
方法 1:标准安装
- 克隆代码库
git clone https://github.com/ajeetraina/bengaluru-bmtc-mcp.git
cd bengaluru-bmtc-mcp
- 安装依赖项
npm install
- 配置环境变量
cp .env.example .env
编辑 .env 文件并填写配置:
PORT=3000
NODE_ENV=development
MONGO_URI=mongodb://localhost:27017/bmtc-mcp
REDIS_URI=redis://localhost:6379
API_KEY=your_api_key_here
JWT_SECRET=your_jwt_secret_here
JWT_EXPIRES_IN=86400
BMTC_API_ENDPOINT=https://bmtc-api-endpoint.example
BMTC_API_KEY=your_bmtc_api_key_here
CACHE_DURATION=300
LOG_LEVEL=info
- 使用模拟数据填充数据库(可选)
node src/scripts/seed.js
- 启动服务
npm start
开发时启用自动重启:
npm run dev
方法 2:使用 Docker Compose
- 克隆代码库
git clone https://github.com/ajeetraina/bengaluru-bmtc-mcp.git
cd bengaluru-bmtc-mcp
- 配置环境变量(可选)
你可以直接在 docker-compose.yml 文件中修改环境变量,也可以创建 .env 文件:
cp .env.example .env
- 构建并启动容器
docker-compose up -d
这将启动三个容器:
bmtc-mcp-api:Node.js API 服务bmtc-mcp-mongo:MongoDB 数据库bmtc-mcp-redis:Redis 缓存服务
- 使用模拟数据填充数据库(可选)
docker-compose exec api node src/scripts/seed.js
- 查看日志
docker-compose logs -f api
- 停止容器
docker-compose down
如需同时移除卷:
docker-compose down -v
使用 API
服务运行后,你可以通过以下地址访问 API:
http://localhost:3000/api/v1
如需查看 API 文档,请访问:
http://localhost:3000/api-docs
API 端点示例
# Authentication
POST /api/v1/auth/login
GET /api/v1/auth/me
# Routes
GET /api/v1/routes
GET /api/v1/routes/:routeId
GET /api/v1/routes/search?source=Kempegowda&destination=Electronic
# Stops
GET /api/v1/stops
GET /api/v1/stops/:stopId
GET /api/v1/stops/near?lat=12.9767&lng=77.5713&radius=500
GET /api/v1/stops/search?query=Lalbagh
# Bus Locations
GET /api/v1/bus-locations
GET /api/v1/bus-locations/:busId
GET /api/v1/bus-locations/near?lat=12.9767&lng=77.5713&radius=1000
# ETA
GET /api/v1/eta/:stopId
GET /api/v1/eta/:stopId/:routeId
API 密钥
JWT 密钥
JWT 密钥用于签署身份验证令牌。请生成一个安全的随机字符串:
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
将其添加到 .env 文件中:
JWT_SECRET=your_generated_secret_here
BMTC API 密钥
在开发过程中,你可以使用模拟数据,无需实际的 BMTC API 密钥:
BMTC_API_ENDPOINT=https://bmtc-api-endpoint.example
BMTC_API_KEY=your_bmtc_api_key_here
在生产环境中,你需要直接联系 BMTC 申请官方 API 访问权限。
开发
测试
运行测试:
npm test
运行测试并生成覆盖率报告:
npm run test:coverage
代码检查
检查代码风格:
npm run lint
修复代码风格问题:
npm run lint:fix
项目结构
bengaluru-bmtc-mcp/
├── .env.example # Environment variables template
├── .eslintrc.json # ESLint configuration
├── .github/ # GitHub configuration
│ └── workflows/ # GitHub Actions workflows
├── .gitignore # Git ignore file
├── CONTRIBUTING.md # Contribution guidelines
├── Dockerfile # Docker configuration
├── LICENSE # MIT License
├── README.md # Project documentation
├── docker-compose.yml # Docker Compose configuration
├── docs/ # Documentation
│ ├── api.md # API documentation
│ └── setup.md # Setup guide
├── jest.config.js # Jest configuration
├── package.json # Project dependencies
└── src/ # Source code
├── config/ # Configuration files
├── controllers/ # Request handlers
├── index.js # Application entry point
├── middlewares/ # Express middlewares
├── models/ # MongoDB models
├── public/ # Static files
├── routes/ # API routes
├── scripts/ # Utility scripts
├── services/ # External service integrations
├── tests/ # Test files
└── utils/ # Utility functions
贡献
请阅读 CONTRIBUTING.md,了解我们的行为准则以及提交拉取请求的流程。
许可证
本项目采用 MIT 许可证授权,详情请参阅 LICENSE 文件。
致谢
- 班加罗尔大都会交通公司(BMTC)
- 新加坡 LTA MCP 实现,为本项目提供了灵感
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。