Skip to main content
Glama
Rxuser2

Roblox MCP Unified Server

by Rxuser2
README.md
# ๐Ÿš€ Roblox MCP Node.js Server

[![Node.js](https://img.shields.io/badge/Node.js-18+-green.svg)](https://nodejs.org/)
[![Express](https://img.shields.io/badge/Express-4.x-lightgrey.svg)](https://expressjs.com/)
[![SQLite](https://img.shields.io/badge/SQLite-3-blue.svg)](https://sqlite.org/)
[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

**Comprehensive MCP Server untuk Roblox Development** - Solusi Node.js yang stabil dan siap produksi untuk semua kebutuhan Roblox development workflow.

## โœจ Key Features

### ๐Ÿ› ๏ธ **Complete Roblox Tool Suite (8 Tools)**
- โœ… `create_script` - Create new Lua/Luau scripts
- โœ… `list_scripts` - List all scripts in project  
- โœ… `update_script` - Update existing scripts
- โœ… `delete_script` - Delete scripts
- โœ… `get_project_status` - Get project statistics
- โœ… `validate_script` - Validate script syntax dan security
- โœ… `backup_project` - Create project backups
- โœ… `restore_project` - Restore from backups

### ๐Ÿš€ **Production Ready**
- ๐Ÿ“ฆ **Built-in Client Library** - Include client functionality dalam server package
- ๐Ÿ” **HMAC Authentication** - Secure API communication
- ๐Ÿ—„๏ธ **SQLite Database** - Persistent script storage
- ๐Ÿณ **Docker Deployment** - Ready untuk containerization
- ๐Ÿš‚ **Railway Deployment** - Cloud deployment ready
- ๐Ÿ“Š **Comprehensive Logging** - Full operation tracking
- โšก **High Performance** - Node.js + Express optimized

### ๐Ÿ›ก๏ธ **Security & Reliability**
- ๐Ÿ”’ **Rate Limiting** - Prevent abuse
- ๐Ÿ›ก๏ธ **Security Headers** - Helmet.js protection
- โœ… **Input Validation** - Joi schema validation
- ๐Ÿ” **HMAC Signing** - Request authenticity verification
- ๐Ÿšจ **Error Handling** - Graceful failure recovery

### ๐ŸŽฎ **Web Dashboard Interface**
- ๐ŸŒ **Modern Web Interface** - Beautiful dashboard untuk manajemen semua tools
- ๐Ÿ“ฑ **Fully Responsive** - Perfect di desktop, tablet, dan mobile
- ๐ŸŽจ **Professional Design** - Dark/Light theme dengan smooth animations
- โšก **Real-time Updates** - Live data dan auto-refresh capabilities
- ๐Ÿ“Š **Analytics Dashboard** - Charts dan insights untuk project monitoring
- ๐Ÿ” **Advanced Search** - Filter dan search scripts dengan mudah
- ๐Ÿ’พ **One-click Backup** - Manajemen backup dan restore yang mudah
- ๐Ÿ” **Secure Settings** - Konfigurasi HMAC secret dengan interface yang user-friendly

## ๐Ÿš€ Quick Start

### Prerequisites
- Node.js 18+ installed
- npm atau yarn package manager

### Installation
```bash
# Clone atau extract server files
cd roblox-mcp-nodejs

# Install dependencies
npm install

# Initialize database
npm run db:init

# Start server (development)
npm run dev

# Start server (production)
npm start
```

### Basic Usage

#### ๐ŸŒ **Web Interface (Recommended)**
```bash
# Start the server
npm start

# Buka browser dan navigasi ke:
http://localhost:3000

# Configure HMAC secret di Settings
# Enjoy the beautiful dashboard!
```

#### ๐Ÿ“ก **API Testing**
```bash
# Test dengan basic usage
node examples/basic-usage.js

# Test dengan advanced usage
node examples/advanced-usage.js

# Test dengan production usage
node examples/production-usage.js
```

### ๐ŸŽฎ **Web Dashboard Features**

**Dashboard Sections:**
- ๐Ÿ“Š **Overview** - Project statistics dan quick actions
- ๐Ÿ“ **Script Manager** - Create, edit, delete scripts dengan interface yang modern
- ๐Ÿ’พ **Backup & Restore** - One-click backup management
- ๐Ÿ“ˆ **Analytics** - Visual charts dan insights

**Key Benefits:**
- โœ… No command-line experience required
- โœ… Real-time script preview dengan syntax highlighting  
- โœ… Advanced search dan filtering
- โœ… Mobile-friendly responsive design
- โœ… Secure authentication configuration
- โœ… Beautiful animations dan micro-interactions

> ๐Ÿ“– **Detailed Guide**: Lihat [Web Interface Guide](docs/WEB-INTERFACE-GUIDE.md) untuk dokumentasi lengkap

## ๐Ÿ› ๏ธ Available Tools

### 1. `create_script` 
Create new Roblox scripts dengan validation

**Parameters:**
- `name` (str): Script name (unique identifier)
- `content` (str): Script content (Lua/Luau code)  
- `script_type` (str, optional): 'lua' or 'luau' (default: 'lua')
- `project_id` (str, optional): Project identifier (default: 'default')

**Example:**
```bash
curl -X POST http://localhost:3000/api/create_script \
  -H "Content-Type: application/json" \
  -H "X-Signature: your_signature" \
  -d '{
    "name": "PlayerController",
    "content": "local Players = game:GetService(\"Players\")",
    "script_type": "lua",
    "project_id": "game_project_001"
  }'
```

### 2. `list_scripts`
List all scripts dalam project dengan metadata

**Example:**
```bash
curl -X GET "http://localhost:3000/api/list_scripts?project_id=default" \
  -H "X-Signature: your_signature"
```

### 3. `update_script`
Update existing script content

### 4. `delete_script` 
Delete script from database

### 5. `get_project_status`
Get comprehensive project statistics dan health

### 6. `validate_script`
Validate script content untuk syntax, security, dan best practices

### 7. `backup_project`
Create complete project backup dengan metadata

### 8. `restore_project`
Restore project dari backup file

## ๐Ÿš‚ Railway Deployment

### Prerequisites
1. GitHub repository dengan kode ini
2. Railway account di https://railway.app

### Step-by-Step Deployment

#### 1. **Setup GitHub Repository**
```bash
# Initialize git (jika belum)
git init
git add .
git commit -m "Initial commit: Roblox MCP Node.js Server"
git branch -M main
git remote add origin https://github.com/yourusername/roblox-mcp-nodejs.git
git push -u origin main
```

#### 2. **Deploy ke Railway**
1. **Login** ke Railway (https://railway.app)
2. **Click "New Project"**
3. **Select "Deploy from GitHub repo"**
4. **Choose** repository `roblox-mcp-nodejs`
5. **Click "Deploy Now"**

#### 3. **Configure Environment Variables**

Di Railway dashboard, pergi ke **Variables** tab dan add:

```bash
# Required Configuration
NODE_ENV=production
PORT=3000

# Database Configuration
DB_PATH=./data/roblox_mcp.db

# HMAC Security (CRITICAL - generate secure secret!)
ROBLOX_MCP_HMAC_SECRET=your_very_secure_hmac_secret_32_chars_minimum

# Logging
LOG_LEVEL=info
ROBLOX_MCP_VERBOSE=false

# Rate Limiting
ENABLE_RATE_LIMITING=true
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100

# Security
ENABLE_SECURITY_HEADERS=true
CORS_ORIGIN=*
```

#### 4. **Custom Build Command (Optional)**
Di Railway, pergi ke **Settings** > **Build** dan set:

```bash
Build Command: npm ci --only=production
```

#### 5. **Deploy**
1. **Click "Deploy"** di Railway
2. **Wait** untuk deployment selesai (~2-3 menit)
3. **Copy Public URL** dari Railway dashboard
4. **Test** dengan: `curl http://your-app.railway.app/health`

### Railway Configuration File (railway.json)
```json
{
  "build": {
    "builder": "NIXPACKS"
  },
  "deploy": {
    "startCommand": "npm start",
    "restartPolicyType": "ON_FAILURE",
    "restartPolicyMaxRetries": 10
  }
}
```

## ๐Ÿณ Docker Deployment

### Local Docker Run
```bash
# Build image
docker build -f docker/Dockerfile -t roblox-mcp-server .

# Run container
docker run -p 3000:3000 \
  -e ROBLOX_MCP_HMAC_SECRET=your_hmac_secret \
  -v roblox_data:/app/data \
  roblox-mcp-server
```

### Docker Compose (Recommended)
```bash
# Start services
docker-compose -f docker/docker-compose.yml up -d

# View logs
docker-compose -f docker/docker-compose.yml logs -f

# Stop services
docker-compose -f docker/docker-compose.yml down
```

## โš™๏ธ Configuration

### Environment Variables

| Variable | Required | Default | Description |
|----------|----------|---------|-------------|
| `NODE_ENV` | No | `development` | Environment mode |
| `PORT` | No | `3000` | Server port |
| `DB_PATH` | No | `./data/roblox_mcp.db` | Database file path |
| `ROBLOX_MCP_HMAC_SECRET` | Yes | - | HMAC secret for authentication |
| `ROBLOX_MCP_VERBOSE` | No | `false` | Enable verbose logging |
| `ENABLE_RATE_LIMITING` | No | `true` | Enable rate limiting |
| `RATE_LIMIT_WINDOW_MS` | No | `900000` | Rate limit window in ms |
| `RATE_LIMIT_MAX_REQUESTS` | No | `100` | Max requests per window |
| `LOG_LEVEL` | No | `info` | Log level |
| `CORS_ORIGIN` | No | `*` | CORS origin |

### Example .env File
```bash
# Production Configuration
NODE_ENV=production
PORT=3000
DB_PATH=./data/roblox_mcp.db
ROBLOX_MCP_HMAC_SECRET=your_very_secure_production_secret_32_chars_minimum
ROBLOX_MCP_VERBOSE=false
ENABLE_RATE_LIMITING=true
LOG_LEVEL=info
CORS_ORIGIN=*

# Development Configuration  
NODE_ENV=development
ROBLOX_MCP_HMAC_SECRET=dev_secret_123
ROBLOX_MCP_VERBOSE=true
LOG_LEVEL=debug
```

## ๐Ÿ“š API Reference

### Authentication

Semua API requests harus include HMAC signature:

```javascript
const crypto = require('crypto');

function generateSignature(data, secret) {
  return crypto
    .createHmac('sha256', secret)
    .update(data, 'utf8')
    .digest('hex');
}

// Headers yang diperlukan:
'X-Signature': generatedSignature
'X-Timestamp': Date.now().toString()
'Content-Type': 'application/json'
```

### Response Format

**Success Response:**
```json
{
  "success": true,
  "message": "Operation completed successfully",
  "data": { ... },
  "timestamp": "2025-11-03T10:08:05.000Z"
}
```

**Error Response:**
```json
{
  "success": false,
  "error": "Error description",
  "code": "ERROR_CODE"
}
```

### Health Check
```bash
GET /health
```

Response:
```json
{
  "status": "healthy",
  "timestamp": "2025-11-03T10:08:05.000Z",
  "uptime": 1234,
  "memory": { ... },
  "version": "1.0.0"
}
```

## ๐Ÿงช Testing

### Unit Tests
```bash
# Test all functionality
npm test

# Test specific functionality
node examples/basic-usage.js
node examples/advanced-usage.js
node examples/production-usage.js
```

### API Testing
```bash
# Health check
curl http://localhost:3000/health

# Create script
curl -X POST http://localhost:3000/api/create_script \
  -H "Content-Type: application/json" \
  -H "X-Signature: your_signature" \
  -d '{"name":"test","content":"print(\"Hello\")"}'

# List scripts
curl -X GET "http://localhost:3000/api/list_scripts" \
  -H "X-Signature: your_signature"
```

## ๐Ÿ”ง Troubleshooting

### Common Issues

#### 1. **Database Connection Error**
```
Error: SQLITE_CANTOPEN: unable to open database file
```
**Solution:**
```bash
# Check database directory permissions
ls -la data/
# Fix permissions
chmod 755 data/
# Or specify full path
export DB_PATH=/full/path/to/roblox_mcp.db
```

#### 2. **HMAC Authentication Failed**
```
Error: Invalid signature
```
**Solution:**
```bash
# Verify HMAC secret matches between client and server
echo "Client Secret: $ROBLOX_MCP_HMAC_SECRET"
echo "Server Secret: $(grep ROBLOX_MCP_HMAC_SECRET .env)"

# Ensure timestamp is recent (< 5 minutes)
const timestamp = Date.now(); // Should be current time
```

#### 3. **Port Already in Use**
```
Error: listen EADDRINUSE :::3000
```
**Solution:**
```bash
# Kill process using port 3000
lsof -ti:3000 | xargs kill -9

# Or use different port
export PORT=3001
```

#### 4. **Permission Denied (Docker)**
```
Error: EACCES: permission denied
```
**Solution:**
```bash
# Fix file permissions in container
docker exec -u root roblox-mcp-server chown -R roblox:nodejs /app
# Or mount with correct permissions
docker run -v $(pwd)/data:/app/data roblox-mcp-server
```

### Debug Mode
```bash
# Enable debug logging
export LOG_LEVEL=debug
export ROBLOX_MCP_VERBOSE=true
npm start
```

### Health Monitoring
```bash
# Monitor server health
watch -n 5 'curl -s http://localhost:3000/health | jq .'

# Monitor logs
tail -f logs/app.log
```

## ๐Ÿ—๏ธ Architecture

```
roblox-mcp-nodejs/
โ”œโ”€โ”€ src/                       # Backend server
โ”‚   โ”œโ”€โ”€ server.js              # Main Express server
โ”‚   โ”œโ”€โ”€ database.js            # SQLite database service
โ”‚   โ”œโ”€โ”€ config.js              # Configuration management
โ”‚   โ”œโ”€โ”€ robloxToolsService.js  # Roblox tools implementation
โ”‚   โ””โ”€โ”€ client.js              # Built-in client library
โ”œโ”€โ”€ public/                    # Web Interface (NEW!)
โ”‚   โ”œโ”€โ”€ index.html             # Main dashboard application
โ”‚   โ”œโ”€โ”€ css/                   # Modern UI styles
โ”‚   โ”‚   โ”œโ”€โ”€ style.css          # Core styling
โ”‚   โ”‚   โ”œโ”€โ”€ components.css     # Component styles
โ”‚   โ”‚   โ””โ”€โ”€ animations.css     # Smooth animations
โ”‚   โ”œโ”€โ”€ js/                    # Frontend JavaScript
โ”‚   โ”‚   โ”œโ”€โ”€ config.js          # App configuration
โ”‚   โ”‚   โ”œโ”€โ”€ api.js             # API communication
โ”‚   โ”‚   โ”œโ”€โ”€ ui.js              # UI management
โ”‚   โ”‚   โ”œโ”€โ”€ charts.js          # Analytics charts
โ”‚   โ”‚   โ””โ”€โ”€ main.js            # Main application
โ”‚   โ””โ”€โ”€ assets/                # Static resources
โ”œโ”€โ”€ examples/                  # API usage examples
โ”‚   โ”œโ”€โ”€ basic-usage.js         # Basic functionality tests
โ”‚   โ”œโ”€โ”€ advanced-usage.js      # Advanced usage patterns
โ”‚   โ””โ”€โ”€ production-usage.js    # Production deployment tests
โ”œโ”€โ”€ docs/                      # Documentation
โ”‚   โ”œโ”€โ”€ WEB-INTERFACE-GUIDE.md # Web interface documentation
โ”‚   โ””โ”€โ”€ RAILWAY-DEPLOYMENT.md  # Deployment guides
โ”œโ”€โ”€ docker/                    # Docker configuration
โ”‚   โ”œโ”€โ”€ Dockerfile             # Container definition
โ”‚   โ”œโ”€โ”€ docker-compose.yml     # Multi-service setup
โ”‚   โ””โ”€โ”€ nginx/                 # Reverse proxy config
โ”œโ”€โ”€ data/                      # Database files
โ”œโ”€โ”€ logs/                      # Application logs
โ”œโ”€โ”€ backups/                   # Project backups
โ”œโ”€โ”€ package.json               # Dependencies
โ””โ”€โ”€ README.md                  # This file
```

## ๐Ÿ”„ Migration from Python Version

Untuk user yang migrasi dari Python version:

### API Compatibility
API endpoints tetap sama, hanya base URL berubah:
```bash
# Python version
POST /tools/create_script

# Node.js version  
POST /api/create_script
```

### Client Update
```javascript
// Python MCP client
from roblox_mcp import create_script

// Node.js MCP client
const RobloxMCPClient = require('roblox-mcp-nodejs/src/client');
const client = new RobloxMCPClient(baseUrl, hmacSecret);
await client.createScript(name, content, scriptType, projectId);
```

### Database Migration
Database structure tetap sama, tidak perlu migration.

## ๐Ÿค Contributing

1. **Fork** repository
2. **Create** feature branch (`git checkout -b feature/AmazingFeature`)
3. **Commit** changes (`git commit -m 'Add some AmazingFeature'`)
4. **Push** to branch (`git push origin feature/AmazingFeature`)
5. **Open** Pull Request

## ๐Ÿ“ License

Distributed under the MIT License. See `LICENSE` for more information.

## ๐Ÿ†˜ Support

- ๐Ÿ“– **Documentation**: Check this README
- ๐Ÿงช **Testing**: Run test suite sebelum deployment
- ๐Ÿš€ **Deployment**: Follow Railway deployment guide
- ๐Ÿ› **Issues**: Report bugs dengan detailed reproduction steps

## ๐Ÿ† Acknowledgments

- **Express.js** - For the excellent web framework
- **Node.js** - For the powerful runtime environment
- **SQLite** - For reliable embedded database
- **Roblox Development Community** - For API insights and best practices
- **MiniMax Agent** - For comprehensive development and testing

---

**Ready untuk production deployment!** ๐Ÿš€

*Built dengan โค๏ธ untuk Roblox developers*

### Quick Links:
- [๐ŸŽฎ Web Interface Guide](docs/WEB-INTERFACE-GUIDE.md) - Beautiful dashboard documentation
- [๐Ÿš€ Railway Deployment Guide](#-railway-deployment)
- [๐Ÿณ Docker Setup](#-docker-deployment)
- [๐Ÿ“š API Documentation](#-api-reference)
- [๐Ÿงช Testing Guide](#-testing)