Skip to main content
Glama

docker_monitoring

Monitor Docker containers to view logs, inspect resources, execute commands, and troubleshoot issues with real-time metrics and events.

Instructions

Monitor containers, get logs, inspect resources, and troubleshoot issues

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesMonitoring action to perform
containerNoContainer name or ID
followNoFollow log output
tailNoNumber of lines to show from end of logs
commandNoCommand to execute in container (for exec)
sinceNoShow logs since timestamp
untilNoShow logs until timestamp

Implementation Reference

  • Handler function for the 'docker_monitoring' tool. Constructs Docker commands for monitoring actions (logs, inspect, exec, top, port, stats, events, diff) based on input parameters and executes them using executeDockerCommand.
    async ({ action, container, follow, tail, command, since, until }) => { try { let dockerCommand: string; switch (action) { case "logs": if (!container) throw new Error("Container name is required for logs"); dockerCommand = `docker logs`; if (follow) dockerCommand += " -f"; if (tail) dockerCommand += ` --tail ${tail}`; if (since) dockerCommand += ` --since ${since}`; if (until) dockerCommand += ` --until ${until}`; dockerCommand += ` ${container}`; break; case "inspect": if (!container) throw new Error("Container name is required for inspect"); dockerCommand = `docker inspect ${container}`; break; case "exec": if (!container) throw new Error("Container name is required for exec"); const execCommand = command || "bash"; dockerCommand = `docker exec -it ${container} ${execCommand}`; break; case "top": if (!container) throw new Error("Container name is required for top"); dockerCommand = `docker top ${container}`; break; case "port": if (!container) throw new Error("Container name is required for port"); dockerCommand = `docker port ${container}`; break; case "stats": dockerCommand = container ? `docker stats --no-stream ${container}` : "docker stats --no-stream"; break; case "events": dockerCommand = "docker events --since 1h"; if (container) dockerCommand += ` --filter container=${container}`; break; case "diff": if (!container) throw new Error("Container name is required for diff"); dockerCommand = `docker diff ${container}`; break; } const result = await executeDockerCommand(dockerCommand); return { content: [ { type: "text", text: `Monitoring ${action} completed:\n\n${result.stdout}${result.stderr ? `\nWarnings:\n${result.stderr}` : ""}` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error with monitoring operation: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }
  • Input schema for the 'docker_monitoring' tool defining parameters for various monitoring actions.
    inputSchema: { action: z.enum(["logs", "inspect", "exec", "top", "port", "stats", "events", "diff"]).describe("Monitoring action to perform"), container: z.string().optional().describe("Container name or ID"), follow: z.boolean().optional().describe("Follow log output"), tail: z.number().optional().describe("Number of lines to show from end of logs"), command: z.string().optional().describe("Command to execute in container (for exec)"), since: z.string().optional().describe("Show logs since timestamp"), until: z.string().optional().describe("Show logs until timestamp") }
  • src/index.ts:1732-1736 (registration)
    Registration of the 'docker_monitoring' MCP tool with title, description, and input schema.
    server.registerTool( "docker_monitoring", { title: "Docker Monitoring and Troubleshooting", description: "Monitor containers, get logs, inspect resources, and troubleshoot issues",
  • Helper function executeDockerCommand used by the docker_monitoring handler to run Docker commands.
    async function executeDockerCommand(command: string): Promise<{ stdout: string; stderr: string }> { try { const result = await execAsync(command); return result; } catch (error: any) { throw new Error(`Docker command failed: ${error.message}`); } }

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/TauqeerAhmad5201/docker-mcp-extension'

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