Skip to main content
Glama

Docker Network Management

manage_networks

Manage Docker networks by listing, creating, removing, inspecting, connecting, or disconnecting containers from networks.

Instructions

Manage Docker networks (list, create, remove, inspect, connect, disconnect)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction to perform on networks
networkNoNetwork name (required for create, remove, inspect, connect, disconnect)
containerNoContainer name (required for connect, disconnect)
driverNoNetwork driver (bridge, overlay, host, none)

Implementation Reference

  • src/index.ts:1435-1503 (registration)
    Registration of the 'manage_networks' MCP tool, including title, description, input schema using Zod, and the inline async handler function that implements the tool logic.
    server.registerTool(
      "manage_networks",
      {
        title: "Docker Network Management",
        description: "Manage Docker networks (list, create, remove, inspect, connect, disconnect)",
        inputSchema: {
          action: z.enum(["list", "create", "remove", "inspect", "connect", "disconnect", "prune"]).describe("Action to perform on networks"),
          network: z.string().optional().describe("Network name (required for create, remove, inspect, connect, disconnect)"),
          container: z.string().optional().describe("Container name (required for connect, disconnect)"),
          driver: z.string().optional().describe("Network driver (bridge, overlay, host, none)")
        }
      },
      async ({ action, network, container, driver }) => {
        try {
          let command: string;
          
          switch (action) {
            case "list":
              command = "docker network ls";
              break;
            case "create":
              if (!network) throw new Error("Network name is required for create action");
              command = `docker network create${driver ? ` --driver ${driver}` : ""} ${network}`;
              break;
            case "remove":
              if (!network) throw new Error("Network name is required for remove action");
              command = `docker network rm ${network}`;
              break;
            case "inspect":
              if (!network) throw new Error("Network name is required for inspect action");
              command = `docker network inspect ${network}`;
              break;
            case "connect":
              if (!network || !container) throw new Error("Network and container names are required for connect action");
              command = `docker network connect ${network} ${container}`;
              break;
            case "disconnect":
              if (!network || !container) throw new Error("Network and container names are required for disconnect action");
              command = `docker network disconnect ${network} ${container}`;
              break;
            case "prune":
              command = "docker network prune -f";
              break;
          }
          
          const result = await executeDockerCommand(command);
          
          return {
            content: [
              {
                type: "text",
                text: `Network ${action} completed:\n\n${result.stdout}${result.stderr ? `\nWarnings:\n${result.stderr}` : ""}`
              }
            ]
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error managing networks: ${error instanceof Error ? error.message : String(error)}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • Core handler logic for 'manage_networks' tool. Maps input actions to specific Docker CLI commands for network management (list, create, rm, inspect, connect, disconnect, prune), executes via executeDockerCommand, and formats response.
    async ({ action, network, container, driver }) => {
      try {
        let command: string;
        
        switch (action) {
          case "list":
            command = "docker network ls";
            break;
          case "create":
            if (!network) throw new Error("Network name is required for create action");
            command = `docker network create${driver ? ` --driver ${driver}` : ""} ${network}`;
            break;
          case "remove":
            if (!network) throw new Error("Network name is required for remove action");
            command = `docker network rm ${network}`;
            break;
          case "inspect":
            if (!network) throw new Error("Network name is required for inspect action");
            command = `docker network inspect ${network}`;
            break;
          case "connect":
            if (!network || !container) throw new Error("Network and container names are required for connect action");
            command = `docker network connect ${network} ${container}`;
            break;
          case "disconnect":
            if (!network || !container) throw new Error("Network and container names are required for disconnect action");
            command = `docker network disconnect ${network} ${container}`;
            break;
          case "prune":
            command = "docker network prune -f";
            break;
        }
        
        const result = await executeDockerCommand(command);
        
        return {
          content: [
            {
              type: "text",
              text: `Network ${action} completed:\n\n${result.stdout}${result.stderr ? `\nWarnings:\n${result.stderr}` : ""}`
            }
          ]
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error managing networks: ${error instanceof Error ? error.message : String(error)}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod input schema defining parameters for the manage_networks tool: action (enum of operations), optional network/container names, and driver.
    inputSchema: {
      action: z.enum(["list", "create", "remove", "inspect", "connect", "disconnect", "prune"]).describe("Action to perform on networks"),
      network: z.string().optional().describe("Network name (required for create, remove, inspect, connect, disconnect)"),
      container: z.string().optional().describe("Container name (required for connect, disconnect)"),
      driver: z.string().optional().describe("Network driver (bridge, overlay, host, none)")
    }
  • Utility helper function used by the manage_networks handler (and others) to execute Docker CLI commands asynchronously using child_process.exec, returning stdout/stderr or throwing errors.
    async function executeDockerCommand(command: string): Promise<{ stdout: string; stderr: string }> {
      try {
        const result = await execAsync(command);
        return result;
      } catch (error: any) {
        throw new Error(`Docker command failed: ${error.message}`);
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. While it lists action types, it doesn't describe what each action does, what permissions are required, whether operations are destructive, what happens on failure, or what the output looks like. For a multi-action tool with mutation capabilities, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise - a single parenthetical list of actions that efficiently communicates scope. Every word earns its place, and the structure is front-loaded with the core purpose followed by specific capabilities.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a multi-action tool with mutation capabilities (create, remove, connect, disconnect) and no annotations or output schema, the description is incomplete. It doesn't explain behavioral implications, error conditions, or what users can expect from different actions. The tool has significant complexity that isn't addressed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 4 parameters thoroughly. The description doesn't add any parameter semantics beyond what's in the schema - it doesn't explain parameter relationships, dependencies, or usage patterns. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool manages Docker networks and lists specific actions (list, create, remove, inspect, connect, disconnect). It provides a specific verb ('manage') and resource ('Docker networks'), but doesn't explicitly differentiate from sibling tools like manage_containers or manage_volumes beyond the network focus.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to choose manage_networks over execute_docker_command for network operations, or how it relates to docker_compose tools. No context about prerequisites or exclusions is provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/TauqeerAhmad5201/docker-mcp-extension'

If you have feedback or need assistance with the MCP directory API, please join our Discord server