Skip to main content
Glama
abhijeetka
by abhijeetka

port_forward

Forward ports from Kubernetes resources like pods, deployments, or services to external access. Specify the resource type, name, and ports to establish connectivity.

Instructions

Port forward a resource to the outside world k8s_object can be a pod, deployment or a service and it should be in the format pod/, deployment/, service/

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
k8s_objectYes
nameYes
namespaceNodefault
portNo
target_portNo

Implementation Reference

  • The port_forward tool handler function. It is registered via the @mcp.tool() decorator and executes the 'kubectl port-forward' command to forward ports for a Kubernetes resource (pod, deployment, or service). The function handles errors and returns the result or an error dictionary.
    @mcp.tool()
    async def port_forward(k8s_object: str, name: str, namespace: str = "default", port: int = 80, target_port: int = 80) -> dict:
        """Port forward a resource to the outside world
            k8s_object can be a pod, deployment or a service and it should be in the format pod/<name>, deployment/<name>, service/<name>
        """
        try:
            cmd = ["kubectl", "port-forward", k8s_object, name, "-n", namespace, str(port), str(target_port)]
            result = subprocess.run(cmd, capture_output=True, text=True, check=True)
            return json.loads(result.stdout)
        except subprocess.CalledProcessError as e:
            return {"error": f"Failed to port forward service: {str(e)}"}
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but only states the action without behavioral details. It doesn't disclose if this creates persistent resources, requires specific permissions, has side effects, or how it handles errors—critical for a mutation tool in Kubernetes.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences with zero waste: first states purpose, second clarifies k8s_object format. Well-structured and front-loaded, though slightly terse given the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 5-parameter mutation tool with no annotations or output schema, the description is incomplete. It lacks details on behavioral traits, parameter interactions, return values, and error handling, making it inadequate for safe and effective use by an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, but the description adds value by explaining k8s_object format with examples (pod/<name>, etc.). However, it doesn't cover other parameters like name, namespace, port, or target_port, leaving significant gaps in parameter understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('port forward') and resource ('a resource to the outside world'), with specific examples of Kubernetes object types. It distinguishes from siblings like expose_service by focusing on port forwarding rather than service exposure, though not explicitly compared.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives like expose_service or when not to use it. The description implies usage for external access but lacks explicit context or prerequisites for effective tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/abhijeetka/mcp-k8s-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server