port-forward
Forward a Kubernetes service to a local port for direct access to cluster resources without exposing them externally. Specify the service name, local port, and target port to establish the connection.
Instructions
Port forward a Kubernetes service to a local port
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| localPort | Yes | The local port to forward to | |
| namespace | No | The namespace of the service (optional, defaults to current context namespace) | |
| service | Yes | The name of the Kubernetes service to port-forward | |
| targetPort | Yes | The target port on the service |
Implementation Reference
- server.js:1629-1640 (handler)The handler executes a kubectl port-forward command on the specified service to forward traffic from a local port to a target port on the service.case "port-forward": { const { service, namespace, localPort, targetPort } = args; const nsArg = namespace ? `-n ${namespace}` : ""; const cmd = `kubectl port-forward svc/${service} ${localPort}:${targetPort} ${nsArg}`; const { stdout } = await execAsync(cmd); return { content: [{ type: "text", text: stdout || `Port-forwarding started for ${service}:${targetPort} -> localhost:${localPort}` }] }; }
- server.js:350-374 (schema)The input schema defines the parameters for the port-forward tool: service (required string), namespace (optional string), localPort (required number), targetPort (required number).name: "port-forward", description: "Port forward a Kubernetes service to a local port", inputSchema: { type: "object", properties: { service: { type: "string", description: "The name of the Kubernetes service to port-forward" }, namespace: { type: "string", description: "The namespace of the service (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 service" } }, required: ["service", "localPort", "targetPort"] } },
- server.js:1392-1394 (registration)The tool is registered by including its schema in the tools array returned by the ListToolsRequestHandler.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools }; });