Skip to main content
Glama
ConnorBoetig-dev

Unrestricted Development MCP Server

docker_logs

Fetch container logs to monitor application output and debug issues by retrieving log entries with optional filtering by time, line count, and timestamp display.

Instructions

Fetch logs from a container

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
containerYesContainer name or ID
tailNoNumber of lines to show from the end of logs
followNoFollow log output (not recommended for MCP)
sinceNoShow logs since timestamp (e.g., "2023-01-01T00:00:00")
timestampsNoShow timestamps
cwdNoWorking directory

Implementation Reference

  • Main handler function that constructs and executes the 'docker logs' command using flags from input args and the executeDockerCommand helper.
    export async function dockerLogs(args: z.infer<typeof dockerLogsSchema>): Promise<ToolResponse> { const tailFlag = args.tail ? `--tail ${args.tail}` : ''; const followFlag = args.follow ? '-f' : ''; const sinceFlag = args.since ? `--since ${args.since}` : ''; const timestampsFlag = args.timestamps ? '-t' : ''; return executeDockerCommand( `docker logs ${tailFlag} ${followFlag} ${sinceFlag} ${timestampsFlag} ${args.container}`.trim(), args.cwd ); }
  • Zod schema defining the input parameters and validation for the docker_logs tool.
    export const dockerLogsSchema = z.object({ container: z.string().describe('Container name or ID'), tail: z.number().optional().describe('Number of lines to show from the end of logs'), follow: z.boolean().optional().default(false).describe('Follow log output (not recommended for MCP)'), since: z.string().optional().describe('Show logs since timestamp (e.g., "2023-01-01T00:00:00")'), timestamps: z.boolean().optional().default(false).describe('Show timestamps'), cwd: z.string().optional().describe('Working directory') });
  • Tool registration object in the dockerTools array, which is exported and included in the server's tool list response.
    { name: 'docker_logs', description: 'Fetch logs from a container', inputSchema: { type: 'object', properties: { container: { type: 'string', description: 'Container name or ID' }, tail: { type: 'number', description: 'Number of lines to show from the end of logs' }, follow: { type: 'boolean', default: false, description: 'Follow log output (not recommended for MCP)' }, since: { type: 'string', description: 'Show logs since timestamp (e.g., "2023-01-01T00:00:00")' }, timestamps: { type: 'boolean', default: false, description: 'Show timestamps' }, cwd: { type: 'string', description: 'Working directory' } }, required: ['container'] } },
  • src/index.ts:447-449 (registration)
    Dispatch logic in the main MCP server request handler that routes 'docker_logs' calls to the handler function after schema validation.
    if (name === 'docker_logs') { const validated = dockerLogsSchema.parse(args); return await dockerLogs(validated);
  • Helper function that executes Docker shell commands via child_process.exec and formats the ToolResponse.
    async function executeDockerCommand(command: string, cwd?: string): Promise<ToolResponse> { try { const { stdout, stderr } = await execAsync(command, { cwd: cwd || process.cwd(), shell: '/bin/bash', maxBuffer: 10 * 1024 * 1024, // 10MB buffer for logs timeout: 60000 // 60 second timeout for builds }); return { content: [ { type: "text" as const, text: JSON.stringify({ success: true, command: command, stdout: stdout.trim(), stderr: stderr.trim(), cwd: cwd || process.cwd() }, null, 2) } ] }; } catch (error: any) { return { content: [ { type: "text" as const, text: JSON.stringify({ success: false, command: command, stdout: error.stdout?.trim() || '', stderr: error.stderr?.trim() || error.message, exitCode: error.code || 1, cwd: cwd || process.cwd() }, null, 2) } ], isError: true }; } }

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/ConnorBoetig-dev/mcp2'

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