port-forward
Forward a Kubernetes service to a local port for direct access to cluster resources during development or debugging.
Instructions
Port forward a Kubernetes service to a local port
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| service | Yes | The name of the Kubernetes service to port-forward | |
| namespace | No | The namespace of the service (optional, defaults to current context namespace) | |
| localPort | Yes | The local port to forward to | |
| targetPort | Yes | The target port on the service |
Implementation Reference
- server.js:1629-1640 (handler)Handler implementation for the 'port-forward' tool. Extracts parameters, constructs and executes a 'kubectl port-forward' command for the specified service, and returns the output or a success message.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)Input schema definition for the 'port-forward' tool, specifying parameters for service name, namespace, local port, and target port.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)Registration of the ListTools handler which returns the list of all tools including 'port-forward'.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools }; });