Skip to main content
Glama
nickgnd

Tmux MCP Server

by nickgnd

get-command-result

Retrieve output from a previously executed command in a tmux session to access terminal results for AI-assisted analysis and control.

Instructions

Get the result of an executed command

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandIdYesID of the executed command

Implementation Reference

  • The handler function that implements the core logic of the 'get-command-result' tool. It fetches the command status using tmux.checkCommandStatus, handles pending/completed/error states, and returns formatted text content.
    async ({ commandId }) => {
      try {
        // Check and update command status
        const command = await tmux.checkCommandStatus(commandId);
    
        if (!command) {
          return {
            content: [{
              type: "text",
              text: `Command not found: ${commandId}`
            }],
            isError: true
          };
        }
    
        // Format the response based on command status
        let resultText;
        if (command.status === 'pending') {
          if (command.result) {
            resultText = `Status: ${command.status}\nCommand: ${command.command}\n\n--- Message ---\n${command.result}`;
          } else {
            resultText = `Command still executing...\nStarted: ${command.startTime.toISOString()}\nCommand: ${command.command}`;
          }
        } else {
          resultText = `Status: ${command.status}\nExit code: ${command.exitCode}\nCommand: ${command.command}\n\n--- Output ---\n${command.result}`;
        }
    
        return {
          content: [{
            type: "text",
            text: resultText
          }]
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error retrieving command result: ${error}`
          }],
          isError: true
        };
      }
    }
  • src/index.ts:394-443 (registration)
    Registration of the 'get-command-result' MCP tool using server.tool, including name, description, input schema, and handler reference.
    server.tool(
      "get-command-result",
      "Get the result of an executed command",
      {
        commandId: z.string().describe("ID of the executed command")
      },
      async ({ commandId }) => {
        try {
          // Check and update command status
          const command = await tmux.checkCommandStatus(commandId);
    
          if (!command) {
            return {
              content: [{
                type: "text",
                text: `Command not found: ${commandId}`
              }],
              isError: true
            };
          }
    
          // Format the response based on command status
          let resultText;
          if (command.status === 'pending') {
            if (command.result) {
              resultText = `Status: ${command.status}\nCommand: ${command.command}\n\n--- Message ---\n${command.result}`;
            } else {
              resultText = `Command still executing...\nStarted: ${command.startTime.toISOString()}\nCommand: ${command.command}`;
            }
          } else {
            resultText = `Status: ${command.status}\nExit code: ${command.exitCode}\nCommand: ${command.command}\n\n--- Output ---\n${command.result}`;
          }
    
          return {
            content: [{
              type: "text",
              text: resultText
            }]
          };
        } catch (error) {
          return {
            content: [{
              type: "text",
              text: `Error retrieving command result: ${error}`
            }],
            isError: true
          };
        }
      }
    );
  • Zod input schema for the tool, defining the required 'commandId' parameter.
    {
      commandId: z.string().describe("ID of the executed command")
    },
  • Core helper function checkCommandStatus that polls the tmux pane content, parses start/end markers to extract output and exit code, updating the command execution status in the activeCommands map.
    export async function checkCommandStatus(commandId: string): Promise<CommandExecution | null> {
      const command = activeCommands.get(commandId);
      if (!command) return null;
    
      if (command.status !== 'pending') return command;
    
      const content = await capturePaneContent(command.paneId, 1000);
    
      if (command.rawMode) {
        command.result = 'Status tracking unavailable for rawMode commands. Use capture-pane to monitor interactive apps instead.';
        return command;
      }
    
      // Find the last occurrence of the markers
      const startIndex = content.lastIndexOf(startMarkerText);
      const endIndex = content.lastIndexOf(endMarkerPrefix);
    
      if (startIndex === -1 || endIndex === -1 || endIndex <= startIndex) {
        command.result = "Command output could not be captured properly";
        return command;
      }
    
      // Extract exit code from the end marker line
      const endLine = content.substring(endIndex).split('\n')[0];
      const endMarkerRegex = new RegExp(`${endMarkerPrefix}(\\d+)`);
      const exitCodeMatch = endLine.match(endMarkerRegex);
    
      if (exitCodeMatch) {
        const exitCode = parseInt(exitCodeMatch[1], 10);
    
        command.status = exitCode === 0 ? 'completed' : 'error';
        command.exitCode = exitCode;
    
        // Extract output between the start and end markers
        const outputStart = startIndex + startMarkerText.length;
        const outputContent = content.substring(outputStart, endIndex).trim();
    
        command.result = outputContent.substring(outputContent.indexOf('\n') + 1).trim();
    
        // Update in map
        activeCommands.set(commandId, command);
      }
    
      return command;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but offers minimal behavioral context. It doesn't disclose whether this is a read-only operation, whether it requires specific permissions, if it works for both completed and ongoing commands, or what format the result returns. The description is too vague about the actual behavior beyond the basic action.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise at just 6 words, front-loading the essential information with zero wasted text. Every word earns its place, making it easy to parse while conveying the core functionality.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool that presumably retrieves command execution results, the description is insufficient given the lack of annotations and output schema. It doesn't explain what constitutes a 'result' (output, exit code, status), whether it works for synchronous or asynchronous commands, or how it relates to sibling tools. The minimal description leaves too many contextual gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the single parameter 'commandId' clearly documented. The description doesn't add any meaningful semantic context beyond what the schema already provides about needing an executed command's ID. Baseline 3 is appropriate when schema coverage is complete.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get') and resource ('result of an executed command'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'execute-command' or 'capture-pane', which might have overlapping functionality in a command execution context.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'execute-command' and 'capture-pane' that might handle command execution or output capture, there's no indication whether this tool is for retrieving results after execution, monitoring ongoing commands, or accessing historical outputs.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/nickgnd/tmux-mcp'

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