Skip to main content
Glama

get_containers_process_trees

Retrieve process trees for multiple containers to analyze runtime behavior and identify security risks in Kubernetes environments.

Instructions

Get process trees for multiple containers

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
container_idsYesList of container IDs to get process trees for
processes_limitNoLimit the number of processes to get

Implementation Reference

  • Main handler function that implements the tool logic: fetches container runtime insights via API, processes the data, limits processes using helper, and returns process trees for given container IDs.
    export async function getContainersProcessTrees( client: RadSecurityClient, containerIds: string[], processesLimit: number = 1000 ): Promise<any> { if (containerIds.length === 0) { throw new Error("No container IDs provided"); } const cris = await client.makeRequest( `/accounts/${client.getAccountId()}/container_runtime_insights`, { container_ids: containerIds.join(',') } ); const containersProcessTrees: Record<string, any> = {}; for (const cri of cris.entries) { const criId = cri.id; const data = await client.makeRequest( `/accounts/${client.getAccountId()}/container_runtime_insights/${criId}` ); if (!data.ongoing || !data.ongoing.containers || data.ongoing.containers.length === 0) { containersProcessTrees[criId] = {}; } else { containersProcessTrees[criId] = data.ongoing.containers[0]; containersProcessTrees[criId].processes = reduceProcesses(data.ongoing.containers[0].processes, processesLimit); } } return containersProcessTrees; }
  • Zod input schema validating container_ids (required array of strings) and processes_limit (optional number, defaults to 1000). Used for tool input parsing and JSON schema generation.
    export const GetContainersProcessTreesSchema = z.object({ container_ids: z.array(z.string()).describe("List of container IDs to get process trees for"), processes_limit: z.number().default(1000).describe("Limit the number of processes to get"), });
  • src/index.ts:1135-1149 (registration)
    Tool call handler registration in the MCP server switch statement: parses arguments using schema, invokes the handler function with client and args, formats response as MCP content.
    case "get_containers_process_trees": { const args = runtime.GetContainersProcessTreesSchema.parse( request.params.arguments ); const response = await runtime.getContainersProcessTrees( client, args.container_ids, args.processes_limit ); return { content: [ { type: "text", text: JSON.stringify(response, null, 2) }, ], }; }
  • src/index.ts:362-367 (registration)
    Tool registration in list tools response: defines tool name, description, and input schema from runtime module for discovery by MCP clients.
    name: "get_containers_process_trees", description: "Get process trees for multiple containers", inputSchema: zodToJsonSchema( runtime.GetContainersProcessTreesSchema ), },
  • Helper function to limit and format process trees into a textual tree representation, recursively traversing processes and children, respecting the processes_limit.
    function reduceProcesses(processes: any[], limit: number): any[] { if (processes.length === 0 || limit <= 0) { return []; } const countProcesses = (procs: any[]): number => { let total = 0; for (const proc of procs) { total += 1; if (proc.children) { total += countProcesses(proc.children); } } return total; }; const extractProcessTree = (procs: any[], indent: string = "", remainingLimit: number): string[] => { const result: string[] = []; for (const process of procs) { if (result.length >= remainingLimit) { break; } const timestamp = process.timestamp || ""; // Print process info if (process.programs) { for (const program of process.programs) { const comm = program.comm || "unknown"; const args = (program.args || []).join(" "); result.push(`${indent}├─ [${timestamp}] ${comm}: ${args}`); } } // Print connections if any if (process.connections) { for (const conn of process.connections) { const addr = conn.hostname || conn.address || "unknown"; const port = conn.port || "unknown"; const connTime = conn.timestamp || ""; result.push(`${indent}│ └─ Connection to ${addr}:${port} at ${connTime}`); } } // Recursively print children with increased indentation if (process.children) { result.push(...extractProcessTree(process.children, indent + "│ ", remainingLimit - result.length)); } } return result; }; // Extract the process tree const tree = extractProcessTree(processes, "", limit); // Add a note if we hit the limit if (tree.length >= limit) { const totalCount = countProcesses(processes); tree.push(`Processes limit(${limit}) reached. Some processes were not included in the output. Total processes: ${totalCount}`); } return tree; }

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/rad-security/mcp-server'

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