Skip to main content
Glama

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
containerYesContainer ID or name
tailNoNumber of lines to show from the end

Implementation Reference

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

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/Toowiredd/chatgpt-mcp-server'

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