terminal_execute
Execute terminal commands programmatically within an Electron application to automate system operations and retrieve command outputs through managed terminal sessions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | ||
| sessionId | Yes |
Implementation Reference
- index.js:291-328 (registration)Registers the 'terminal_execute' MCP tool with input schema for command and sessionId, and handler that proxies execution to an Electron-based API server.server.tool( "terminal_execute", { command: z.string(), sessionId: z.string() }, async ({ command, sessionId }) => { try { // Check if server is running, start if not if (!(await isServerRunning())) { await startElectronProcess(); } let response; //if (sessionId) { // Execute in existing session response = await axios.post(`${apiBaseUrl}/execute/${sessionId}`, { command }); //} else { // Create new session // response = await axios.post(`${apiBaseUrl}/execute`, { command }); //} const result = response.data; // Clean up terminal output using strip-ansi const cleanOutput = stripAnsi(result.output); return { content: [{ type: "text", text: `Session ID: ${result.sessionId}\n\n ${cleanOutput}`, exitCode: result.exitCode }], }; } catch (error) { return formatErrorResponse(error, sessionId); } } );
- index.js:297-327 (handler)Handler function for terminal_execute tool. Ensures Electron server is running, sends command to /execute/{sessionId} endpoint, strips ANSI from output, and returns formatted response.async ({ command, sessionId }) => { try { // Check if server is running, start if not if (!(await isServerRunning())) { await startElectronProcess(); } let response; //if (sessionId) { // Execute in existing session response = await axios.post(`${apiBaseUrl}/execute/${sessionId}`, { command }); //} else { // Create new session // response = await axios.post(`${apiBaseUrl}/execute`, { command }); //} const result = response.data; // Clean up terminal output using strip-ansi const cleanOutput = stripAnsi(result.output); return { content: [{ type: "text", text: `Session ID: ${result.sessionId}\n\n ${cleanOutput}`, exitCode: result.exitCode }], }; } catch (error) { return formatErrorResponse(error, sessionId); } }
- index.js:293-296 (schema)Zod schema defining inputs: command (string) and sessionId (string).{ command: z.string(), sessionId: z.string() },