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
| Name | Required | Description | Default |
|---|---|---|---|
| pod | Yes | The name of the Kubernetes pod to port-forward | |
| namespace | No | The namespace of the pod (optional, defaults to current context namespace) | |
| localPort | Yes | The local port to forward to | |
| targetPort | Yes | The target port on the pod |
Implementation Reference
- server.js:1642-1653 (handler)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}` }] }; }
- server.js:375-400 (schema)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 }; });