init project
This commit is contained in:
Vendored
+44
@@ -0,0 +1,44 @@
|
||||
import { z } from 'zod';
|
||||
import { errorResult, jsonResult, toErrorMessage } from '../shared.js';
|
||||
import { dockerManager } from './dockerManager.js';
|
||||
export function registerDockerListContainersTool(server) {
|
||||
server.registerTool('docker_list_containers', {
|
||||
title: 'Docker List Containers',
|
||||
description: 'List Docker containers started by this server with their current status and port mappings.',
|
||||
inputSchema: {
|
||||
includeDockerStatus: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.default(false)
|
||||
.describe('Also query the Docker daemon for live status of each tracked container.'),
|
||||
},
|
||||
}, async ({ includeDockerStatus }) => {
|
||||
try {
|
||||
await dockerManager.ensureReachable();
|
||||
const tracked = dockerManager.listTracked();
|
||||
if (!includeDockerStatus) {
|
||||
return jsonResult({ containers: tracked });
|
||||
}
|
||||
const docker = dockerManager.getDocker();
|
||||
const enriched = await Promise.all(tracked.map(async (c) => {
|
||||
try {
|
||||
const info = await docker.getContainer(c.id).inspect();
|
||||
return {
|
||||
...c,
|
||||
state: info.State?.Status ?? 'unknown',
|
||||
running: info.State?.Running ?? false,
|
||||
exitCode: info.State?.ExitCode ?? null,
|
||||
};
|
||||
}
|
||||
catch {
|
||||
return { ...c, state: 'unknown', running: false, exitCode: null };
|
||||
}
|
||||
}));
|
||||
return jsonResult({ containers: enriched });
|
||||
}
|
||||
catch (error) {
|
||||
return errorResult(toErrorMessage(error));
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=listContainers.js.map
|
||||
Reference in New Issue
Block a user