MCP Remote Server

MCP Remote Server

Enables execution of SSH commands on remote servers and management of Google Cloud Platform (GCE) instances through Cursor IDE.

Category
访问服务器

README

MCP Remote Server

A Model Context Protocol (MCP) server that enables Cursor IDE to execute SSH commands on remote servers and manage Google Cloud Platform (GCE) instances. This server provides a seamless integration between Cursor and your remote infrastructure.

Features

  • 🔐 SSH Command Execution: Run commands on remote servers via SSH
  • ☁️ GCE Instance Management: Start and stop Google Cloud Compute Engine instances
  • 🔄 Connection Pooling: Reuses SSH connections for improved performance
  • 📝 SSH Config Integration: Uses your existing ~/.ssh/config for host configuration
  • 🚀 MCP Protocol: Full support for Model Context Protocol v2025-06-18

Prerequisites

  • Node.js 16+ installed
  • SSH access configured to your remote server
  • Google Cloud Platform credentials (for GCE features)
  • Cursor IDE installed

Installation

  1. Clone or navigate to the repository:

    cd mcp-remote
    
  2. Install dependencies:

    npm install
    
  3. Start the MCP server:

    node src/index.js
    

    The server will start on http://localhost:3000 by default.

Configuration

1. SSH Configuration

First, you need to configure your SSH connection in ~/.ssh/config. The server always uses the host alias dev regardless of what you specify in prompts.

Create or edit ~/.ssh/config:

Host dev
    HostName your-server.example.com
    User your-username
    Port 22
    IdentityFile ~/.ssh/id_rsa
    # Optional: Add additional SSH options
    # ServerAliveInterval 60
    # ServerAliveCountMax 3
    # StrictHostKeyChecking no
    # UserKnownHostsFile ~/.ssh/known_hosts

Example with AWS EC2:

Host dev
    HostName ec2-12-34-56-78.compute-1.amazonaws.com
    User ubuntu
    Port 22
    IdentityFile ~/.ssh/my-aws-key.pem

Example with Google Cloud:

Host dev
    HostName 34.123.45.67
    User root
    Port 22
    IdentityFile ~/.ssh/gcp-key.pem

Important Notes:

  • The host alias must be named dev (all lowercase)
  • The server will always connect to dev regardless of the host you specify in prompts
  • Make sure your SSH key has proper permissions: chmod 600 ~/.ssh/id_rsa

2. Cursor MCP Configuration

Configure Cursor to connect to the MCP server by editing ~/.cursor/mcp.json:

{
  "mcpServers": {
    "local-mcp": {
      "name": "Local MCP",
      "url": "http://localhost:3000",
      "description": "Runs SSH commands and manages GCE instances",
      "apiKeyHeader": "x-api-key",
      "apiKeyValue": "8BOe6KshR5Eq0otTSjSGMEf5P1edKcq"
    }
  }
}

Configuration Fields:

  • name: Display name for the MCP server in Cursor
  • url: The URL where your MCP server is running (default: http://localhost:3000)
  • description: Description of what the server does
  • apiKeyHeader: Header name for API authentication (currently optional)
  • apiKeyValue: API key value for authentication (currently optional)

After modifying mcp.json:

  1. Save the file
  2. Restart Cursor IDE
  3. The MCP server should appear in Cursor's tool list

3. Environment Variables (Optional)

You can set environment variables to customize behavior:

# SSH Configuration (optional - defaults to ~/.ssh/id_rsa)
export SSH_USERNAME=your-username
export SSH_PRIVATE_KEY_PATH=~/.ssh/custom_key

# Server Configuration
export PORT=3000

# GCP Configuration (for GCE features)
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/gcp-credentials.json

Usage

Starting the Server

# Start the server
node src/index.js

# Or with custom port
PORT=8080 node src/index.js

The server will output:

MCP server running on http://localhost:3000
Ready to accept MCP connections from Cursor

Using in Cursor IDE

Once configured, you can use the MCP tools directly in Cursor:

  1. Run SSH Commands:

    • Ask Cursor: "Check disk usage on server1.example.com"
    • The server will automatically connect to dev and execute the command
    • Example: "Run df -h on my remote server"
  2. Manage GCE Instances:

    • Ask Cursor: "Start instance my-vm in project my-project, zone us-central1-a"
    • Ask Cursor: "Stop instance my-vm in project my-project, zone us-central1-a"

Available Tools

  1. run_command

    • Execute SSH commands on the remote server
    • Always connects to dev from ~/.ssh/config
    • Parameters:
      • host: Ignored (always uses dev)
      • cmdKey: The command to execute (e.g., df -h, ls -la)
  2. start_instance

    • Start a GCE instance
    • Parameters:
      • project: GCP project ID
      • zone: GCE zone (e.g., us-central1-a)
      • instance: Instance name
  3. stop_instance

    • Stop a GCE instance
    • Parameters:
      • project: GCP project ID
      • zone: GCE zone
      • instance: Instance name

Architecture

Connection Pooling

The server maintains a pool of SSH connections to improve performance:

  • Connections are reused across multiple commands
  • Connections are kept alive with keepalive settings
  • Automatic cleanup on connection errors

SSH Config Integration

The server reads connection details from ~/.ssh/config:

  • Hostname, port, username, and identity file
  • Supports all standard SSH config options
  • Handles ~ expansion in file paths
  • Supports multiple IdentityFile entries (uses the first one)

Troubleshooting

Server Won't Start

  1. Check if port is already in use:

    lsof -i :3000
    
  2. Check Node.js version:

    node --version  # Should be 16+
    

Cursor Can't Connect

  1. Verify server is running:

    curl http://localhost:3000
    
  2. Check ~/.cursor/mcp.json syntax:

    • Ensure valid JSON
    • Verify the URL matches your server
  3. Restart Cursor IDE after modifying mcp.json

SSH Connection Issues

  1. Test SSH connection manually:

    ssh dev
    
  2. Verify SSH config:

    ssh -F ~/.ssh/config dev
    
  3. Check SSH key permissions:

    ls -la ~/.ssh/id_rsa
    chmod 600 ~/.ssh/id_rsa
    
  4. Verify the host alias exists:

    grep -A 5 "^Host dev" ~/.ssh/config
    

Commands Not Executing

  1. Check server logs for error messages
  2. Verify the dev host is properly configured in ~/.ssh/config
  3. Check SSH key has access to the remote server

Development

Project Structure

mcp-remote/
├── src/
│   ├── index.js          # Main MCP server
│   ├── ssh.js            # SSH connection handling
│   └── gcp.js            # GCP instance management
├── package.json
├── README.md
└── .gitignore

Adding New Tools

To add new MCP tools:

  1. Add tool definition to the tools array in src/index.js
  2. Add handler in the tools/call case
  3. Implement the functionality in the appropriate module

Testing

# Test SSH connection
node -e "const {runRemoteCommand} = require('./src/ssh'); runRemoteCommand({host: 'dev', command: 'echo test'}).then(r => console.log(r));"

# Test MCP server
curl -X POST http://localhost:3000 \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2025-06-18"},"id":1}'

Security Considerations

  • The server runs on localhost:3000 by default (not exposed to network)
  • SSH credentials are read from ~/.ssh/config (standard SSH security)
  • API key authentication is available but currently optional
  • Consider using environment variables for sensitive data

License

[Add your license here]

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions:

  • Check the Troubleshooting section
  • Review server logs for error messages
  • Ensure SSH configuration is correct

Note: The server always connects to the dev host alias from your SSH config, regardless of the host you specify in prompts. Make sure dev is properly configured in ~/.ssh/config.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选