Skip to content

Commit 950a3e3

Browse files
committed
upd
1 parent 66292c9 commit 950a3e3

19 files changed

+780
-1076
lines changed

.env.example

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,34 @@ NODE_ENV=development
33
PORT=3001
44
HOST=0.0.0.0
55

6-
# Main IoT Cloud REST API
6+
# IoT Cloud REST API
7+
# Required: Base URL for the IoT Cloud API
78
IOT_API_BASE_URL=https://staging.openapi.rogo.com.vn/api/v2.0/iot-core
8-
IOT_API_KEY=f6883470-bd95-4e23-9ee6-51e878386451
9-
IOT_API_TIMEOUT=30000
109

11-
# Firebase Admin SDK
12-
# Option 1: Path to service account JSON file
13-
FIREBASE_SERVICE_ACCOUNT_PATH=./firebase-service-account.json
14-
# Option 2: Inline JSON (for deployment platforms like Heroku, Railway)
15-
# FIREBASE_SERVICE_ACCOUNT={"type":"service_account","project_id":"..."}
10+
# Required: API Key for authentication with IoT Cloud API
11+
IOT_API_KEY=your-api-key-here
12+
13+
# Optional: Request timeout in milliseconds (default: 30000)
14+
IOT_API_TIMEOUT=30000
1615

1716
# CORS Configuration
17+
# Enable CORS for cross-origin requests
1818
ENABLE_CORS=true
19+
20+
# Comma-separated list of allowed origins
21+
# Use * to allow all origins (not recommended for production)
1922
CORS_ORIGINS=http://localhost:3000,https://chat.openai.com,https://claude.ai
2023

2124
# Rate Limiting
25+
# Enable rate limiting to prevent abuse
2226
ENABLE_RATE_LIMIT=true
27+
28+
# Maximum number of requests per window
2329
RATE_LIMIT_MAX=100
30+
31+
# Time window in milliseconds (default: 1 minute)
2432
RATE_LIMIT_WINDOW=60000
2533

2634
# Logging
27-
LOG_LEVEL=debug
35+
# Log level: debug, info, warn, error
36+
LOG_LEVEL=info

.github/workflows/docker-build.yml

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ env:
1717
IMAGE_NAME: ${{ github.repository }}
1818

1919
jobs:
20-
2120
build-and-push:
2221
name: Build and Push Docker Image
2322
runs-on: ubuntu-latest
2423
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
25-
24+
2625
permissions:
2726
contents: read
2827
packages: write
@@ -75,3 +74,63 @@ jobs:
7574

7675
- name: Image digest
7776
run: echo ${{ steps.meta.outputs.digest }}
77+
78+
deploy:
79+
name: Deploy to VPS
80+
needs: build-and-push
81+
runs-on: ubuntu-latest
82+
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main')
83+
84+
steps:
85+
- name: Checkout code
86+
uses: actions/checkout@v4
87+
88+
- name: Setup SSH key
89+
run: |
90+
mkdir -p ~/.ssh
91+
echo "${{ secrets.VPS_KEY_BASE64 }}" | base64 -d > ~/.ssh/deploy_key
92+
chmod 600 ~/.ssh/deploy_key
93+
ssh-keyscan -p ${{ secrets.VPS_PORT }} ${{ secrets.VPS_HOST }} >> ~/.ssh/known_hosts
94+
95+
- name: Deploy to VPS via SSH
96+
run: |
97+
ssh -i ~/.ssh/deploy_key -p ${{ secrets.VPS_PORT }} ${{ secrets.VPS_USERNAME }}@${{ secrets.VPS_HOST }} << 'ENDSSH'
98+
set -e
99+
100+
# Navigate to project directory
101+
cd /opt/mcp
102+
103+
# Login to GitHub Container Registry
104+
echo ${{ secrets.GITHUB_TOKEN }} | sudo docker login ghcr.io -u ${{ github.actor }} --password-stdin
105+
106+
# Pull the latest image
107+
sudo docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
108+
109+
# Detect docker-compose version and use appropriate command
110+
if command -v docker-compose &> /dev/null; then
111+
COMPOSE_CMD="sudo docker-compose"
112+
else
113+
COMPOSE_CMD="sudo docker compose"
114+
fi
115+
116+
# Stop and remove old containers
117+
$COMPOSE_CMD down || true
118+
119+
# Start services with the new image
120+
$COMPOSE_CMD up -d
121+
122+
# Wait for services to be healthy
123+
echo "Waiting for services to start..."
124+
sleep 15
125+
126+
# Check service status
127+
$COMPOSE_CMD ps
128+
129+
# Show recent logs
130+
$COMPOSE_CMD logs --tail=50 iot-cloud-mcp
131+
132+
# Clean up old images
133+
sudo docker image prune -af --filter "until=24h"
134+
135+
echo "Deployment completed successfully!"
136+
ENDSSH

