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"]
            }
          }
        ]
      };
    });
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