remote-debug-mcp 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,315 @@
1
+ Metadata-Version: 2.4
2
+ Name: remote-debug-mcp
3
+ Version: 0.2.0
4
+ Summary: MCP server for remote debugging via SSH and Telnet with persistent background connections
5
+ Project-URL: Homepage, https://github.com/user/remote-debug-mcp
6
+ Project-URL: Repository, https://github.com/user/remote-debug-mcp
7
+ Project-URL: Issues, https://github.com/user/remote-debug-mcp/issues
8
+ License: MIT License
9
+
10
+ Copyright (c) 2025
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+ License-File: LICENSE
30
+ Keywords: android,debugging,mcp,remote-debug,serial,ssh,telnet
31
+ Classifier: Development Status :: 4 - Beta
32
+ Classifier: Intended Audience :: Developers
33
+ Classifier: License :: OSI Approved :: MIT License
34
+ Classifier: Operating System :: OS Independent
35
+ Classifier: Programming Language :: Python :: 3
36
+ Classifier: Programming Language :: Python :: 3.10
37
+ Classifier: Topic :: Software Development :: Debuggers
38
+ Classifier: Topic :: System :: Networking
39
+ Requires-Python: >=3.10
40
+ Requires-Dist: mcp>=1.0.0
41
+ Requires-Dist: pexpect>=4.8
42
+ Description-Content-Type: text/markdown
43
+
44
+ # Remote Debug MCP
45
+
46
+ 基于 MCP (Model Context Protocol) 的远程调试服务器,支持 **SSH** 和 **Telnet** 后台持久化连接,专为远程串口调试和 Android/Linux 设备管理设计。
47
+
48
+ ## 功能
49
+
50
+ - **SSH** — 持续后台连接远程服务器/Windows PC,支持命令执行、SCP/SFTP 文件传输、MD5 完整性校验、自动重连
51
+ - **Telnet** — 持续后台连接,支持数据收发、串口数据监听、后台监控保存
52
+ - **com2tcp** — 一键桥接 Windows COM 串口到 TCP Telnet,远程调试串口设备
53
+ - **配置文件** — YAML 文件预设连接参数,`ssh_connect(config_name="xxx")` 一键连接
54
+
55
+ ## 安装
56
+
57
+ ```bash
58
+ # 克隆到 ~/.config 目录(推荐,与配置文件路径一致)
59
+ mkdir -p ~/.config
60
+ git clone https://github.com/zxyyzwd/remote_debug_mcp.git ~/.config/remote_debug_mcp
61
+ cd ~/.config/remote_debug_mcp
62
+
63
+ # 虚拟环境安装
64
+ python3 -m venv .venv && source .venv/bin/activate && pip install -e .
65
+
66
+ # 或直接安装
67
+ pip install -e .
68
+ ```
69
+
70
+ 依赖:Python ≥ 3.10 · pexpect · mcp
71
+
72
+ ## 配置客户端
73
+
74
+ ### OpenCode
75
+
76
+ `~/.config/opencode/opencode.jsonc`:
77
+
78
+ ```jsonc
79
+ {
80
+ "mcp": {
81
+ "remote-debug": {
82
+ "type": "local",
83
+ "command": ["python3", "-m", "remote_debug_mcp"],
84
+ "enabled": true,
85
+ "timeout": 60000
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ ### Claude Code
92
+
93
+ `~/.claude.json`:
94
+
95
+ ```json
96
+ {
97
+ "mcp": {
98
+ "remote-debug": {
99
+ "command": "python3",
100
+ "args": ["-m", "remote_debug_mcp"],
101
+ "enabled": true,
102
+ "timeout": 60000
103
+ }
104
+ }
105
+ }
106
+ ```
107
+
108
+ 也可用命令行添加:
109
+
110
+ ```bash
111
+ claude mcp add remote-debug python3 -- -m remote_debug_mcp
112
+ ```
113
+
114
+ > 使用虚拟环境时,将 `python3` 替换为虚拟机环境中的 Python 路径。
115
+
116
+ 配置后重启客户端即可使用。
117
+
118
+ ## 连接配置
119
+
120
+ ### YAML 配置文件
121
+
122
+ `config.yaml` 放在工作目录或仓库根目录,首次调用 `ssh_connect(config_name=...)` 时自动加载并缓存。
123
+
124
+ `config.yaml` 默认搜索路径:
125
+ - `./config.yaml`(当前工作目录)
126
+ - `<source_dir>/config.yaml`(源码目录)
127
+ - `<source_dir>/../config.yaml`(`src/` 父目录)
128
+ - `<repo_root>/config.yaml`(仓库根目录)
129
+ - `<repo_root>/src/remote_debug_mcp/config.yaml`(源码包目录)
130
+ - `~/.config/remote-debug-mcp/config.yaml`(用户全局配置)
131
+
132
+ ```yaml
133
+ connections:
134
+ # ── SSH 连接 ──────────────────────
135
+ - name: "office-pc" # 连接名称,后续引用用
136
+ type: ssh
137
+ host: "192.168.1.16" # 远程 IP
138
+ port: 22 # SSH 端口
139
+ username: "zxyyz" # 用户名
140
+ password: "kaixin123" # 密码(明文,仅本地使用)
141
+
142
+ - name: "office-pc-key" # 密钥认证
143
+ type: ssh
144
+ host: "192.168.1.16"
145
+ username: "admin"
146
+ key_file: "/home/me/.ssh/id_rsa"
147
+
148
+ # ── 串口映射 ──────────────────────
149
+ - name: "serial-com4" # com2tcp 桥接配置
150
+ type: com2tcp
151
+ ssh: "office-pc" # 引用上面的 SSH 连接名(用于解析 host)
152
+ com_port: "COM4" # Windows COM 口
153
+ telnet_port: 5200 # 暴露的 Telnet 端口
154
+ baud: 115200 # 波特率(默认 115200)
155
+ # 以下为可选参数(均有默认值)
156
+ # username: "" # Telnet 登录用户名
157
+ # password: "" # Telnet 登录密码
158
+ # connect_timeout: 15 # 连接超时(秒)
159
+ # buffer_max_size: 65536 # 缓冲区大小(字节,默认 64KB)
160
+ # max_retries: 3 # 自动重连次数
161
+ ```
162
+
163
+ 使用:
164
+
165
+ ```
166
+ ssh_connect → config_name: "office-pc" # 自动从 config.yaml 读参数连接
167
+ list_connections # 查看已加载的配置
168
+ save_config # 保存当前内存配置
169
+ save_config → connections: [{...}] # 创建/更新配置条目(无配置文件时的唯一入库入口)
170
+ ```
171
+
172
+ ## com2tcp 串口调试工作流
173
+
174
+ ### 远程环境要求
175
+
176
+ 远程 Windows PC 需满足以下条件,否则 `setup_com2tcp` 将失败:
177
+
178
+ | 依赖 | 说明 | 安装方式 |
179
+ |------|------|----------|
180
+ | **Python >= 3.8** | 运行 com2telnet.py 串口转 TCP 服务 | [python.org](https://www.python.org/downloads/) 下载,**勾选 "Add Python to PATH"** |
181
+ | **pip** | 安装 pyserial 依赖 | 随 Python 一同安装 |
182
+ | **pyserial** | 串口通信库 | `setup_com2tcp` 自动 `pip install` |
183
+ | **防火墙放行** | Telnet 端口(如 5200)需入站放行 TCP | `setup_com2tcp` 执行时自动通过 SSH 放行,或手动配置 |
184
+
185
+ 安装 Python 后验证:
186
+
187
+ ```powershell
188
+ python --version
189
+ pip --version
190
+ ```
191
+
192
+ `setup_com2tcp` 会自动上传 `com2telnet.py` + `pyproject.toml` 到 `D:\remote-debug\com2telnet\` 并安装依赖,无需手动操作。
193
+
194
+ 如果远程机器无 Python,可通过 SSH 自动下载安装:
195
+
196
+ ```powershell
197
+ Invoke-WebRequest -Uri "https://www.python.org/ftp/python/3.11.9/python-3.11.9-amd64.exe" -OutFile "$env:TEMP\python-installer.exe"
198
+ Start-Process -Wait -FilePath "$env:TEMP\python-installer.exe" -ArgumentList "/quiet", "InstallAllUsers=1", "PrependPath=1"
199
+ ```
200
+
201
+ ### 架构
202
+
203
+ ```
204
+ ┌──────────┐ SSH (PowerShell) ┌──────────────────┐
205
+ │ MCP │ ──────────────────▶ │ Windows PC │
206
+ │ Server │ │ COM4 → :5200 │
207
+ │ │ Telnet :5200 │ ↑ │
208
+ │ │ ◀────────────────── │ 串口设备 │
209
+ └──────────┘ └──────────────────┘
210
+ ```
211
+
212
+ ```
213
+ 1. ssh_connect → config_name: "office-pc" # SSH 到 Windows PC
214
+ 2. setup_com2tcp → ssh_session_id: "...", com_port: "COM4", telnet_port: 5200
215
+ 3. save_config → connections: [{name: "serial-com4", type: "com2tcp", ...}] # 持久化配置
216
+ 4. telnet_connect → session_id: "serial", config_name: "serial-com4" # 所有参数从配置解析
217
+ 5. telnet_send → data: "ls", timeout: 3
218
+ 6. telnet_listen → duration: 10
219
+ 7. telnet_start_monitor → output_file: "serial.log" # 后台持续记录
220
+ ```
221
+
222
+ ## 工具参考
223
+
224
+ ### SSH(6 个)
225
+
226
+ | 工具 | 说明 |
227
+ |------|------|
228
+ | `ssh_connect` | 通过 config_name 从 config.yaml 读取参数连接(密码/密钥自适应) |
229
+ | `ssh_execute` | 执行命令(自动适配 bash/PowerShell,中文编码正确) |
230
+ | `ssh_upload` | 上传文件(SCP → SFTP 降级,自动 MD5 校验) |
231
+ | `ssh_download` | 下载文件(SCP → SFTP 降级,自动 MD5 校验) |
232
+ | `ssh_disconnect` | 关闭会话 |
233
+ | `ssh_list` | 列出所有 SSH 会话 |
234
+
235
+ ### Telnet(5 个)
236
+
237
+ | 工具 | 说明 |
238
+ |------|------|
239
+ | `telnet_connect` | 通过 config_name 连接(host/port/login/buffer/retries 全从配置解析) |
240
+ | `telnet_send` | 发送数据(timeout=0 发后即返,timeout>0 等响应;`__CTRL_C__`/`__CTRL_D__`/`__CTRL_Z__`;普通数据自动追加 `\r`) |
241
+ | `telnet_listen` | 监听指定秒数,返回新数据(支持 utf-8/base64/hex 编码) |
242
+ | `telnet_disconnect` | 关闭会话 |
243
+ | `telnet_list` | 列出所有 Telnet 会话 |
244
+
245
+ ### Telnet 监控(2 个)
246
+
247
+ | 工具 | 说明 |
248
+ |------|------|
249
+ | `telnet_start_monitor` | 启动后台持续监听(可选持续写入文件) |
250
+ | `telnet_stop_monitor` | 停止后台监听,返回累计行数 |
251
+
252
+ ### 配置(2 个)
253
+
254
+ | 工具 | 说明 |
255
+ |------|------|
256
+ | `list_connections` | 列出已加载配置中的所有 SSH 和 com2tcp 连接 |
257
+ | `save_config` | **配置唯一入库入口**:无参保存内存配置;带 `connections` 参数创建/更新条目后写入文件 |
258
+
259
+ ### 工作流(1 个)
260
+
261
+ | 工具 | 说明 |
262
+ |------|------|
263
+ | `setup_com2tcp` | 完整 com2tcp 工作流(上传 + 启动 + 验证),完成后提示调 `save_config` 持久化 |
264
+
265
+ ### 通用(1 个)
266
+
267
+ | 工具 | 说明 |
268
+ |------|------|
269
+ | `list_sessions` | 列出所有 SSH + Telnet 会话 |
270
+
271
+ ## 架构
272
+
273
+ ```
274
+ src/
275
+ ├── remote_debug_mcp/
276
+ │ ├── server.py # MCP 服务端:17 个工具定义 + 分发
277
+ │ ├── sessions.py # SSH/Telnet 会话生命周期管理
278
+ │ ├── config_loader.py # YAML 配置文件加载/保存
279
+ │ ├── config.example.yaml
280
+ │ ├── __init__.py
281
+ │ └── __main__.py
282
+ └── remote/ # 上传远程服务器的 Python 脚本
283
+ ├── pyproject.toml # 远程工具安装配置
284
+ └── com2telnet.py # 串口转 Telnet 服务端
285
+ ```
286
+
287
+ ## 技术要点
288
+
289
+ - SSH 使用 `pexpect.spawn('ssh', ...)` 直连,**不使用 pxssh**(避免 Windows 提示符兼容问题)
290
+ - SSH pexpect `encoding=None` 原始字节模式
291
+ - **Windows 双路径编码**:`-T` 无 PTY 模式用 **GBK** 编码,`-t` PTY 回退模式建立后执行 `chcp 65001` 切换 **UTF-8** 编码
292
+ - Linux 统一 UTF-8 编解码
293
+ - Windows 连接后尝试切 PowerShell,成功后走交互式命令执行;失败则回退 CMD + one-shot 模式(每次命令新起 SSH),适配不同 SSH 服务端配置
294
+ - 命令输出通过 `echo` 唯一标记分隔,不依赖 shell 提示符
295
+ - Windows 自动切换到 PowerShell,工作目录 `D:\remote_debug`
296
+ - 文件传输 SCP 优先 → SFTP 兜底,传输后自动 MD5 校验
297
+ - Telnet `telnet_send` 使用 echo-marker 策略(`command; echo __MCP_{ts}__`),命令执行完即刻返回,不再盲等 timeout 秒
298
+ - Telnet `telnet_stop_monitor` 移除阻塞 `join()`,不再阻塞事件循环
299
+ - Telnet 缓冲区 64KB(可配),支持 utf-8/base64/hex 编码
300
+ - Telnet 后台监听:deque 行缓存 90 万行(FIFO),可选持续写入文件
301
+ - 自动重连:指数退避,默认最多 3 次
302
+ - 配置自动缓存内存,`save_config` 持久化到 YAML
303
+
304
+ 详细设计参见 [DESIGN.md](DESIGN.md)
305
+
306
+ ## 变更日志
307
+
308
+ ### v0.2.0
309
+
310
+ - **Windows 双路径编码**:`-T` 无 PTY 模式仍用 GBK,`-t` PTY 回退模式切换为 UTF-8(建立后执行 `chcp 65001`),解决 server12 等 PTY 机器中文乱码
311
+ - **Telnet 命令 latency 优化**:`telnet_send` 采用 echo-marker 策略(与 SSH 统一),命令执行完即刻返回,不再盲等 timeout 秒
312
+ - **Telnet 监控无阻塞**:`telnet_stop_monitor` 移除 `join()` 调用,不再阻塞事件循环 3 秒
313
+ - **com2telnet 广播优化**:`_broadcast()` 改用 `asyncio.gather()` 并发 drain,慢客户端不再阻塞其他客户端
314
+ - **SSH 命令轮询**:输出轮询间隔 300ms → 100ms,命令响应延迟降低 3 倍
315
+ - 连接日志新增 `[pty/no-pty]` `[powershell/cmd]` `[gbk/utf-8]` 诊断信息
@@ -0,0 +1,11 @@
1
+ remote_debug_mcp/__init__.py,sha256=ye8y97-PQyT20seg8IIgbZzH-4lrXTTYIomuu9LMrRQ,61
2
+ remote_debug_mcp/__main__.py,sha256=oNhY2z-YMhS3zUJSgbKqSPcbEV0oqqHpYitXGW_zzMY,108
3
+ remote_debug_mcp/config_loader.py,sha256=L_PQP-dmtDV7pgznC2bgvJrnigCGbc1ZQA2TGQS30aw,7111
4
+ remote_debug_mcp/server.py,sha256=UD8J0J0RD0SGBoK9-SwnUUaBGWo-sxw1XDglayo_Tuw,29284
5
+ remote_debug_mcp/sessions.py,sha256=PF0TW583lyWo6qxblyQQiqBxUwzMTCwlBhsDACoQlmU,46122
6
+ remote_debug_mcp/config.example.yaml,sha256=iv3mGvxdDS_IqlpJhLBsev_mfjc2dLrSe0XzHxJgH4A,1129
7
+ remote_debug_mcp-0.2.0.dist-info/METADATA,sha256=4uTI42JAgaWWtB4eBapN4htgtnoqGUJCMsTn_eXxWlI,12861
8
+ remote_debug_mcp-0.2.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
9
+ remote_debug_mcp-0.2.0.dist-info/entry_points.txt,sha256=hx4G_KPgAKAkpA92pJ2eMAfsLu6W8f02OGLv7nupR5g,59
10
+ remote_debug_mcp-0.2.0.dist-info/licenses/LICENSE,sha256=Btzdu2kIoMbdSp6OyCLupB1aRgpTCJ_szMimgEnpkkE,1056
11
+ remote_debug_mcp-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.30.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ remote-debug-mcp = remote_debug_mcp:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.