Skip to main content
Glama

port-forward-pod

Forward a Kubernetes pod's port to your local machine for direct access to containerized applications during development or debugging.

Instructions

Port forward a Kubernetes pod to a local port

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
podYesThe name of the Kubernetes pod to port-forward
namespaceNoThe namespace of the pod (optional, defaults to current context namespace)
localPortYesThe local port to forward to
targetPortYesThe target port on the pod

Implementation Reference

  • The handler logic for the 'port-forward-pod' tool. It destructures the input arguments, constructs a kubectl port-forward command for the specified pod (with optional namespace), executes it using execAsync, and returns the stdout or a success message in the MCP content format.
    case "port-forward-pod": { const { pod, namespace, localPort, targetPort } = args; const nsArg = namespace ? `-n ${namespace}` : ""; const cmd = `kubectl port-forward pod/${pod} ${localPort}:${targetPort} ${nsArg}`; const { stdout } = await execAsync(cmd); return { content: [{ type: "text", text: stdout || `Port-forwarding started for ${pod}:${targetPort} -> localhost:${localPort}` }] }; }
  • The tool definition object for 'port-forward-pod', including its name, description, and input schema for validation. This object is part of the 'tools' array returned by the ListTools handler, effectively registering the tool.
    { name: "port-forward-pod", description: "Port forward a Kubernetes pod to a local port", inputSchema: { type: "object", properties: { pod: { type: "string", description: "The name of the Kubernetes pod to port-forward" }, namespace: { type: "string", description: "The namespace of the pod (optional, defaults to current context namespace)" }, localPort: { type: "number", description: "The local port to forward to" }, targetPort: { type: "number", description: "The target port on the pod" } }, required: ["pod", "localPort", "targetPort"] } },
  • server.js:1392-1394 (registration)
    The request handler for ListToolsRequestSchema that returns the full list of tools (including 'port-forward-pod'), which registers all tools with the MCP server.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { 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/thekaranpargaie/kube-mcp'

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