Skip to main content
Glama
abdessamad-elamrani

MalwareAnalyzerMCP

read_output

Retrieve output from running or completed processes during malware analysis to monitor execution results and gather forensic data.

Instructions

Read output from a running or completed process.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pidYesThe process ID to read output from

Implementation Reference

  • The core handler function readOutput(pid) that retrieves output from active or completed terminal sessions, formats completed output with exit code and runtime, and returns { output: string | null }.
    readOutput(pid) {
      // First check active sessions
      const session = this.sessions.get(pid);
      if (session) {
        const output = session.lastOutput;
        session.lastOutput = ''; // Clear the buffer after reading
        return { output };
      }
    
      // Then check completed sessions
      const completedSession = this.completedSessions.get(pid);
      if (completedSession) {
        // Format completion message with exit code and runtime
        const runtime = (completedSession.endTime.getTime() - completedSession.startTime.getTime()) / 1000;
        const outputStr = `Process completed with exit code ${completedSession.exitCode}\nRuntime: ${runtime.toFixed(2)}s\nFinal output:\n${completedSession.output}`;
        
        // Remove from completed sessions as we've delivered the final output
        this.completedSessions.delete(pid);
        
        return { output: outputStr };
      }
    
      // Return null if PID not found
      return { output: null };
    }
  • Zod schema defining the input parameters for the read_output tool: a required integer pid.
     * Schema for read_output tool
     * Defines parameters for reading process output
     */
    const readOutputSchema = z.object({
      pid: z.number().int().describe("The process ID to read output from")
    });
  • serverMCP.js:105-109 (registration)
    Registration of the read_output tool in the ListToolsRequestSchema handler, specifying name, description, and input schema.
    {
      name: 'read_output',
      description: 'Read output from a running or completed process.',
      inputSchema: zodToJsonSchema(readOutputSchema),
    },
  • MCP server request handler dispatch for 'read_output' tool, which validates input and delegates to terminalManager.readOutput.
    case 'read_output':
      try {
        // Type-check and validate arguments
        if (!args || typeof args.pid !== 'number') {
          return {
            content: [{ type: "text", text: "Error: Invalid PID parameter" }],
            isError: true,
          };
        }
        
        console.error(`Reading output for PID: ${args.pid}`);
        const result = terminalManager.readOutput(args.pid);
        return {
          content: [{ type: "text", text: JSON.stringify(result) }],
        };
      } catch (error) {
        console.error('Error reading output:', error);
        return {
          content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }],
          isError: true,
        };
      }

Tool Definition Quality

Score is being calculated. Check back soon.

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/abdessamad-elamrani/MalwareAnalyzerMCP'

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