docker_compose_logs
View container output from docker-compose stacks to monitor application behavior and debug issues. Filter by specific services, set line limits, or view logs from specific time periods.
Instructions
View output from containers in a docker-compose stack
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| services | No | Only show logs for specific services | |
| tail | No | Number of lines to show from end of logs | |
| since | No | Show logs since timestamp | |
| timestamps | No | Show timestamps | |
| file | No | Path to compose file | |
| cwd | No | Working directory |
Implementation Reference
- src/tools/docker.ts:333-345 (handler)The main handler function that constructs and executes the docker compose logs command using dynamic flags and the executeDockerCommand helper.export async function dockerComposeLogs(args: z.infer<typeof dockerComposeLogsSchema>): Promise<ToolResponse> { const tailFlag = args.tail ? `--tail ${args.tail}` : ''; const sinceFlag = args.since ? `--since ${args.since}` : ''; const timestampsFlag = args.timestamps ? '-t' : ''; const services = args.services ? args.services.join(' ') : ''; const fileFlag = args.file ? `-f ${args.file}` : ''; const composeCmd = await getComposeCmd(); return executeDockerCommand( `${composeCmd} ${fileFlag} logs ${tailFlag} ${sinceFlag} ${timestampsFlag} ${services}`.trim(), args.cwd ); }
- src/tools/docker.ts:182-189 (schema)Zod schema for input validation of the docker_compose_logs tool parameters.export const dockerComposeLogsSchema = z.object({ services: z.array(z.string()).optional().describe('Only show logs for specific services'), tail: z.number().optional().describe('Number of lines to show from end of logs'), since: z.string().optional().describe('Show logs since timestamp'), timestamps: z.boolean().optional().default(false).describe('Show timestamps'), file: z.string().optional().describe('Path to compose file'), cwd: z.string().optional().describe('Working directory') });
- src/index.ts:495-498 (registration)Dispatch logic in the main MCP server handler that validates arguments with the schema and calls the dockerComposeLogs handler function.if (name === 'docker_compose_logs') { const validated = dockerComposeLogsSchema.parse(args); return await dockerComposeLogs(validated); }
- src/tools/docker.ts:562-576 (registration)Tool metadata definition including name, description, and JSON input schema, included in the dockerTools array for listing available tools.{ name: 'docker_compose_logs', description: 'View output from containers in a docker-compose stack', inputSchema: { type: 'object', properties: { services: { type: 'array', items: { type: 'string' }, description: 'Only show logs for specific services' }, tail: { type: 'number', description: 'Number of lines to show from end of logs' }, since: { type: 'string', description: 'Show logs since timestamp' }, timestamps: { type: 'boolean', default: false, description: 'Show timestamps' }, file: { type: 'string', description: 'Path to compose file' }, cwd: { type: 'string', description: 'Working directory' } } } },
- src/tools/docker.ts:21-62 (helper)Core helper function that executes any docker command via child_process.exec and formats the response in MCP ToolResponse format.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 }; } }