Skip to content

Commit e9ef0ed

Browse files
committed
feat: add xiaozhi websocket based mcp server support
1 parent b94a2e5 commit e9ef0ed

File tree

8 files changed

+1197
-384
lines changed

8 files changed

+1197
-384
lines changed

Dockerfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ COPY src/ ./src/
2020
COPY main.py .
2121
COPY .env* ./
2222

23+
# Create logs directory
24+
RUN mkdir -p logs
25+
2326
# Create non-root user for security
2427
RUN useradd -m -u 1000 mcpuser && chown -R mcpuser:mcpuser /app
2528
USER mcpuser
2629

27-
# Expose stdio for MCP communication
30+
# Set environment variables for MCP
31+
ENV PYTHONUNBUFFERED=1
32+
ENV PYTHONPATH=/app
33+
34+
# Default command - supports both stdio (Claude/Cursor) and WebSocket (Xiaozhi) modes
35+
# Mode is controlled by ENABLE_XIAOZHI environment variable
2836
CMD ["python", "main.py"]

README.md

Lines changed: 121 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
A Model Context Protocol (MCP) server for Synology NAS devices. Enables AI assistants to manage files and downloads through secure authentication and session management.
66

7+
**🌟 NEW: Unified server supports both Claude/Cursor (stdio) and Xiaozhi (WebSocket) simultaneously!**
8+
79
## 🚀 Quick Start with Docker
810

911
### 1️⃣ Setup Environment
@@ -17,6 +19,20 @@ cp env.example .env
1719
```
1820

1921
### 2️⃣ Configure .env File
22+
23+
**Basic Configuration (Claude/Cursor only):**
24+
```bash
25+
# Required: Synology NAS connection
26+
SYNOLOGY_URL=http://192.168.1.100:5000
27+
SYNOLOGY_USERNAME=your_username
28+
SYNOLOGY_PASSWORD=your_password
29+
30+
# Optional: Auto-login on startup
31+
AUTO_LOGIN=true
32+
VERIFY_SSL=false
33+
```
34+
35+
**Extended Configuration (Both Claude/Cursor + Xiaozhi):**
2036
```bash
2137
# Required: Synology NAS connection
2238
SYNOLOGY_URL=http://192.168.1.100:5000
@@ -26,27 +42,39 @@ SYNOLOGY_PASSWORD=your_password
2642
# Optional: Auto-login on startup
2743
AUTO_LOGIN=true
2844
VERIFY_SSL=false
45+
46+
# Enable Xiaozhi support
47+
ENABLE_XIAOZHI=true
48+
XIAOZHI_TOKEN=your_xiaozhi_token_here
49+
XIAOZHI_MCP_ENDPOINT=wss://api.xiaozhi.me/mcp/
2950
```
3051

3152
### 3️⃣ Run with Docker
53+
54+
**One simple command supports both modes:**
55+
3256
```bash
33-
# Build and run
34-
docker-compose up --build
57+
# Claude/Cursor only mode (default if ENABLE_XIAOZHI not set)
58+
docker-compose up -d
59+
60+
# Both Claude/Cursor + Xiaozhi mode (if ENABLE_XIAOZHI=true in .env)
61+
docker-compose up -d
3562

36-
# Most of the case you run detached
63+
# Build and run
3764
docker-compose up -d --build
3865
```
3966

40-
### 4️⃣ Alternative: Docker Run
67+
### 4️⃣ Alternative: Local Python
68+
4169
```bash
42-
# Build image
43-
docker build -t synology-mcp-server .
70+
# Install dependencies
71+
pip install -r requirements.txt
4472

45-
# Run container
46-
docker run --env-file .env synology-mcp-server
73+
# Run with environment control
74+
python main.py
4775
```
4876

49-
## 🔌 MCP Client Setup
77+
## 🔌 Client Setup
5078

5179
### 🤖 Claude Desktop
5280

@@ -70,9 +98,9 @@ Add to your Claude Desktop configuration file:
7098
}
7199
```
72100

73-
### 🔄 Continue (VS Code Extension)
101+
### ↗️ Cursor
74102

75-
Add to your Continue configuration (`.continue/config.json`):
103+
Add to your Cursor MCP settings:
76104

77105
```json
78106
{
@@ -89,9 +117,9 @@ Add to your Continue configuration (`.continue/config.json`):
89117
}
90118
```
91119

92-
### ↗️ Cursor
120+
### 🔄 Continue (VS Code Extension)
93121

