Skip to main content
Glama
sfz009900

Kali Linux MCP Server

by sfz009900

get_command_output

Retrieve the latest output from interactive commands executed on the Kali Linux MCP Server, enabling real-time monitoring of security testing and penetration tasks.

Instructions

获取交互式命令的最新输出。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYes交互式会话ID。

Implementation Reference

  • Input schema for the get_command_output tool, defining the required session_id parameter.
    {
      name: "get_command_output",
      description: "获取交互式命令的最新输出。",
      inputSchema: {
        type: "object",
        properties: {
          session_id: {
            type: "string",
            description: "交互式会话ID。"
          }
        },
        required: ["session_id"]
      }
    },
  • Handler implementation for get_command_output. Fetches the latest output from the interactive session since the last fetch, strips ANSI codes from stdout, and returns session status including new output availability and waiting state.
    case "get_command_output": {
      const sessionId = String(request.params.arguments?.session_id);
      
      if (!sessionId) {
        throw new McpError(ErrorCode.InvalidParams, "会话ID是必需的");
      }
      
      const session = activeSessions.get(sessionId);
      if (!session) {
        throw new McpError(ErrorCode.InvalidParams, `找不到会话ID: ${sessionId}`);
      }
      
      // 增加上次获取输出的时间记录
      if (!(session as any).lastOutputFetch) {
        (session as any).lastOutputFetch = 0;
      }
      
      // 初始化lastOutputPosition(如果还没有的话)
      if (!(session as any).lastOutputPosition) {
        (session as any).lastOutputPosition = 0;
      }
    
      // 获取新输出
      const newOutput = session.stdout.substring((session as any).lastOutputPosition);
      const hasNewOutput = newOutput.length > 0;
      
      // 更新获取时间和位置
      const now = Date.now();
      const timeSinceLastFetch = now - (session as any).lastOutputFetch;
      (session as any).lastOutputFetch = now;
      (session as any).lastOutputPosition = session.stdout.length;
      
      return {
        content: [{
          type: "text",
          text: JSON.stringify({
            status: "success",
            stdout: stripAnsiCodes(newOutput), // 只返回新的输出
            stderr: session.stderr,
            has_new_output: hasNewOutput,
            time_since_last_fetch_ms: timeSinceLastFetch,
            waiting_for_input: session.isWaitingForInput
          })
        }]
      };
    }
  • src/index.ts:74-156 (registration)
    Tool registration within the ListToolsRequestSchema handler, including the tool in the list of available tools.
      return {
        tools: [
          {
            name: "execute_command",
            description: "(无需交互式比如ping 127.0.0.1)在Kali Linux渗透测试环境中执行命令。支持所有Kali Linux内置的安全测试工具和常规Linux命令。",
            inputSchema: {
              type: "object",
              properties: {
                command: {
                  type: "string",
                  description: "要在Kali Linux环境中执行的命令。可以是任何安全测试、漏洞扫描、密码破解等渗透测试命令。"
                }
              },
              required: ["command"]
            }
          },
          {
            name: "start_interactive_command",
            description: "(需要交互式比如mysql -u root -p)在Kali Linux环境中启动一个交互式命令,并返回会话ID。交互式命令可以接收用户输入,可以在不close_interactive_command的情况下同时执行execute_command。",
            inputSchema: {
              type: "object",
              properties: {
                command: {
                  type: "string",
                  description: "要在Kali Linux环境中执行的交互式命令。"
                }
              },
              required: ["command"]
            }
          },
          {
            name: "send_input_to_command",
            description: "(自行判断是AI输入还是用户手动输入)向正在运行的交互式命令发送用户输入。",
            inputSchema: {
              type: "object",
              properties: {
                session_id: {
                  type: "string",
                  description: "交互式会话ID。"
                },
                input: {
                  type: "string",
                  description: "发送给命令的输入文本。"
                },
                end_line: {
                  type: "boolean",
                  description: "是否在输入后添加换行符。默认为true。"
                }
              },
              required: ["session_id", "input"]
            }
          },
          {
            name: "get_command_output",
            description: "获取交互式命令的最新输出。",
            inputSchema: {
              type: "object",
              properties: {
                session_id: {
                  type: "string",
                  description: "交互式会话ID。"
                }
              },
              required: ["session_id"]
            }
          },
          {
            name: "close_interactive_command",
            description: "关闭交互式命令会话。",
            inputSchema: {
              type: "object",
              properties: {
                session_id: {
                  type: "string",
                  description: "交互式会话ID。"
                }
              },
              required: ["session_id"]
            }
          }
        ]
      };
    });
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states what the tool does but lacks critical behavioral details: it doesn't specify if this is a read-only operation (implied but not explicit), whether it returns only the latest output or a history, error conditions (e.g., invalid session), or performance characteristics like rate limits.

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 a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is appropriately sized and front-loaded, making it easy to parse quickly.

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?

Given the complexity (interactive command output retrieval) and lack of annotations and output schema, the description is incomplete. It doesn't explain what the output looks like (e.g., text, structured data), error handling, or dependencies on other tools like 'start_interactive_command'. For a tool with no structured behavioral hints, more context is needed.

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?

Schema description coverage is 100%, with the single parameter 'session_id' documented as '交互式会话ID' (interactive session ID). The description adds no additional parameter semantics beyond what the schema provides, such as format examples or constraints. Baseline 3 is appropriate when the schema does the heavy lifting.

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 ('获取' meaning 'get') and the resource ('交互式命令的最新输出' meaning 'latest output of interactive command'), making the purpose immediately understandable. It distinguishes from siblings like 'execute_command' (which runs commands) and 'send_input_to_command' (which sends input), but doesn't explicitly contrast with 'close_interactive_command' or 'start_interactive_command'.

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. It doesn't mention prerequisites (like needing an active session), when not to use it, or how it relates to sibling tools like 'execute_command' for non-interactive output or 'send_input_to_command' for providing input.

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

Related 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/sfz009900/kalilinuxmcp'

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