QUICKSTART.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Quick Start Guide
2+
3+
## 🚀 Get Started in 5 Minutes
4+
5+
### 1. Install Dependencies
6+
7+
```bash
8+
npm install
9+
```
10+
11+
### 2. Configure Environment
12+
13+
```bash
14+
cp .env.example .env
15+
```
16+
17+
Edit `.env` and add your IoT Cloud API credentials:
18+
19+
```env
20+
IOT_API_BASE_URL=https://staging.openapi.rogo.com.vn/api/v2.0/iot-core
21+
IOT_API_KEY=your-api-key-here
22+
```
23+
24+
### 3. Start the Server
25+
26+
```bash
27+
npm run start:dev
28+
```
29+
30+
Server will start at: **http://localhost:3001**
31+
32+
### 4. Test the Connection
33+
34+
In a new terminal, run the test script:
35+
36+
```bash
37+
node test-mcp.js
38+
```
39+
40+
You should see:
41+
42+
```
43+
✅ Connected! Status: 200
44+
✅ MCP Server initialized successfully!
45+
✅ Received 7 tools: login, get_devices, get_device, ...
46+
✅ Server is ready!
47+
🎉 All checks passed!
48+
```
49+
50+
### 5. Connect Your AI Agent
51+
52+
#### For Claude Desktop
53+
54+
Edit `~/Library/Application Support/Claude/claude_desktop_config.json`:
55+
56+
```json
57+
{
58+
"mcpServers": {
59+
"iot-cloud": {
60+
"url": "http://localhost:3001/api/mcp/sse"
61+
}
62+
}
63+
}
64+
```
65+
66+
Restart Claude Desktop, then try:
67+
68+
```
69+
You: Login to my IoT account with email user@example.com and password mypassword
70+
```
71+
72+
Claude will use the `login` tool to authenticate you!
73+
74+
## 📚 Next Steps
75+
76+
- **Read the [README.md](./README.md)** for full documentation
77+
- **Check [API Documentation](http://localhost:3001/api/docs)** for available endpoints
78+
- **Explore [MCP Protocol](./docs/MCP_PROTOCOL.md)** for technical details
79+
80+
## 🔧 Troubleshooting
81+
82+
### Server won't start
83+
84+
**Error:** `Cannot find module`
85+
86+
**Solution:**
87+
88+
```bash
89+
rm -rf node_modules package-lock.json
90+
npm install
91+
```
92+
93+
### Cannot connect to IoT API
94+
95+
**Error:** `ECONNREFUSED`
96+
97+
**Solution:**
98+
99+
- Verify `IOT_API_BASE_URL` in `.env`
100+
- Check your network/firewall settings
101+
- Test API directly: `curl https://your-api-url/health`
102+
103+
### Test script fails
104+
105+
**Error:** `Connection error`
106+
107+
**Solution:**
108+
109+
- Make sure server is running: `npm run start:dev`
110+
- Check port 3001 is not in use: `lsof -i :3001`
111+
112+
## 💡 Tips
113+
114+
1. **Use debug logging** during development:
115+
116+
```env
117+
LOG_LEVEL=debug
118+
```
119+
120+
2. **Enable CORS** for web clients:
121+
122+
```env
123+
ENABLE_CORS=true
124+
CORS_ORIGINS=http://localhost:3000
125+
```
126+
127+
3. **Increase rate limits** for testing:
128+
```env
129+
RATE_LIMIT_MAX=1000
130+
```
131+
132+
## ✅ You're Ready!
133+
134+
Your MCP server is now ready to bridge AI agents with your IoT devices!

0 commit comments

Comments
 (0)