surge-mcp-server

surge-mcp-server

Enables natural language control of Surge proxy, including toggling features, managing policies, requests, DNS, and device settings via the Surge HTTP API.

Category
访问服务器

README

Surge MCP Server

English | 简体中文

A Model Context Protocol (MCP) server for controlling Surge proxy via its HTTP API.

Features

This MCP server provides comprehensive control over Surge proxy through the following tool categories:

Features Toggle

  • Get and toggle MITM, Capture, Rewrite, and Scripting features

Outbound Mode

  • Get and set outbound mode (direct, proxy, rule)

Proxy Policies

  • List all available policies
  • Get policy group details
  • Test policies with specific URLs
  • Set selected policy for policy groups

Request Management

  • List recent and active requests
  • Kill specific active requests

Profile Management

  • Get current profile information
  • Reload profile

DNS

  • Flush DNS cache

Modules

  • List all available modules
  • Enable/disable specific modules

Scripting

  • List all scripts
  • Evaluate scripts with mock environment

Device Management (Mac Only, Surge 4.0.6+)

  • List all active and saved devices
  • Modify device properties (name, IP address, Surge handling)

Prerequisites

  1. Surge installed and running
  2. HTTP API enabled in Surge configuration
  3. Node.js 18+ installed

Surge Configuration

Add the following to your Surge configuration file:

[General]
http-api = YOUR_API_KEY@127.0.0.1:6171

Replace YOUR_API_KEY with a secure API key of your choice.

For TLS support (optional):

http-api-tls = true
http-api-web-dashboard = true

Installation

  1. Clone this repository:
git clone https://github.com/DLYZZT/surge-mcp-server.git
cd surge_mcp
  1. Install dependencies:
npm install
  1. Build the project:
npm run build

Configuration

Set the following environment variables:

export SURGE_HOST=127.0.0.1        # Default: 127.0.0.1
export SURGE_PORT=6171              # Default: 6171
export SURGE_API_KEY=YOUR_API_KEY   # Required: Your Surge API key

Usage with Claude Desktop

Add the following to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

Windows: %APPDATA%\Claude\claude_desktop_config.json

Option 1: Using npx (Recommended)

{
  "mcpServers": {
    "surge": {
      "command": "npx",
      "args": ["-y", "surge-mcp-server"],
      "env": {
        "SURGE_HOST": "127.0.0.1",
        "SURGE_PORT": "6171",
        "SURGE_API_KEY": "YOUR_API_KEY"
      }
    }
  }
}

Option 2: Using local installation

{
  "mcpServers": {
    "surge": {
      "command": "node",
      "args": ["/path/to/surge_mcp/dist/index.js"],
      "env": {
        "SURGE_HOST": "127.0.0.1",
        "SURGE_PORT": "6171",
        "SURGE_API_KEY": "YOUR_API_KEY"
      }
    }
  }
}

Replace /path/to/surge_mcp with the actual path to this project and YOUR_API_KEY with your Surge API key.

Available Tools

Feature Management

  • surge_get_feature_status - Check status of features
  • surge_toggle_feature - Enable/disable features

Outbound Mode

  • surge_get_outbound_mode - Get current mode
  • surge_set_outbound_mode - Set mode (direct/proxy/rule)

Policy Management

  • surge_list_policies - List all policies
  • surge_get_policy_group - Get policy group details
  • surge_test_policy - Test policies with URL
  • surge_set_policy_group - Set policy for group

Request Management

  • surge_list_requests - List recent/active requests
  • surge_kill_request - Kill active request

Profile Management

  • surge_get_profile - Get current profile
  • surge_reload_profile - Reload profile

DNS

  • surge_flush_dns - Flush DNS cache

Module Management

  • surge_list_modules - List all modules
  • surge_toggle_module - Enable/disable module

Script Management

  • surge_list_scripts - List all scripts
  • surge_evaluate_script - Evaluate script with mock environment

Device Management (Mac Only, Surge 4.0.6+)

  • surge_list_devices - List all active and saved devices
  • surge_modify_device - Modify device properties

Example Usage in Claude

Once configured, you can ask Claude to control Surge:

  • "What's the current outbound mode in Surge?"
  • "Enable MITM in Surge"
  • "List all proxy policies"
  • "Set the proxy group 'Proxy' to use 'US Server'"
  • "Show me recent requests"
  • "Flush DNS cache"
  • "Reload Surge profile"
  • "List all devices in Surge" (Mac only)
  • "Rename the device with MAC address XX:XX:XX:XX:XX:XX to 'My iPhone'" (Mac only)

Development

Run in development mode with auto-rebuild:

npm run dev

Troubleshooting

Connection Issues

  • Ensure Surge is running
  • Verify HTTP API is enabled in Surge configuration
  • Check that the API key matches
  • Confirm the port number is correct

Authentication Errors

  • Double-check your API key is set correctly
  • Ensure the API key in Surge config matches the environment variable

Security Notes

  • Keep your API key secure and never commit it to version control
  • The API key grants full control over Surge
  • Consider using http-api-tls = true for encrypted communication
  • Restrict the API to localhost (127.0.0.1) unless remote access is needed

Reference

Based on the official Surge HTTP API documentation: https://manual.nssurge.com/others/http-api.html

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选