container_logs
Retrieve Docker container logs to monitor application output and debug issues by specifying container ID and optional line count.
Instructions
Get container logs
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"container": "<container>"
},
"name": "container_logs"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| container | Yes | Container ID or name | |
| tail | No | Number of lines to show from the end |
Implementation Reference
- src/services/docker.service.ts:57-59 (handler)Core handler function that implements the 'container_logs' tool logic by executing the 'docker logs' command with optional --tail parameter.
async getContainerLogs(id: string, tail?: number): Promise<string> { return this.executeCommand(`logs ${tail ? `--tail ${tail}` : ''} ${id}`); } - src/servers/mcp.server.ts:177-194 (registration)Tool registration in the MCP server's listTools handler, defining name, description, and input schema for 'container_logs'.
{ name: 'container_logs', description: 'Get container logs', inputSchema: { type: 'object', properties: { container: { type: 'string', description: 'Container ID or name', }, tail: { type: 'number', description: 'Number of lines to show from the end', }, }, required: ['container'], }, }, - src/servers/mcp.server.ts:276-285 (handler)Dispatch handler in MCP server's callToolRequestSchema that parses arguments and invokes the DockerService handler for 'container_logs'.
case 'container_logs': { const { container, tail } = request.params.arguments as { container: string; tail?: number; }; const output = await this.dockerService.getContainerLogs(container, tail); return { content: [{ type: 'text', text: output }], }; } - src/servers/mcp.server.ts:180-193 (schema)Input schema definition for the 'container_logs' tool, specifying required 'container' and optional 'tail' parameters.
inputSchema: { type: 'object', properties: { container: { type: 'string', description: 'Container ID or name', }, tail: { type: 'number', description: 'Number of lines to show from the end', }, }, required: ['container'], }, - src/services/docker.service.ts:8-18 (helper)Helper method used by getContainerLogs to execute Docker CLI commands asynchronously.
async executeCommand(command: string): Promise<string> { try { const { stdout } = await execAsync(`docker ${command}`); return stdout; } catch (error: any) { throw new McpError( ErrorCode.InternalError, `Docker command failed: ${error.message}` ); } }