get_namespace_details
Retrieve detailed information about a specific Kubernetes namespace, including its configuration and status, to monitor and manage cluster resources effectively.
Instructions
Get detailed information about a specific namespace.
Args: context_name: The Kubernetes context name namespace: The name of the namespace to get details for
Returns: JSON string containing detailed information about the namespace
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context_name | Yes | ||
| namespace | Yes |
Implementation Reference
- tools/namespace.py:31-65 (handler)The primary handler for the 'get_namespace_details' MCP tool. Decorated with @mcp.tool() for automatic registration and @use_current_context for context management. Fetches namespace details via Kubernetes API, extracts key metadata, and returns formatted JSON or error messages.@mcp.tool() @use_current_context def get_namespace_details(context_name: str, namespace: str): """ Get detailed information about a specific namespace. Args: context_name: The Kubernetes context name namespace: The name of the namespace to get details for Returns: JSON string containing detailed information about the namespace """ core_v1: CoreV1Api = get_api_clients(context_name)["core"] try: ns = core_v1.read_namespace(namespace) # Extract useful information result = { "name": ns.metadata.name, "status": ns.status.phase, "labels": ns.metadata.labels if ns.metadata.labels else {}, "annotations": ns.metadata.annotations if ns.metadata.annotations else {}, "created": ns.metadata.creation_timestamp.strftime( "%Y-%m-%dT%H:%M:%SZ") if ns.metadata.creation_timestamp else None } return json.dumps(result) except ApiException as e: if e.status == 404: return json.dumps({"error": f"Namespace '{namespace}' not found"}) else: return json.dumps({"error": f"API error: {str(e)}"})
- server/server.py:14-14 (registration)Import statement in load_modules() function that loads the tools/namespace.py module, triggering the execution of @mcp.tool() decorators to register the get_namespace_details tool with the MCP server.import tools.namespace # noqa: F401