Skip to main content
Glama

MCP SSH Server with Streamable HTTP

by timetetng
STREAMABLE_HTTP_UPGRADE.md11.4 kB
--- ## 🚀 **部署步骤** ### **方式1: 一键部署** ```bash # 设置环境变量 export GITHUB_TOKEN="your_github_token" export AUTH_TOKEN="your_secure_token" # 一键部署 curl -sSL https://raw.githubusercontent.com/timetetng/mcpssh-streamable/main/deploy-streamable.sh | sudo -E bash ``` ### **方式2: 手动部署** ```bash # 1. 克隆项目 git clone https://github.com/timetetng/mcpssh-streamable.git cd mcpssh-streamable # 2. 安装依赖 npm install # 3. 构建项目 npm run build # 4. 设置环境变量 export MCP_AUTH_TOKEN="your_secure_token" # 5. 启动两种服务 npm run start:all ``` ### **方式3: 现有项目升级** ```bash # 1. 进入现有项目目录 cd mcpssh # 2. 更新依赖 npm install hono fetch-to-node # 3. 创建Streamable HTTP服务器 # 复制上面的代码到 src/mcp-streamable-http-server.ts # 4. 更新package.json脚本 # 5. 启动双服务 npm run start:all ``` --- ## 🔧 **测试验证** ### **1. 服务状态检查** ```bash # 检查服务状态 sudo systemctl status mcp-ssh sudo systemctl status mcp-ssh-streamable # 检查端口 netstat -tlnp | grep :3000 # 标准HTTP netstat -tlnp | grep :3001 # Streamable HTTP ``` ### **2. 健康检查** ```bash # 标准HTTP健康检查 curl http://localhost:3000/health # Streamable HTTP健康检查 curl http://localhost:3001/health ``` ### **3. MCP客户端测试** **标准HTTP客户端测试**: ```bash # 测试标准HTTP MCP连接 curl -X POST \ -H "Authorization: Bearer YOUR_TOKEN" \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' \ http://localhost:3000/mcp ``` **Streamable HTTP客户端测试**: ```bash # 测试Streamable HTTP MCP连接 curl -X POST \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' \ http://localhost:3001/mcp ``` ### **4. 实际SSH操作测试** 在你的MCP客户端中配置Streamable HTTP端点,然后测试: ``` 连接到192.168.1.100,用户名ubuntu,密码password,然后检查磁盘使用情况 ``` --- ## 📋 **客户端配置示例** ### **标准HTTP客户端(传统)** ```json { "mcpServers": { "mcpssh": { "command": "node", "args": ["./dist/client-proxy.js"], "env": { "MCP_REMOTE_URL": "http://YOUR_SERVER_IP:3000/mcp", "MCP_AUTH_TOKEN": "YOUR_AUTH_TOKEN_HERE" } } } } ``` ### **Streamable HTTP客户端(你的SSE客户端)** ```json { "mcpServers": { "mcpssh-streamable": { "url": "http://YOUR_SERVER_IP:3001/mcp" } } } ``` ### **混合客户端(同时使用两种)** ```json { "mcpServers": { "mcpssh-standard": { "command": "node", "args": ["./dist/client-proxy.js"], "env": { "MCP_REMOTE_URL": "http://YOUR_SERVER_IP:3000/mcp", "MCP_AUTH_TOKEN": "YOUR_AUTH_TOKEN_HERE" } }, "mcpssh-streamable": { "url": "http://YOUR_SERVER_IP:3001/mcp" } } } ``` --- ## 🔧 **部署脚本 - deploy-streamable.sh** 创建 `deploy-streamable.sh` 脚本: ```bash #!/bin/bash # MCP SSH Server Streamable HTTP - Ubuntu Deployment Script set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color print_status() { echo -e "${GREEN}[✓]${NC} $1" } print_error() { echo -e "${RED}[✗]${NC} $1" exit 1 } # Configuration REPO_URL="${REPO_URL:-https://github.com/timetetng/mcpssh-streamable.git}" APP_USER="mcpssh" APP_DIR="/var/lib/mcpssh/app" NODE_VERSION="18" MCP_PORT="${MCP_PORT:-3000}" STREAMABLE_PORT="${STREAMABLE_PORT:-3001}" CUSTOM_AUTH_TOKEN="${AUTH_TOKEN:-}" GITHUB_TOKEN="${GITHUB_TOKEN:-}" echo "==================================" echo "MCP SSH Server Streamable Deployment" echo "==================================" echo "" # Check if running as root if [[ $EUID -ne 0 ]]; then print_error "This script must be run as root (use sudo)" fi # Step 1: Update system print_status "Updating system packages..." apt update && apt upgrade -y >/dev/null 2>&1 # Step 2: Install Node.js print_status "Installing Node.js ${NODE_VERSION}..." if ! command -v node &> /dev/null; then curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash - >/dev/null 2>&1 apt install -y nodejs >/dev/null 2>&1 fi print_status "Node.js $(node --version) installed" # Step 3: Install dependencies print_status "Installing required packages..." apt install -y git ufw >/dev/null 2>&1 # Step 4: Create application user print_status "Creating application user..." if ! id "$APP_USER" &>/dev/null; then useradd -r -s /bin/bash -m -d /var/lib/mcpssh $APP_USER fi # Step 5: Clone repository print_status "Cloning repository..." if [ -d "$APP_DIR" ]; then print_status "Updating existing installation..." cd $APP_DIR if [ -n "$GITHUB_TOKEN" ]; then sudo -u $APP_USER git pull https://$GITHUB_TOKEN@github.com/timetetng/mcpssh-streamable.git main else sudo -u $APP_USER git pull fi else if [ -n "$GITHUB_TOKEN" ]; then sudo -u $APP_USER git clone https://$GITHUB_TOKEN@github.com/timetetng/mcpssh-streamable.git $APP_DIR else print_error "This is a private repository. Please set GITHUB_TOKEN environment variable." fi fi # Step 6: Install dependencies and build print_status "Installing dependencies and building..." cd $APP_DIR sudo -u $APP_USER npm install >/dev/null 2>&1 sudo -u $APP_USER npm run build >/dev/null 2>&1 # Step 7: Set authentication token print_status "Setting authentication token..." if [ -n "$CUSTOM_AUTH_TOKEN" ]; then AUTH_TOKEN="$CUSTOM_AUTH_TOKEN" print_status "Using provided AUTH_TOKEN" else AUTH_TOKEN=$(openssl rand -hex 32) print_status "Generated new AUTH_TOKEN" fi # Create .env file cat > $APP_DIR/.env << EOF MCP_PORT=$MCP_PORT STREAMABLE_PORT=$STREAMABLE_PORT MCP_AUTH_TOKEN=$AUTH_TOKEN EOF chown $APP_USER:$APP_USER $APP_DIR/.env chmod 600 $APP_DIR/.env # Step 8: Create systemd service for standard HTTP print_status "Creating standard HTTP service..." cat > /etc/systemd/system/mcp-ssh.service << 'EOF' [Unit] Description=MCP SSH HTTP Server After=network.target [Service] Type=simple User=mcpssh Group=mcpssh WorkingDirectory=/var/lib/mcpssh/app Environment="NODE_ENV=production" EnvironmentFile=/var/lib/mcpssh/app/.env ExecStart=/usr/bin/node /var/lib/mcpssh/app/dist/mcp-http-server.js Restart=always RestartSec=10 [Install] WantedBy=multi-user.target EOF # Step 9: Create systemd service for Streamable HTTP print_status "Creating Streamable HTTP service..." cat > /etc/systemd/system/mcp-ssh-streamable.service << 'EOF' [Unit] Description=MCP SSH Streamable HTTP Server After=network.target [Service] Type=simple User=mcpssh Group=mcpssh WorkingDirectory=/var/lib/mcpssh/app Environment="NODE_ENV=production" EnvironmentFile=/var/lib/mcpssh/app/.env ExecStart=/usr/bin/npx tsx /var/lib/mcpssh/app/src/mcp-streamable-http-server.ts Restart=always RestartSec=10 [Install] WantedBy=multi-user.target EOF # Step 10: Configure firewall print_status "Configuring firewall..." ufw allow 22/tcp >/dev/null 2>&1 # SSH ufw allow $MCP_PORT/tcp >/dev/null 2>&1 # Standard HTTP MCP ufw allow $STREAMABLE_PORT/tcp >/dev/null 2>&1 # Streamable HTTP MCP echo "y" | ufw enable >/dev/null 2>&1 # Step 11: Enable and start services print_status "Starting MCP SSH services..." systemctl daemon-reload systemctl enable mcp-ssh >/dev/null 2>&1 systemctl start mcp-ssh systemctl enable mcp-ssh-streamable >/dev/null 2>&1 systemctl start mcp-ssh-streamable # Wait for services to start sleep 3 # Check services if systemctl is-active --quiet mcp-ssh; then print_status "Standard HTTP service is running on port $MCP_PORT" else print_error "Failed to start standard HTTP service" fi if systemctl is-active --quiet mcp-ssh-streamable; then print_status "Streamable HTTP service is running on port $STREAMABLE_PORT" else print_error "Failed to start Streamable HTTP service" fi # Step 12: Create convenience scripts print_status "Creating convenience scripts..." cat > /usr/local/bin/mcp-ssh-status << 'EOF' #!/bin/bash echo "=== MCP SSH Services Status ===" echo "" echo "Standard HTTP Service:" systemctl status mcp-ssh --no-pager -l echo "" echo "Streamable HTTP Service:" systemctl status mcp-ssh-streamable --no-pager -l echo "" echo "=== Service Logs ===" echo "Standard HTTP (last 10 lines):" journalctl -u mcp-ssh -n 10 --no-pager echo "" echo "Streamable HTTP (last 10 lines):" journalctl -u mcp-ssh-streamable -n 10 --no-pager EOF chmod +x /usr/local/bin/mcp-ssh-status cat > /usr/local/bin/mcp-ssh-restart << 'EOF' #!/bin/bash echo "Restarting MCP SSH services..." systemctl restart mcp-ssh systemctl restart mcp-ssh-streamable sleep 2 /usr/local/bin/mcp-ssh-status EOF chmod +x /usr/local/bin/mcp-ssh-restart # Get server IP SERVER_IP=$(ip route get 1 | awk '{print $7;exit}') # Print summary echo "" echo "==================================" echo -e "${GREEN}Deployment Completed Successfully!${NC}" echo "==================================" echo "" echo "Server Details:" echo " - Server IP: $SERVER_IP" echo " - Standard HTTP Port: $MCP_PORT" echo " - Streamable HTTP Port: $STREAMABLE_PORT" echo " - Services Status:" systemctl is-active mcp-ssh && echo " ✓ Standard HTTP: Running" || echo " ✗ Standard HTTP: Failed" systemctl is-active mcp-ssh-streamable && echo " ✓ Streamable HTTP: Running" || echo " ✗ Streamable HTTP: Failed" echo "" echo -e "${YELLOW}IMPORTANT - Save this information:${NC}" echo "" echo "Authentication Token:" echo -e "${GREEN}$AUTH_TOKEN${NC}" echo "" echo "Client Configurations:" echo "" echo "=== Standard HTTP (兼容传统客户端) ===" echo '{"mcpServers": {"mcpssh": {"command": "node", "args": ["/path/to/mcpssh/dist/client-proxy.js"], "env": {"MCP_REMOTE_URL": "http://'$SERVER_IP':$MCP_PORT/mcp", "MCP_AUTH_TOKEN": "'$AUTH_TOKEN'"}}}}' echo "" echo "=== Streamable HTTP (你的SSE客户端) ===" echo '{"mcpServers": {"mcpssh-streamable": {"url": "http://'$SERVER_IP':$STREAMABLE_PORT/mcp"}}}' echo "" echo "Useful Commands:" echo " - Check status: mcp-ssh-status" echo " - Restart services: mcp-ssh-restart" echo " - View logs: journalctl -u mcp-ssh -f" echo " - View Streamable logs: journalctl -u mcp-ssh-streamable -f" echo " - Update application: cd $APP_DIR && git pull && npm run build" echo "" echo "Security Notes:" echo " - Firewall configured for ports $MCP_PORT and $STREAMABLE_PORT" echo " - To restrict access: ufw delete allow $MCP_PORT/tcp && ufw delete allow $STREAMABLE_PORT/tcp" echo " - Then: ufw allow from YOUR_IP to any port $MCP_PORT proto tcp" echo " ufw allow from YOUR_IP to any port $STREAMABLE_PORT proto tcp" echo "" ``` --- ## ✅ **完整文档总结** 这个方案为你提供了: 1. **🔄 向后兼容** - 保留原有标准HTTP功能 2. **⚡ 流式支持** - 添加Streamable HTTP满足你的SSE客户端 3. **🔧 工具完整** - 所有SSH操作在两种模式下都可使用 4. **🚀 易于部署** - 一键部署脚本自动化所有配置 5. **📊 双服务架构** - 独立运行,互不干扰 6. **🔍 监控便利** - 提供状态检查和日志查看命令 这样你就可以同时使用传统客户端和你的SSE Streamable HTTP客户端了! 按步骤照着改就行,行简!有不明白的地方再问菲比~

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/timetetng/mcpssh-streamable'

If you have feedback or need assistance with the MCP directory API, please join our Discord server