nestjs-xiaozhi-mcp-server
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@nestjs-xiaozhi-mcp-serverAdd a todo to buy groceries tomorrow"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
NestJS Xiaozhi MCP Server
A high-performance Model Context Protocol (MCP) Hub & Gateway built with NestJS (v12) for the Xiaozhi ESP32 AI assistant ecosystem.
🌟 Overview
NestJS Xiaozhi MCP Server acts as a unified central bridge between the Xiaozhi AI voice assistant (ESP32) and external capabilities. It aggregates:
7 Local Business Tools: Daily schedule, alarm/reminders, real-time stock quotes (FTS, SSI, VND, AAPL, TSLA), and task/todo management.
37 Dynamic OmniRoute Agentic Tools: Persistent Long-Term Memory, AgentSkills, OmniSkills sandbox execution, webhooks, and advanced automations retrieved dynamically via SSE from OmniRoute (
https://ai.tuanphongoto.com/api/mcp/sse).Dual Protocol Transports: Full support for standard MCP SSE Transport (recommended for Xiaozhi) and legacy single-turn HTTP JSON-RPC.
Production-Ready Docker Setup: Multi-stage build on Alpine, non-root execution, strictly bounded resource consumption (512MB RAM / 1.0 CPU), V8 GC tuning, log rotation, and native healthchecks.
Related MCP server: iot-mcp-bridge
🏗️ System Architecture
graph TD
subgraph Edge Layer [Hardware & Voice]
ESP32[📻 ESP32 XiaoZhi Robot / Speaker]
end
subgraph Core AI Server [XiaoZhi Core]
XiaozhiBackend[🖥️ XiaoZhi Backend Server<br/>STT / TTS / WebSocket Protocol]
LLM[🤖 LLM via OmniProxy / OpenAI]
end
subgraph MCP Hub [NestJS Xiaozhi MCP Server - Port 3000]
HealthCtrl[💓 /health Monitoring]
McpCtrl[🔌 McpController<br/>GET /mcp/sse & POST /mcp/messages]
McpEngine[⚙️ McpServer Engine<br/>Factory Pattern Sessions]
Business[💼 Business Services<br/>Schedule / Finance / Todo]
OmniBridge[⚡ OmniRouteClientService<br/>Auto-reconnect & Sync]
end
subgraph Remote Cloud [AI Gateway]
OmniRoute[🌐 OmniRoute MCP Server<br/>37 Agentic Tools / Memory / Skills]
end
ESP32 <-->|Opus Frames / WebSocket| XiaozhiBackend
XiaozhiBackend <-->|Prompt & Tools List| LLM
XiaozhiBackend <-->|MCP SSE Transport| McpCtrl
McpCtrl --> McpEngine
McpEngine --> Business
McpEngine <-->|Dynamic Remote Tools| OmniBridge
OmniBridge <-->|SSE Client Transport| OmniRoute🛠️ Tech Stack
Framework: NestJS (v12)
Protocol: Model Context Protocol via
@modelcontextprotocol/sdk(v1.30+)Runtime: Node.js 22 LTS (ESM syntax)
Package Manager: pnpm
Language: TypeScript (Strict Mode)
Testing: Vitest
Linting: Oxlint & Prettier
Containerization: Docker & Docker Compose (Multi-stage Alpine, non-root user
node)
🧰 Available MCP Tools (Total: 44 Tools)
1. Local Business Tools (7 Tools)
Tool Name | Description |
| Lấy danh sách lịch trình, kế hoạch công việc và cuộc hẹn trong ngày của người dùng. |
| Thêm cuộc hẹn, sự kiện hoặc công việc mới vào lịch trình. |
| Đặt báo thức hoặc nhắc nhở vào khung giờ cụ thể. |
| Tra cứu giá và thông tin thị trường cổ phiếu thực tế (FTS, SSI, VND, AAPL, TSLA). |
| Lấy danh sách việc cần làm (Todo List) theo trạng thái (all, pending, completed). |
| Thêm việc cần làm mới với các mức ưu tiên (low, medium, high). |
| Đánh dấu việc cần làm đã hoàn thành theo ID hoặc nội dung. |
2. OmniRoute Agentic Tools (37 Dynamic Tools)
When OMNIROUTE_ENABLED=true, the server connects to OmniRoute and dynamically surfaces 37 agentic tools across 13 scopes, including:
Persistent Agent Memory:
memory_set,memory_get,memory_search(Allows XiaoZhi to remember user preferences across sessions).AgentSkills & OmniSkills: Dynamic skill registry and sandbox execution.
Chaos Mode & A2A: Multi-model parallel execution and agent-to-agent protocol triggers.
System Webhooks & Utilities: Remote execution and automation integrations.
📡 Protocol & Endpoints
Endpoint | Method | Transport | Description |
|
| MCP SSE | Khởi tạo phiên kết nối SSE (Server-Sent Events) cho Xiaozhi. |
|
| MCP SSE | Gửi các thông điệp JSON-RPC theo session id ( |
|
| HTTP RPC | Endpoint JSON-RPC đơn lượt truyền thống (Backward compatible). |
|
| HTTP JSON | Cấp cấu hình WebSocket ( |
|
| HTTP | Kiểm tra trạng thái hoạt động (uptime, status) cho Docker/Kubernetes. |
⚙️ Environment Variables
Create a .env file in the root directory (see .env.example):
Variable | Type | Default | Description |
| Number |
| Port máy chủ NestJS lắng nghe |
| String |
| Tên định danh của MCP Server |
| String |
| Phiên bản của MCP Server |
| String | (optional) | Khóa bảo vệ endpoint (Header |
| Boolean |
| Bật/tắt kết nối đến OmniRoute MCP Server |
| String |
| URL SSE endpoint của OmniRoute |
| String | (optional) | Bearer API Key xác thực với OmniRoute |
| String |
| Địa chỉ WebSocket server cấp cho ESP32 khi gọi |
| String | (optional) | Token xác thực WebSocket (nếu có) |
🚀 Deployment & Running
Option 1: Production Deployment with Docker Compose (docker-compose.prod.yml)
The production Compose configuration (docker-compose.prod.yml) pulls the pre-built, multi-architecture image directly from GitHub Container Registry (GHCR). On production servers, no source code or build dependencies are needed—only .env and docker-compose.prod.yml:
# 1. Pull the latest production image
docker compose -f docker-compose.prod.yml pull
# 2. Start container in detached mode
docker compose -f docker-compose.prod.yml up -d
# 3. Check health and real-time logs
docker compose -f docker-compose.prod.yml ps
docker compose -f docker-compose.prod.yml logs -f
# 4. Graceful stop
docker compose -f docker-compose.prod.yml downYou can pin a specific image version by settingIMAGE_TAG=v1.0.0 in your .env or shell environment before running docker compose -f docker-compose.prod.yml up -d.
Option 2: Run Directly with Docker CLI
# Pull and run directly from GHCR
docker pull ghcr.io/shirotamada/nestjs-xiaozhi-mcp-server:latest
docker run -d \
--name nestjs-xiaozhi-mcp-prod \
-p 3000:3000 \
--env-file .env \
--restart always \
ghcr.io/shirotamada/nestjs-xiaozhi-mcp-server:latestOption 3: Local Build & Development with Docker Compose (docker-compose.yml)
The included Dockerfile and docker-compose.yml feature:
Strict Resource Boundaries: Maximum
512MBRAM and1.0CPU core limit to safeguard host resources.Node.js Memory Tuning:
NODE_OPTIONS="--max-old-space-size=384"triggers V8 Garbage Collection proactively before hitting the 512MB container ceiling.Security: Runs under unprivileged user
node(non-root).Log Rotation: Capped at 3 files $\times$ 20MB to prevent disk exhaustion.
Automated Healthcheck: Pings
GET /healthevery 30s.
# 1. Pull & run (or build locally if needed)
docker compose up -d
# 2. Inspect container status and health
docker compose ps
# 3. View real-time logs
docker compose logs -f
# 4. Check health endpoint
curl http://localhost:3000/health
# 5. Stop container
docker compose downOption 4: Local Development (Without Docker)
# Install dependencies
pnpm install
# Run in watch mode (development)
pnpm run start:dev
# Run in production mode
pnpm run build
pnpm run start:prod📻 Integration with XiaoZhi ESP32 Server
Open your XiaoZhi backend server configuration (
config.yamlordata/.config.yaml).Add
nestjs-xiaozhi-hubundermcp.global.servers:
mcp:
global:
enabled: true
servers:
- name: "nestjs-xiaozhi-hub"
sse_url: "http://<SERVER_IP>:3000/mcp/sse"
enabled: true
reconnect_interval: 5
max_reconnect_attempts: 10
# headers:
# Authorization: "Bearer your-secret-api-key" # Uncomment if MCP_API_KEY is configuredA ready-to-use template is available at templates/xiaozhi-config.yaml.
Restart the XiaoZhi server. XiaoZhi will discover all 44 tools automatically!
🧪 Testing & Code Quality
# Run unit tests
pnpm run test
# Run tests with coverage
pnpm run test:cov
# Run fast code linter (Oxlint)
pnpm run lint
# Format codebase (Prettier)
pnpm run format📄 License
UNLICENSED
This server cannot be deployed
Maintenance
Related MCP Connectors
- ZapierOAuthcom.zapier
Hosted MCP server connecting AI assistants to 9,000+ apps and 40,000+ actions via Zapier.
Give your AI agent a memory and body on your iPhone: set alarms, ring your phone, over MCP.
Connect any AI agent to 1,000+ apps and 27,000+ actions through one remote MCP server (OAuth).
- UnifAPIOAuthcom.unifapi
Hosted MCP server for live public-data APIs and Skills for AI agents.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceA general-purpose MCP gateway that exposes your local CLI skills to any AI assistant.4 npm1MIT
- AlicenseNot gradedqualityDmaintenanceEnables natural language control of ESP8266 and Raspberry Pi IoT devices via Claude Desktop using the MCP protocol.MIT
- AlicenseNot gradedqualityAmaintenanceConnects embodied devices (like StackChan, Raspberry Pi, ESP32) to AI via MCP protocol, enabling motion control with zero API cost, no PC required, and fully self-hosted.MIT
- AlicenseNot gradedqualityCmaintenanceThis MCP server enables AI models to interact with ESP32 devices, providing built-in tools for web search, note management, calculator, and custom tools like todo lists and timers.MIT