Skip to main content
Glama
BenedatLLC

Kubernetes Tools MCP Server

by BenedatLLC

get_pod_events

Retrieve Kubernetes pod events to diagnose issues and monitor pod lifecycle changes in your cluster.

Instructions

Get events for a specific Kubernetes pod. This is equivalent to the kubectl command:
`kubectl get events -n NAMESPACE --field-selector involvedObject.name=POD_NAME,involvedObject.kind=Pod`

Parameters
----------
pod_name : str
    Name of the pod to retrieve events for.
namespace : str, optional
    Namespace of the pod (default is "default").

Returns
-------
list of EventSummary
    List of events associated with the specified pod. Each EventSummary has the following fields:

    last_seen : Optional[datetime.datetime]
        Timestamp of the last occurrence of the event (if available).
    type : str
        Type of the event.
    reason : str
        Reason for the event.
    object : str
        The object this event applies to.
    message : str
        Message describing the event.
Raises
------
K8sConfigError
    If unable to initialize the K8S API.
K8sApiError
    If the API call to list events fails.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pod_nameYes
namespaceNodefault

Implementation Reference

  • Pydantic model defining the output structure for events returned by get_pod_events.
    class EventSummary(BaseModel):
        """This is the representation of a Kubernetes Event"""
        last_seen: Optional[datetime.timedelta]  # Time since event occurred
        type: str
        reason: str
        object: str
        message: str
  • Core handler function that fetches pod events from Kubernetes API using field selector and maps to EventSummary objects.
    def get_pod_events(pod_name: str, namespace: str = "default") -> list[EventSummary]:
        """
        Get events for a specific Kubernetes pod. This is equivalent to the kubectl command:
        `kubectl get events -n NAMESPACE --field-selector involvedObject.name=POD_NAME,involvedObject.kind=Pod`
    
        Parameters
        ----------
        pod_name : str
            Name of the pod to retrieve events for.
        namespace : str, optional
            Namespace of the pod (default is "default").
    
        Returns
        -------
        list of EventSummary
            List of events associated with the specified pod. Each EventSummary has the following fields:
    
            last_seen : Optional[datetime.datetime]
                Timestamp of the last occurrence of the event (if available).
            type : str
                Type of the event.
            reason : str
                Reason for the event.
            object : str
                The object this event applies to.
            message : str
                Message describing the event.
        Raises
        ------
        K8sConfigError
            If unable to initialize the K8S API.
        K8sApiError
            If the API call to list events fails.
        """
        global K8S
        if K8S is None:
            K8S = _get_api_client()
        logging.info(f"get_pod_events(pod_name={pod_name}, namespace={namespace})")
        field_selector = f"involvedObject.name={pod_name}"
        events = K8S.list_namespaced_event(namespace, field_selector=field_selector)
        now = datetime.datetime.now(datetime.timezone.utc)
        return [
            EventSummary(
                last_seen=(now - event.last_timestamp) if event.last_timestamp else None,
                type=event.type,
                reason=event.reason,
                object=getattr(event.involved_object, 'name', pod_name),
                message=event.message,
            )
            for event in events.items
        ]
  • Registration of get_pod_events in the TOOLS list for MCP integration.
    TOOLS = [
        get_namespaces,
        get_node_summaries,
        get_pod_summaries,
        get_pod_container_statuses,
        get_pod_events,
        get_pod_spec,
        get_logs_for_pod_and_container,
        get_deployment_summaries,
        get_service_summaries
    ]

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/BenedatLLC/k8stools'

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