From 558d8098719039d2523037289c31160633ac25d9 Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Wed, 13 May 2026 00:04:26 -0600 Subject: [PATCH] feat(deployment): add readLogs procedure to fetch deployment logs - Introduced a new `readLogs` procedure that allows users to retrieve logs for a specific deployment by providing the deployment ID and an optional tail parameter. - Implemented permission checks to ensure users have access to the requested logs. - Enhanced log retrieval for both cloud and non-cloud environments, utilizing appropriate commands based on the server context. Resolve https://github.com/Dokploy/mcp/issues/14 --- apps/dokploy/server/api/routers/deployment.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/apps/dokploy/server/api/routers/deployment.ts b/apps/dokploy/server/api/routers/deployment.ts index 6f3b1d1ae..f91b67b40 100644 --- a/apps/dokploy/server/api/routers/deployment.ts +++ b/apps/dokploy/server/api/routers/deployment.ts @@ -197,4 +197,39 @@ export const deploymentRouter = createTRPCRouter({ }); return result; }), + + readLogs: protectedProcedure + .input( + z.object({ + deploymentId: z.string().min(1), + tail: z.number().int().min(1).max(10000).default(100), + }), + ) + .query(async ({ input, ctx }) => { + const deployment = await findDeploymentById(input.deploymentId); + const serviceId = deployment.applicationId || deployment.composeId; + if (serviceId) { + await checkServicePermissionAndAccess(ctx, serviceId, { + deployment: ["read"], + }); + } + + if (!deployment.logPath) { + return ""; + } + + const command = `tail -n ${input.tail} "${deployment.logPath}" 2>/dev/null || echo ""`; + const serverId = deployment.serverId || deployment.schedule?.serverId; + if (serverId) { + const { stdout } = await execAsyncRemote(serverId, command); + return stdout; + } + + if (IS_CLOUD) { + return ""; + } + + const { stdout } = await execAsync(command); + return stdout; + }), });