docker-mcp
Version:
A Model Context Protocol (MCP) server that enables AI agents to interact with Docker containers locally or remotely via SSH. Provides comprehensive Docker management capabilities including container operations, logs, monitoring, and cleanup.
60 lines • 2.62 kB
JavaScript
import { z } from "zod";
export function registerDockerContainerLogs(server, dockerService) {
server.registerTool("docker_container_logs", {
title: "Get Container Logs",
description: "Retrieve logs from a Docker container with optional filtering",
inputSchema: {
containerId: z.string().describe("Container ID or name"),
tail: z.number().optional().describe("Number of lines to retrieve from the end of the logs (default: 100)"),
since: z.string().optional().describe("Show logs since timestamp (e.g., '2023-01-01T00:00:00Z') or relative time (e.g., '10m', '1h', '24h')"),
until: z.string().optional().describe("Show logs until timestamp (e.g., '2023-01-01T00:00:00Z') or relative time (e.g., '10m', '1h', '24h')"),
timestamps: z.boolean().optional().describe("Include timestamps in the output (default: false)")
}
}, async ({ containerId, tail, since, until, timestamps }) => {
try {
const logs = await dockerService.getContainerLogs(containerId, {
tail: tail || 100,
since,
until,
timestamps: timestamps || false
});
// Format the response with metadata
const logLines = logs.split('\n').filter(line => line.trim());
const logCount = logLines.length;
return {
content: [
{
type: "text",
text: JSON.stringify({
containerId,
logCount,
options: {
tail: tail || 100,
since: since || null,
until: until || null,
timestamps: timestamps || false
},
logs: logs
}, null, 2)
}
]
};
}
catch (error) {
return {
content: [
{
type: "text",
text: JSON.stringify({
error: "Failed to get container logs",
message: error instanceof Error ? error.message : String(error),
containerId
}, null, 2)
}
],
isError: true
};
}
});
}
//# sourceMappingURL=docker_container_logs.js.map