Skip to main content
Glama

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
NameRequiredDescriptionDefault
serviceYesThe name of the Kubernetes service to port-forward
namespaceNoThe namespace of the service (optional, defaults to current context namespace)
localPortYesThe local port to forward to
targetPortYesThe target port on the service

Implementation Reference

  • 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}` }] }; }
  • 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 }; });

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