Skip to main content
Glama

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

Implementation Reference

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

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