Skip to main content
Glama
Flux159
by Flux159

stop_port_forward

Stop a running port-forward process in Kubernetes by specifying its ID to terminate network connections between local and cluster resources.

Instructions

Stop a port-forward process

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYes

Implementation Reference

  • The handler function for the 'stop_port_forward' tool. It retrieves the tracked port-forward entry using the provided ID from the KubernetesManager, calls the stop method on its server (which kills the process), removes the entry, and returns a success message.
    export async function stopPortForward(
      k8sManager: KubernetesManager,
      input: {
        id: string;
      }
    ): Promise<{ content: { success: boolean; message: string }[] }> {
      const portForward = k8sManager.getPortForward(input.id);
      if (!portForward) {
        throw new Error(`Port-forward with id ${input.id} not found`);
      }
    
      try {
        await portForward.server.stop();
        k8sManager.removePortForward(input.id);
        return {
          content: [
            { success: true, message: "port-forward stopped successfully" },
          ],
        };
      } catch (error: any) {
        throw new Error(`Failed to stop port-forward: ${error.message}`);
      }
    }
  • Schema definition for the 'stop_port_forward' tool, specifying the name, description, and input schema requiring an 'id' string.
    export const StopPortForwardSchema = {
      name: "stop_port_forward",
      description: "Stop a port-forward process",
      annotations: {
        title: "Stop Port Forward",
      },
      inputSchema: {
        type: "object",
        properties: {
          id: { type: "string" },
        },
        required: ["id"],
      },
    };
  • src/index.ts:493-500 (registration)
    Registration and dispatch of the 'stop_port_forward' tool within the CallToolRequestHandler switch statement, calling the imported stopPortForward function with the KubernetesManager and input.
    case "stop_port_forward": {
      return await stopPortForward(
        k8sManager,
        input as {
          id: string;
        }
      );
    }
  • src/index.ts:128-130 (registration)
    Inclusion of StopPortForwardSchema in the allTools array, which is used to list available tools via ListToolsRequestHandler.
    // Port forwarding
    PortForwardSchema,
    StopPortForwardSchema,
  • src/index.ts:40-43 (registration)
    Import of the stopPortForward handler and StopPortForwardSchema from src/tools/port_forward.ts (noted as .js, likely TypeScript transpiled).
    startPortForward,
    PortForwardSchema,
    stopPortForward,
    StopPortForwardSchema,

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/Flux159/mcp-server-kubernetes'

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