fix: repair logs, inspect, and rename tools
- logs: add server/services params for container/stack log endpoints - inspect: add service param for deployment_container/stack_container types - rename: remove incorrect tag special-casing (RenameTag expects id field) - scripts: add comprehensive test_all_tools.py covering all 13 tools
This commit is contained in:
+29
-10
@@ -10,12 +10,17 @@ const InspectType = z.enum([
|
||||
"swarm_service", "swarm_stack", "swarm_task",
|
||||
]);
|
||||
|
||||
// Types that need {deployment/stack, service} instead of {id}
|
||||
const DEPLOYMENT_SCOPED_TYPES = new Set(["deployment_container", "deployment_swarm_service"]);
|
||||
const STACK_SCOPED_TYPES = new Set(["stack_container", "stack_swarm_info", "stack_swarm_service"]);
|
||||
|
||||
export const inspectInputSchema = {
|
||||
inspect_type: InspectType.describe(
|
||||
"Type of Docker object to inspect (container, image, network, volume, deployment_container, swarm, swarm_node, etc.)"
|
||||
),
|
||||
id: z.string().describe("ID or name of the object to inspect"),
|
||||
server: z.string().optional().describe("Server name (required for server-scoped inspections)"),
|
||||
id: z.string().describe("ID or name of the object to inspect. For deployment_container/deployment_swarm_service this is the deployment name. For stack_container/stack_swarm_info/stack_swarm_service this is the stack name."),
|
||||
server: z.string().optional().describe("Server name (required for container, image, network, volume inspections)"),
|
||||
service: z.string().optional().describe("Service name (required for deployment_container, deployment_swarm_service, stack_container, stack_swarm_info, stack_swarm_service)"),
|
||||
};
|
||||
|
||||
export async function handleInspect(
|
||||
@@ -23,10 +28,11 @@ export async function handleInspect(
|
||||
inspect_type: z.infer<typeof InspectType>;
|
||||
id: string;
|
||||
server?: string;
|
||||
service?: string;
|
||||
},
|
||||
client: KomodoClient,
|
||||
): Promise<{ content: { type: "text"; text: string }[] }> {
|
||||
const { inspect_type, id, server } = args;
|
||||
const { inspect_type, id, server, service } = args;
|
||||
|
||||
const requestName = INSPECT_REQUEST_MAP[inspect_type];
|
||||
if (!requestName) {
|
||||
@@ -34,14 +40,27 @@ export async function handleInspect(
|
||||
}
|
||||
|
||||
const params: Record<string, unknown> = {};
|
||||
const paramKey = server ? INSPECT_PARAM_KEY[inspect_type] : undefined;
|
||||
if (paramKey) {
|
||||
// Server-scoped Docker objects: {server, <container|image|network|volume>}
|
||||
params.server = server;
|
||||
params[paramKey] = id;
|
||||
} else {
|
||||
params.id = id;
|
||||
|
||||
if (DEPLOYMENT_SCOPED_TYPES.has(inspect_type)) {
|
||||
// InspectDeploymentContainer / InspectDeploymentSwarmService: {deployment, service}
|
||||
params.deployment = id;
|
||||
if (service) params.service = service;
|
||||
if (server) params.server = server;
|
||||
} else if (STACK_SCOPED_TYPES.has(inspect_type)) {
|
||||
// InspectStackContainer / InspectStackSwarmInfo / InspectStackSwarmService: {stack, service}
|
||||
params.stack = id;
|
||||
if (service) params.service = service;
|
||||
if (server) params.server = server;
|
||||
} else {
|
||||
const paramKey = server ? INSPECT_PARAM_KEY[inspect_type] : undefined;
|
||||
if (paramKey) {
|
||||
// Server-scoped Docker objects: {server, <container|image|network|volume>}
|
||||
params.server = server;
|
||||
params[paramKey] = id;
|
||||
} else {
|
||||
params.id = id;
|
||||
if (server) params.server = server;
|
||||
}
|
||||
}
|
||||
|
||||
const result = await client.rpc("read", requestName, params);
|
||||
|
||||
+28
-9
@@ -5,13 +5,21 @@ const LogResourceType = z.enum(["deployment", "stack", "container", "swarm_servi
|
||||
|
||||
export const logsInputSchema = {
|
||||
resource_type: LogResourceType.describe(
|
||||
"Resource type to get logs for (deployment, stack, container, swarm_service)"
|
||||
"Resource type to get logs for (deployment, stack, container, swarm_service). Returns log lines as text."
|
||||
),
|
||||
id: z.string().describe("Resource ID or name"),
|
||||
tail: z
|
||||
.number()
|
||||
.optional()
|
||||
.describe("Number of recent log lines to return"),
|
||||
server: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe("Server name (required for container logs)"),
|
||||
services: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe("Service names to include (required for stack logs)"),
|
||||
};
|
||||
|
||||
export async function handleLogs(
|
||||
@@ -19,29 +27,40 @@ export async function handleLogs(
|
||||
resource_type: z.infer<typeof LogResourceType>;
|
||||
id: string;
|
||||
tail?: number;
|
||||
server?: string;
|
||||
services?: string[];
|
||||
},
|
||||
client: KomodoClient,
|
||||
): Promise<{ content: { type: "text"; text: string }[] }> {
|
||||
const { resource_type, id, tail } = args;
|
||||
|
||||
const params: Record<string, unknown> = { id };
|
||||
if (tail !== undefined) params.tail = tail;
|
||||
const { resource_type, id, tail, server, services } = args;
|
||||
|
||||
let result: unknown;
|
||||
|
||||
switch (resource_type) {
|
||||
case "deployment":
|
||||
case "deployment": {
|
||||
const params: Record<string, unknown> = { id };
|
||||
if (tail !== undefined) params.tail = tail;
|
||||
result = await client.rpc("read", "GetDeploymentLog", params);
|
||||
break;
|
||||
case "stack":
|
||||
}
|
||||
case "stack": {
|
||||
const params: Record<string, unknown> = { id, services: services ?? [] };
|
||||
if (tail !== undefined) params.tail = tail;
|
||||
result = await client.rpc("read", "GetStackLog", params);
|
||||
break;
|
||||
case "container":
|
||||
}
|
||||
case "container": {
|
||||
const params: Record<string, unknown> = { server, container: id };
|
||||
if (tail !== undefined) params.tail = tail;
|
||||
result = await client.rpc("read", "GetContainerLog", params);
|
||||
break;
|
||||
case "swarm_service":
|
||||
}
|
||||
case "swarm_service": {
|
||||
const params: Record<string, unknown> = { id };
|
||||
if (tail !== undefined) params.tail = tail;
|
||||
result = await client.rpc("read", "GetSwarmServiceLog", params);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -33,10 +33,6 @@ export async function handleRename(
|
||||
}
|
||||
|
||||
const params: Record<string, unknown> = { id, name };
|
||||
if (resource_type === "tag") {
|
||||
params.tag = id;
|
||||
delete params.id;
|
||||
}
|
||||
|
||||
const result = await client.rpc("write", requestName, params);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user