94-
Add to your Cursor MCP settings:
122+
Add to your Continue configuration (`.continue/config.json`):
95123

96124
```json
97125
{
@@ -129,7 +157,7 @@ For Codeium's MCP support:
129157

130158
### 🐍 Alternative: Direct Python Execution
131159

132-
If you prefer not to use Docker, you can run the server directly:
160+
If you prefer not to use Docker:
133161

134162
```json
135163
{
@@ -142,21 +170,63 @@ If you prefer not to use Docker, you can run the server directly:
142170
"SYNOLOGY_URL": "http://192.168.1.100:5000",
143171
"SYNOLOGY_USERNAME": "your_username",
144172
"SYNOLOGY_PASSWORD": "your_password",
145-
"AUTO_LOGIN": "true"
173+
"AUTO_LOGIN": "true",
174+
"ENABLE_XIAOZHI": "false"
146175
}
147176
}
148177
}
149178
}
150179
```
151180

152-
## 💻 Local Development Setup
181+
## 🌟 Xiaozhi Integration
182+
183+
**New unified architecture supports both clients simultaneously!**
184+
185+
### How It Works
186+
187+
- **ENABLE_XIAOZHI=false** (default): Standard MCP server for Claude/Cursor via stdio
188+
- **ENABLE_XIAOZHI=true**: Multi-client bridge supporting both:
189+
- 📡 **Xiaozhi**: WebSocket connection
190+
- 💻 **Claude/Cursor**: stdio connection
153191

192+
### Setup Steps
193+
194+
1. **Add to your .env file:**
154195
```bash
155-
# Install dependencies
156-
pip install -r requirements.txt
196+
ENABLE_XIAOZHI=true
197+
XIAOZHI_TOKEN=your_xiaozhi_token_here
198+
```
157199

158-
# Run directly
200+
2. **Run normally:**
201+
```bash
202+
# Same command, different behavior based on environment
159203
python main.py
204+
# OR
205+
docker-compose up
206+
```
207+
208+
### Key Features
209+
-**Zero Configuration Conflicts**: One server, multiple clients
210+
-**Parallel Operation**: Both clients can work simultaneously
211+
-**All Tools Available**: Xiaozhi gets access to all Synology MCP tools
212+
-**Backward Compatible**: Existing setups work unchanged
213+
-**Auto-Reconnection**: Handles WebSocket connection drops
214+
-**Environment Controlled**: Simple boolean flag to enable/disable
215+
216+
### Startup Messages
217+
218+
**Claude/Cursor only mode:**
219+
```
220+
🚀 Synology MCP Server
221+
==============================
222+
📌 Claude/Cursor only mode (ENABLE_XIAOZHI=false)
223+
```
224+
225+
**Both clients mode:**
226+
```
227+
🚀 Synology MCP Server with Xiaozhi Bridge
228+
==================================================
229+
🌟 Supports BOTH Xiaozhi and Claude/Cursor simultaneously!
160230
```
161231

162232
## 🛠️ Available MCP Tools
@@ -220,6 +290,9 @@ python main.py
220290
| `AUTO_LOGIN` | No | `true` | Auto-login on server start |
221291
| `VERIFY_SSL` | No | `true` | Verify SSL certificates |
222292
| `DEBUG` | No | `false` | Enable debug logging |
293+
| `ENABLE_XIAOZHI` | No | `false` | Enable Xiaozhi WebSocket bridge |
294+
| `XIAOZHI_TOKEN` | Xiaozhi only | - | Authentication token for Xiaozhi |
295+
| `XIAOZHI_MCP_ENDPOINT` | No | `wss://api.xiaozhi.me/mcp/` | Xiaozhi WebSocket endpoint |
223296

224297
*Required for auto-login and default operations
225298

@@ -289,11 +362,38 @@ python main.py
289362

290363
## ✨ Features
291364

