We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/jmagar/homelab-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
import type Docker from "dockerode";
import type { DockerVolumeInfo, HostConfig } from "../../types.js";
import { narrowToDefaultHost } from "../../utils/host-utils.js";
import type { ClientManager } from "./utils/client-manager.js";
// Type for volume with optional CreatedAt field
interface VolumeWithCreatedAt extends Docker.VolumeInspectInfo {
CreatedAt?: string;
}
/**
* Service for Docker volume operations.
* Handles volume listing and management.
*/
export class VolumeService {
constructor(private clientManager: ClientManager) {}
/**
* List Docker volumes across multiple hosts in parallel.
*
* @param hosts - List of Docker hosts to query
* @returns Promise resolving to array of volume information
*/
async listVolumes(hosts: HostConfig[]): Promise<DockerVolumeInfo[]> {
const targetHosts = narrowToDefaultHost(hosts);
const results = await Promise.allSettled(
targetHosts.map((host) => this.listVolumesOnHost(host))
);
return results
.filter((r): r is PromiseFulfilledResult<DockerVolumeInfo[]> => r.status === "fulfilled")
.flatMap((r) => r.value);
}
/**
* List Docker volumes from a single host (internal helper).
*/
private async listVolumesOnHost(host: HostConfig): Promise<DockerVolumeInfo[]> {
const docker = await this.clientManager.getClient(host);
const result = await docker.listVolumes();
const volumes = result?.Volumes ?? [];
return volumes.map((volume) => {
// Cast once to document the expected shape with CreatedAt
const volumeWithCreatedAt = volume as VolumeWithCreatedAt;
return {
name: volumeWithCreatedAt.Name,
driver: volumeWithCreatedAt.Driver,
scope: volumeWithCreatedAt.Scope,
mountpoint: volumeWithCreatedAt.Mountpoint,
createdAt:
typeof volumeWithCreatedAt.CreatedAt === "string"
? volumeWithCreatedAt.CreatedAt
: undefined,
labels: volumeWithCreatedAt.Labels ?? undefined,
hostName: host.name,
};
});
}
}