Skip to main content
Glama
nexon33

Electron Terminal MCP Server

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
NameRequiredDescriptionDefault
commandYes
sessionIdYes

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);
        }
      }
    );
  • 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);
      }
    }
  • Zod schema defining inputs: command (string) and sessionId (string).
    {
      command: z.string(),
      sessionId: z.string()
    },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nexon33/console-terminal-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server