Skip to main content
Glama

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
NameRequiredDescriptionDefault
idYesContainer ID or name
tailNoNumber of lines from the end

Implementation Reference

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

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/ofershap/mcp-server-docker'

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