Skip to main content
Glama
abhijeetka
by abhijeetka

annotate_resource

Add annotations to Kubernetes resources like pods, services, or deployments to add metadata for tracking, configuration, or automation purposes.

Instructions

Annotate a Kubernetes resource with the specified annotation

Args:
    resource_type: Type of the resource (e.g., pod, service, deployment)
    resource_name: Name of the resource to annotate
    annotation: Annotation to add (e.g., key=value)
    namespace: Namespace of the resource

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
resource_typeYes
resource_nameYes
annotationYes
namespaceNodefault

Implementation Reference

  • The handler function for the 'annotate_resource' tool. It uses kubectl to annotate a specified Kubernetes resource with the given annotation key-value pair in the specified namespace.
    @mcp.tool()
    async def annotate_resource(resource_type: str, resource_name: str, annotation: str, namespace: str = "default") -> dict:
        """Annotate a Kubernetes resource with the specified annotation
    
        Args:
            resource_type: Type of the resource (e.g., pod, service, deployment)
            resource_name: Name of the resource to annotate
            annotation: Annotation to add (e.g., key=value)
            namespace: Namespace of the resource
        """
        try:
            cmd = ["kubectl", "annotate", resource_type, resource_name, annotation, "-n", namespace, "--overwrite"]
            result = subprocess.run(cmd, capture_output=True, text=True, check=True)
            return {"message": f"Resource {resource_type}/{resource_name} annotated successfully in namespace {namespace}",
                    "details": result.stdout}
        except subprocess.CalledProcessError as e:
            return {"error": f"Failed to annotate resource: {str(e)}"}

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