""" MCP tool for resolving TiDB Observability Delta Lake table paths from GS clusters API. """ from pydantic import ValidationError as PydanticValidationError from src.models.get_o11y_delta_path import GetO11yDeltaPathRequest from src.services.auth import get_valid_server_auth from src.services.observability_resolve import resolve_slowlog_delta_path from src.tools.query_range import mcp from src.utils.errors import AuthServiceError, NetworkError, ValidationError from src.utils.logging_utils import get_logger from src.utils.tool_response import format_tool_error, tool_text_response logger = get_logger("tool.get_o11y_delta_path") @mcp.tool() async def get_o11y_delta_path( cluster_id: str, env: str, deploy_type: str, ) -> list[dict[str, str]]: """ Resolve the slowlog and sql_statement Delta Lake table paths for a cluster. Supports clusters resolved from AWS, Alicloud, and GCP Observability domains. The returned URI scheme is inferred from the resolved provider: - AWS/Alicloud: `s3://` - GCP: `gs://` Args: cluster_id: TiDB Cloud cluster ID (applicationID). env: Environment for biz_type resolution (e.g. 'prod', 'staging'). deploy_type: Cluster deploy type (e.g. 'dedicated', 'premium', 'starter'). """ try: logger.info( "tool_call_start name=get_o11y_delta_path cluster_id=%s env=%s deploy_type=%s", cluster_id, env, deploy_type, ) await get_valid_server_auth() try: request = GetO11yDeltaPathRequest.model_validate( { "cluster_id": str(cluster_id).strip(), "env": env.strip(), "deploy_type": deploy_type.strip(), } ) except (ValueError, PydanticValidationError) as e: raise ValidationError(f"Invalid Delta path parameters: {str(e)}") from e path_result = await resolve_slowlog_delta_path( cluster_id=request.cluster_id, env=request.env, deploy_type=request.deploy_type, ) logger.info( "tool_call_success name=get_o11y_delta_path cluster_id=%s", request.cluster_id, ) responses = [{"type": "text", "text": path_result.slowlog_path}] if path_result.sql_statement_path is not None: responses.append({"type": "text", "text": path_result.sql_statement_path}) return responses except (AuthServiceError, ValidationError, NetworkError) as e: logger.warning("tool_call_error name=get_o11y_delta_path type=%s", e.__class__.__name__) return tool_text_response(format_tool_error(e)) except Exception as e: logger.exception("tool_call_unexpected_error name=get_o11y_delta_path") return tool_text_response(format_tool_error(e))