container_logs
Retrieve Docker container logs to monitor application output and debug issues. Specify container ID and optional line count for targeted log access.
Instructions
Get logs from a Docker container.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Container ID or name | |
| tail | No | Number of lines from the end |
Implementation Reference
- src/docker.ts:61-71 (handler)Handler function that fetches logs from a Docker container using the Docker API. It retrieves the container by ID, fetches logs with specified tail lines, and strips control characters from the output.
export async function containerLogs(id: string, tail: number): Promise<string> { const container = docker.getContainer(id); const logs = await container.logs({ stdout: true, stderr: true, tail, follow: false, }); // Strip Docker log control characters (eslint: intentional for Docker output) return logs.toString("utf-8").replace(/[\x00-\x08]/g, ""); // eslint-disable-line no-control-regex } - src/index.ts:53-68 (registration)Registration of the 'container_logs' MCP tool with the server. Includes the tool name, description, input schema, and the async handler that calls the containerLogs function.
server.tool( "container_logs", "Get logs from a Docker container.", { id: z.string().describe("Container ID or name"), tail: z .number() .optional() .default(100) .describe("Number of lines from the end"), }, async ({ id, tail }) => { const logs = await containerLogs(id, tail); return { content: [{ type: "text", text: logs || "(no logs)" }] }; }, ); - src/index.ts:57-62 (schema)Zod schema defining the input parameters for container_logs: 'id' (required string for container ID or name) and 'tail' (optional number with default 100 for number of log lines).
id: z.string().describe("Container ID or name"), tail: z .number() .optional() .default(100) .describe("Number of lines from the end"),