365+
-**Unified Entry Point** - Single `main.py` supports both stdio and WebSocket clients
366+
-**Environment Controlled** - Switch modes via `ENABLE_XIAOZHI` environment variable
367+
-**Multi-Client Support** - Simultaneous Claude/Cursor + Xiaozhi access
292368
-**Secure Authentication** - RSA encrypted password transmission
293369
-**Session Management** - Persistent sessions across multiple NAS devices
294370
-**Complete File Operations** - Create, delete, list, search, rename, move files with detailed metadata
295371
-**Directory Management** - Recursive directory operations with safety checks
296372
-**Download Station** - Complete torrent and download management
297373
-**Docker Support** - Easy containerized deployment
298-
-**Multi-Client Support** - Works with Claude, Continue, Cursor, Codeium and more
299-
-**Error Handling** - Comprehensive error reporting and recovery
374+
-**Backward Compatible** - Existing configurations work unchanged
375+
-**Error Handling** - Comprehensive error reporting and recovery
376+
377+
## 🏗️ Architecture
378+
379+
### File Structure
380+
```
381+
mcp-server-synology/
382+
├── main.py # 🎯 Unified entry point
383+
├── src/
384+
│ ├── mcp_server.py # Standard MCP server
385+
│ ├── multiclient_bridge.py # Multi-client bridge
386+
│ ├── auth/ # Authentication modules
387+
│ ├── filestation/ # File operations
388+
│ └── downloadstation/ # Download management
389+
├── docker-compose.yml # Single service, environment-controlled
390+
├── Dockerfile
391+
├── requirements.txt
392+
└── .env # Configuration
393+
```
394+
395+
### Mode Selection
396+
- **`ENABLE_XIAOZHI=false`**`main.py``mcp_server.py` (stdio only)
397+
- **`ENABLE_XIAOZHI=true`**`main.py``multiclient_bridge.py``mcp_server.py` (both clients)
398+
399+
**Perfect for any workflow - from simple Claude/Cursor usage to advanced multi-client setups!** 🚀

docker-compose.yml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
1-
version: '3.8'
2-
31
services:
2+
# Synology MCP Server with optional Xiaozhi support
3+
# Set ENABLE_XIAOZHI=true in .env to enable both Xiaozhi and Claude/Cursor
4+
# Set ENABLE_XIAOZHI=false (or omit) for Claude/Cursor only
45
synology-mcp:
56
build: .
67
container_name: synology-mcp-server
8+
command: ["python", "main.py"]
79
network_mode: host # Allow access to local network (192.168.x.x)
810
environment:
9-
# Override these in .env file or here
11+
- ENABLE_XIAOZHI=${ENABLE_XIAOZHI:-false}
12+
- XIAOZHI_TOKEN=${XIAOZHI_TOKEN}
13+
- XIAOZHI_MCP_ENDPOINT=${XIAOZHI_MCP_ENDPOINT:-wss://api.xiaozhi.me/mcp/}
1014
- SYNOLOGY_URL=${SYNOLOGY_URL:-http://192.168.1.10:5000}
1115
- SYNOLOGY_USERNAME=${SYNOLOGY_USERNAME:-your_username}
1216
- SYNOLOGY_PASSWORD=${SYNOLOGY_PASSWORD:-your_password}
1317
- AUTO_LOGIN=${AUTO_LOGIN:-true}
1418
- DEBUG=${DEBUG:-false}
1519
- VERIFY_SSL=${VERIFY_SSL:-false}
20+
env_file:
21+
- .env
1622
volumes:
17-
# Mount .env file if you want to use it
23+
- ./logs:/app/logs
1824
- ./.env:/app/.env:ro
1925
stdin_open: true
2026
tty: true
21-
# For MCP, we typically don't need port mapping since it uses stdio
22-
# ports:
23-
# - "8000:8000"
24-
restart: unless-stopped
27+
restart: unless-stopped
28+
healthcheck:
29+
test: ["CMD", "python", "-c", "import sys; sys.exit(0)"]
30+
interval: 30s
31+
timeout: 10s
32+
retries: 3
33+
start_period: 10s
34+
logging:
35+
driver: "json-file"
36+
options:
37+
max-size: "10m"
38+
max-file: "3"

env.example

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,11 @@ VERIFY_SSL=false # Set to true if your NAS has valid SSL certificate
1717

1818
# Optional: Debug settings
1919
DEBUG=false
20-
LOG_LEVEL=INFO
20+
LOG_LEVEL=INFO
21+
22+
# Xiaozhi MCP Integration (optional)
23+
# Set to true to enable both Xiaozhi (WebSocket) and Claude/Cursor (stdio) support
24+
# Set to false or omit for Claude/Cursor only mode
25+
ENABLE_XIAOZHI=false
26+
XIAOZHI_TOKEN=your_xiaozhi_token_here
27+
XIAOZHI_MCP_ENDPOINT=wss://api.xiaozhi.me/mcp/

0 commit comments

Comments
 (0)