@ebowwa/mcp-terminal 1.0.8

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,148 @@
1
+ # Terminal MCP Recursive Loop Bug Analysis
2
+
3
+ ## Date: 2026-02-05
4
+ ## Team: terminal-mcp-fix
5
+ ## Status: Analysis Complete
6
+
7
+ ---
8
+
9
+ ## Bug Description
10
+
11
+ The `execSSHTool` function in `/packages/src/terminal/mcp/stdio.ts` has a **parameter order mismatch** causing recursive loop behavior.
12
+
13
+ ### Location of Bug
14
+
15
+ **File:** `/packages/src/terminal/mcp/stdio.ts`
16
+ **Line:** 223-225
17
+
18
+ ```typescript
19
+ async function execSSHTool(host: string, command: string, options?: Partial<SSHOptions>): Promise<string> {
20
+ try {
21
+ const result = await execSSH(host, command, options); // ❌ WRONG PARAMETER ORDER
22
+ return result.stdout || result.stderr || "Command executed";
23
+ ```
24
+
25
+ ### Root Cause
26
+
27
+ **Function Signature Mismatch:**
28
+
29
+ The `execSSH` function from `client.ts` expects:
30
+ ```typescript
31
+ export async function execSSH(
32
+ command: string, // 1st param: command string
33
+ options: SSHOptions, // 2nd param: SSH options including host
34
+ ): Promise<string>
35
+ ```
36
+
37
+ But `execSSHTool` calls it with:
38
+ ```typescript
39
+ execSSH(host, command, options) // ❌ WRONG
40
+ ```
41
+
42
+ ### Impact
43
+
44
+ 1. **Wrong command execution:** The `host` string is executed as a shell command
45
+ 2. **Options misinterpretation:** The actual `command` is treated as SSH options
46
+ 3. **Potential recursion:** If options contain objects that trigger re-execution
47
+ 4. **Silent failures:** Errors may be masked by fallback return values
48
+
49
+ ---
50
+
51
+ ## Fix Required
52
+
53
+ ### Option 1: Fix the call (RECOMMENDED)
54
+
55
+ ```typescript
56
+ async function execSSHTool(host: string, command: string, options?: Partial<SSHOptions>): Promise<string> {
57
+ try {
58
+ const result = await execSSH(command, { // ✅ CORRECT ORDER
59
+ ...options,
60
+ host,
61
+ });
62
+ return result.stdout || result.stderr || "Command executed";
63
+ } catch (error) {
64
+ throw new Error(`SSH command failed: ${error}`);
65
+ }
66
+ }
67
+ ```
68
+
69
+ ### Option 2: Change function signature (ALTERNATIVE)
70
+
71
+ ```typescript
72
+ async function execSSHTool(command: string, options: SSHOptions): Promise<string> {
73
+ try {
74
+ const result = await execSSH(command, options); // ✅ MATCHES SIGNATURE
75
+ return result.stdout || result.stderr || "Command executed";
76
+ } catch (error) {
77
+ throw new Error(`SSH command failed: ${error}`);
78
+ }
79
+ }
80
+ ```
81
+
82
+ ---
83
+
84
+ ## Test Coverage
85
+
86
+ ### Test Suite Location
87
+
88
+ `/packages/src/terminal/mcp/test-fix.sh`
89
+
90
+ ### Test Cases
91
+
92
+ 1. **Server Startup:** Verify MCP server starts without errors
93
+ 2. **No Recursion:** Execute safe commands and detect infinite loops
94
+ 3. **Memory Leaks:** Monitor memory growth over multiple executions
95
+ 4. **Parameter Validation:** Test missing/invalid parameter handling
96
+ 5. **Tool Discovery:** Verify `exec_ssh` appears in tools list
97
+
98
+ ### Safe Test Commands
99
+
100
+ ```bash
101
+ echo 'test' # Safe echo
102
+ whoami # Current user
103
+ pwd # Current directory
104
+ uname -m # Machine architecture
105
+ date +%s # Unix timestamp
106
+ ```
107
+
108
+ ---
109
+
110
+ ## Risk Assessment
111
+
112
+ ### Severity: HIGH
113
+
114
+ - **Impact:** Can execute hostnames as shell commands
115
+ - **Scope:** Affects all `exec_ssh` tool calls via MCP
116
+ - **Exploitability:** High if user-provided hosts are not validated
117
+
118
+ ### Mitigation
119
+
120
+ 1. Apply fix immediately to `stdio.ts`
121
+ 2. Add unit tests for parameter validation
122
+ 3. Add integration tests for exec_ssh tool
123
+ 4. Review all MCP tool implementations for similar issues
124
+
125
+ ---
126
+
127
+ ## Related Files
128
+
129
+ - `/packages/src/terminal/mcp/stdio.ts` - **NEEDS FIX**
130
+ - `/packages/src/terminal/mcp/index.ts` - May have same issue
131
+ - `/packages/src/terminal/client.ts` - Reference implementation
132
+ - `/packages/src/terminal/mcp/test-fix.sh` - Test suite
133
+
134
+ ---
135
+
136
+ ## Next Steps
137
+
138
+ 1. ✅ Analysis complete
139
+ 2. ⏳ Fixers implementing fix
140
+ 3. ⏳ Testers running test suite
141
+ 4. ⏳ Verify no regression
142
+ 5. ⏳ Deploy to production
143
+
144
+ ---
145
+
146
+ **Author:** Test Engineer
147
+ **Reviewed by:** team-lead
148
+ **Priority:** CRITICAL
@@ -0,0 +1,67 @@
1
+ # Terminal MCP Fix - Quick Reference
2
+
3
+ ## TL;DR
4
+
5
+ **File:** `stdio.ts` line 225
6
+ **Bug:** Wrong parameter order to `execSSH()`
7
+ **Fix:** Swap parameters to match function signature
8
+
9
+ ---
10
+
11
+ ## The Fix
12
+
13
+ ### BEFORE (Line 223-225):
14
+ ```typescript
15
+ async function execSSHTool(host: string, command: string, options?: Partial<SSHOptions>): Promise<string> {
16
+ try {
17
+ const result = await execSSH(host, command, options); // ❌ WRONG
18
+ ```
19
+
20
+ ### AFTER:
21
+ ```typescript
22
+ async function execSSHTool(host: string, command: string, options?: Partial<SSHOptions>): Promise<string> {
23
+ try {
24
+ const result = await execSSH(command, { // ✅ CORRECT
25
+ ...options,
26
+ host,
27
+ });
28
+ ```
29
+
30
+ ---
31
+
32
+ ## Why This Works
33
+
34
+ The `execSSH` function signature is:
35
+ ```typescript
36
+ execSSH(command: string, options: SSHOptions)
37
+ ```
38
+
39
+ So we need to pass:
40
+ 1. `command` as first parameter
41
+ 2. Object with `host` field merged with `options` as second parameter
42
+
43
+ ---
44
+
45
+ ## Same Issue in index.ts
46
+
47
+ **File:** `index.ts` line 215
48
+
49
+ Same fix needed there too!
50
+
51
+ ---
52
+
53
+ ## Testing
54
+
55
+ After fix, run:
56
+ ```bash
57
+ cd /Users/ebowwa/Desktop/codespaces/packages/src/terminal/mcp
58
+ ./test-fix.sh
59
+ ```
60
+
61
+ ---
62
+
63
+ ## Status
64
+
65
+ - ✅ Analysis complete
66
+ - ⏳ Fix pending
67
+ - ⏳ Test suite ready
package/README.md ADDED
@@ -0,0 +1,181 @@
1
+ # Terminal MCP Server
2
+
3
+ Model Context Protocol server for terminal session management, SSH operations, tmux integration, and file operations.
4
+
5
+ ## Features
6
+
7
+ - **Session Management**: Create, list, manage terminal sessions
8
+ - **SSH Operations**: Execute commands, test connections, manage SSH pool
9
+ - **Tmux Integration**: List and manage tmux sessions
10
+ - **File Operations**: List, upload, download files via SCP
11
+ - **PTY Operations**: Create and manage PTY sessions
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ bun install
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### Start the MCP Server
22
+
23
+ ```bash
24
+ # Default port 8913
25
+ bun run mcp
26
+
27
+ # Custom port
28
+ MCP_PORT=8914 bun run mcp
29
+
30
+ # Dev mode (with port 8913)
31
+ bun run mcp-dev
32
+ ```
33
+
34
+ ### Available Tools
35
+
36
+ #### Session Management
37
+
38
+ | Tool | Description | Arguments |
39
+ |------|-------------|------------|
40
+ | `list_sessions` | List all active terminal sessions | none |
41
+ | `get_session_info` | Get detailed info about a session | `session_id` |
42
+ | `create_session` | Create a new terminal session | `host`, `type?`, `command?` |
43
+ | `write_command` | Write a command to a session | `session_id`, `command` |
44
+ | `resize_session` | Resize a session terminal | `session_id`, `rows`, `cols` |
45
+ | `close_session` | Close a terminal session | `session_id` |
46
+
47
+ #### SSH Operations
48
+
49
+ | Tool | Description | Arguments |
50
+ |------|-------------|------------|
51
+ | `exec_ssh` | Execute command via SSH | `host`, `command`, `options?` |
52
+ | `test_connection` | Test SSH connection | `host` |
53
+
54
+ #### Tmux Operations
55
+
56
+ | Tool | Description | Arguments |
57
+ |------|-------------|------------|
58
+ | `list_tmux_sessions` | List all tmux sessions | none |
59
+
60
+ #### File Operations
61
+
62
+ | Tool | Description | Arguments |
63
+ |------|-------------|------------|
64
+ | `list_files` | List files on remote host | `host`, `path?` |
65
+ | `upload_file` | Upload file via SCP | `host`, `local_path`, `remote_path` |
66
+ | `download_file` | Download file via SCP | `host`, `remote_path`, `local_path` |
67
+
68
+ #### Connection Management
69
+
70
+ | Tool | Description | Arguments |
71
+ |------|-------------|------------|
72
+ | `get_active_connections` | Get active SSH connections | none |
73
+
74
+ ## API Endpoints
75
+
76
+ ### Health Check
77
+
78
+ ```bash
79
+ curl http://localhost:8913/health
80
+ ```
81
+
82
+ Response:
83
+ ```json
84
+ {
85
+ "status": "ok",
86
+ "port": 8913,
87
+ "service": "terminal-mcp"
88
+ }
89
+ ```
90
+
91
+ ### List Available Tools
92
+
93
+ ```bash
94
+ curl http://localhost:8913/mcp
95
+ ```
96
+
97
+ ### Execute Tool
98
+
99
+ ```bash
100
+ curl -X POST http://localhost:8913/mcp \
101
+ -H "Content-Type: application/json" \
102
+ -d '{
103
+ "tool": "list_sessions",
104
+ "args": {}
105
+ }'
106
+ ```
107
+
108
+ ## Examples
109
+
110
+ ### List All Sessions
111
+
112
+ ```bash
113
+ curl -X POST http://localhost:8913/mcp \
114
+ -H "Content-Type: application/json" \
115
+ -d '{"tool": "list_sessions"}'
116
+ ```
117
+
118
+ ### Create SSH Session
119
+
120
+ ```bash
121
+ curl -X POST http://localhost:8913/mcp \
122
+ -H "Content-Type: application/json" \
123
+ -d '{
124
+ "tool": "create_session",
125
+ "args": {
126
+ "host": "user@server.com",
127
+ "type": "ssh"
128
+ }
129
+ }'
130
+ ```
131
+
132
+ ### Execute SSH Command
133
+
134
+ ```bash
135
+ curl -X POST http://localhost:8913/mcp \
136
+ -H "Content-Type: application/json" \
137
+ -d '{
138
+ "tool": "exec_ssh",
139
+ "args": {
140
+ "host": "user@server.com",
141
+ "command": "ls -la"
142
+ }
143
+ }'
144
+ ```
145
+
146
+ ### List Tmux Sessions
147
+
148
+ ```bash
149
+ curl -X POST http://localhost:8913/mcp \
150
+ -H "Content-Type: application/json" \
151
+ -d '{"tool": "list_tmux_sessions"}'
152
+ ```
153
+
154
+ ### Upload File
155
+
156
+ ```bash
157
+ curl -X POST http://localhost:8913/mcp \
158
+ -H "Content-Type: application/json" \
159
+ -d '{
160
+ "tool": "upload_file",
161
+ "args": {
162
+ "host": "user@server.com",
163
+ "local_path": "/local/file.txt",
164
+ "remote_path": "/remote/file.txt"
165
+ }
166
+ }'
167
+ ```
168
+
169
+ ## Integration with Claude
170
+
171
+ This MCP server can be integrated with Claude Code or other MCP-compatible clients to provide terminal management capabilities.
172
+
173
+ ## Dependencies
174
+
175
+ - `node-ssh`: SSH client functionality
176
+ - `hono`: HTTP server framework
177
+ - `zod`: Schema validation
178
+
179
+ ## License
180
+
181
+ MIT