Skip to main content
Glama
yangyu2729

console-switch-mcp

by yangyu2729
README.md
# Console Switch MCP

通过串口 Console 口(RS-232/USB-to-Serial)控制网络交换机的 MCP Server。支持华为、H3C、思科等主流品牌交换机。

## 功能

| Tool | 说明 |
|---|---|
| `list_ports` | 列出计算机所有可用串口(COM口) |
| `connect` | 通过 Console 口连接交换机 |
| `send_command` | 发送单条命令并获取返回结果 |
| `send_config` | 批量发送配置命令 |
| `disconnect` | 断开 Console 连接 |
| `get_status` | 查看当前连接状态 |

## 支持的设备

- 华为 (Huawei) — 自动识别 `<Huawei>` / `[Huawei]` 提示符
- H3C — 自动识别 `<H3C>` / `[H3C]` 提示符
- 思科 (Cisco) — 自动识别 `Router>` / `Router#` 提示符
- 其他支持标准串口 Console 的网络设备

## 前置条件

1. **硬件**:Console 线(USB 转 RJ45/RS-232),常见芯片:FTDI、CH340、PL2303
2. **驱动**:安装对应 USB 转串口芯片的驱动程序
3. **Node.js**:>= 18.0.0

## 安装

### 1. 克隆项目

```bash
git clone https://github.com/yangyu2729/console-switch-mcp.git
cd console-switch-mcp
```

### 2. 安装依赖并构建

```bash
npm install
npm run build
```

### 3. 配置 MCP

#### WorkBuddy

编辑 `~/.workbuddy/mcp.json`,添加:

```json
{
  "mcpServers": {
    "console-switch-mcp": {
      "command": "node",
      "args": ["/你的路径/console-switch-mcp/build/index.js"],
      "disabled": false
    }
  }
}
```

> Windows 路径示例:`C:/Users/你的用户名/console-switch-mcp/build/index.js`
> macOS/Linux 路径示例:`/home/你的用户名/console-switch-mcp/build/index.js`

#### Claude Desktop

编辑配置文件:

- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`

```json
{
  "mcpServers": {
    "console-switch-mcp": {
      "command": "node",
      "args": ["/绝对路径/console-switch-mcp/build/index.js"]
    }
  }
}
```

配置完成后重启 WorkBuddy / Claude Desktop 即可生效。

## 使用

在 AI 对话中直接使用自然语言操作:

- "列出电脑上可用的串口"
- "用 COM3 连接华为交换机,波特率 9600"
- "查看交换机版本信息"
- "查看 VLAN 配置"
- "进入系统视图,配置端口"
- "断开连接"

### 常用华为交换机命令

```
display version              查看设备版本
display current-configuration 查看当前配置
display vlan                 查看 VLAN 信息
display interface brief      查看接口概要
display arp                  查看 ARP 表
display mac-address          查看 MAC 地址表
display ip routing-table     查看路由表
display cpu-usage            查看 CPU 使用率
display logbuffer            查看日志缓冲
system-view                  进入系统视图
ping 192.168.1.1             测试网络连通性
```

## 串口参数

| 参数 | 默认值 | 说明 |
|---|---|---|
| baudRate | 9600 | 华为/H3C 默认 9600,部分设备用 115200 |
| dataBits | 8 | 数据位 |
| stopBits | 1 | 停止位 |
| parity | none | 校验位 |

## 项目结构

```
console-switch-mcp/
├── src/
│   ├── index.ts           # MCP Server 入口
│   └── serial-console.ts  # 串口通信核心模块
├── build/                 # 编译输出
├── package.json
└── tsconfig.json
```

## License

MIT

TDQS

A4.2/5.0

Scored across 6 tools

Disambiguation5/5

Each tool has a clearly distinct role: listing ports, connecting/disconnecting, checking status, and sending commands (single vs. batch). The overlap between send_command and send_config is clarified by their descriptions, making misselection unlikely.

Naming Consistency4/5

Most tools follow a verb_noun pattern (list_ports, get_status, send_command, send_config), while connect and disconnect are standalone verbs. This is a minor deviation but remains predictable and readable.

Tool Count5/5

With 6 tools, the set is well-scoped for a console management server, covering the essential operations without redundancy or bloat.

Completeness5/5

The server covers the full lifecycle: discovering ports, connecting, checking status, sending individual commands, and batch configuration. No obvious gaps for typical console-based switch management.

Maintenance

ActivityStale
ResponsivenessNo issues