Skip to main content
Glama
alaturqua

MCP Trino Server

by alaturqua

expire_snapshots

Remove outdated snapshots from Iceberg tables to free storage space and maintain performance using a configurable retention threshold.

Instructions

Remove old snapshots from an Iceberg table

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
catalogYescatalog name
schema_nameYesschema name
retention_thresholdNoAge threshold for snapshot removal (e.g., '7d', '30d')7d
tableYesThe name of the table

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • src/server.py:179-200 (registration)
    Tool registration for expire_snapshots in the MCP server – defines the tool with required parameters (catalog, schema_name, table) and optional retention_threshold (default '7d'), then delegates to the client method.
    @mcp.tool(description="Remove old snapshots from an Iceberg table")
    def expire_snapshots(
        catalog: str = Field(description="catalog name "),
        schema_name: str = Field(description="schema name "),
        retention_threshold: str = Field(
            description="Age threshold for snapshot removal (e.g., '7d', '30d')", default="7d"
        ),
        table: str = Field(description="The name of the table"),
    ) -> str:
        """Remove old snapshots from an Iceberg table.
    
        Args:
            catalog: catalog name
            schema_name: schema name
            table: The name of the table
            retention_threshold: Age threshold for snapshot removal (e.g., "7d", "30d")
    
        Returns:
            str: Confirmation message
        """
        return client.expire_snapshots(catalog, schema_name, table, retention_threshold)
  • Core handler that builds and executes the SQL query (ALTER TABLE ... EXECUTE expire_snapshots) against Trino, with fallback to configured defaults for catalog/schema and a CatalogSchemaError check.
    def expire_snapshots(
        self,
        catalog: str,
        table: str,
        schema: str,
        retention_threshold: str = "7d",
    ) -> str:
        """Remove old snapshots from an Iceberg table.
    
        This operation removes snapshots older than the specified retention threshold,
        helping to manage storage and improve performance.
    
        Args:
            table: The name of the table.
            retention_threshold: Age threshold for snapshot removal (e.g., "7d").
            catalog: The catalog name. If None, uses configured default.
            schema: The schema name. If None, uses configured default.
    
        Returns:
            Success message indicating snapshots were expired.
    
        Raises:
            CatalogSchemaError: If either catalog or schema is not specified and not configured.
        """
        catalog = catalog or self.config.catalog
        schema = schema or self.config.schema
        if not catalog or not schema:
            msg = "Both catalog and schema must be specified"
            raise CatalogSchemaError(msg)
        query = (
            f"ALTER TABLE {catalog}.{schema}.{table} "
            f"EXECUTE expire_snapshots(retention_threshold => '{retention_threshold}')"
        )
        self.execute_query(query)
        return f"Snapshots older than {retention_threshold} expired for table {catalog}.{schema}.{table}"
  • Helper method execute_query used by expire_snapshots to run the generated SQL and return results.
    def execute_query(self, query: str) -> str:
        """Execute a SQL query against Trino and return results as a formatted string.
    
        Args:
            query (str): The SQL query to execute.
            params (Optional[dict]): Dictionary of query parameters with primitive types.
    
        Returns:
            str: JSON-formatted string containing query results or success message.
        """
        cur: trino.dbapi.Cursor = self.client.cursor()
        cur.execute(query)
        if cur.description:
            return json.dumps(
                [dict(zip([col[0] for col in cur.description], row, strict=True)) for row in cur.fetchall()],
                default=str,
            )
        return "Query executed successfully (no results to display)"
  • Error class raised by expire_snapshots when catalog/schema are missing.
    class CatalogSchemaError(TrinoError):
        """Error raised when catalog or schema information is missing."""
    
        def __init__(self):
            super().__init__("Both catalog and schema must be specified")
  • Configuration schema – TrinoConfig provides default catalog and schema values that expire_snapshots falls back to if not explicitly provided.
    @dataclass
    class TrinoConfig:
        """Configuration class for Trino connection settings."""
    
        host: str
        port: int
        user: str
        catalog: str | None = None
        schema: str | None = None
        http_scheme: str = "http"
        auth: trino.auth.BasicAuthentication | None = None
        source: str = "mcp-trino-python"
    
    
    def load_config() -> TrinoConfig:
        """Load Trino configuration from environment variables."""
        load_dotenv(override=True)
    
        return TrinoConfig(
            host=os.getenv("TRINO_HOST", "localhost"),
            port=int(os.getenv("TRINO_PORT", "8080")),
            user=os.getenv("TRINO_USER", os.getenv("USER", "trino")),
            catalog=os.getenv("TRINO_CATALOG"),
            schema=os.getenv("TRINO_SCHEMA"),
            http_scheme=os.getenv("TRINO_HTTP_SCHEME", "http"),
            auth=None
            if os.getenv("TRINO_PASSWORD", None) is None
            else trino.auth.BasicAuthentication(os.getenv("TRINO_USER", None), os.getenv("TRINO_PASSWORD", None)),
            source="mcp-trino-python",
        )
Behavior2/5

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

With no annotations, the description must disclose behavioral traits. It only states 'Remove old snapshots' but does not indicate that this is a destructive operation, whether permissions are required, what happens to associated data, or impact on table availability.

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?

The description is a single concise sentence that clearly states the purpose. It is front-loaded and efficient, though some additional behavioral details could be included without sacrificing conciseness.

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?

Given that this is a destructive tool with no annotations and 4 parameters, the description is too brief. It does not mention the retention_threshold default or any side effects. The output schema exists but the description should still summarize expected behavior.

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?

The input schema has 100% parameter description coverage, so the baseline is 3. The description does not add additional meaning beyond the schema; it merely restates the overall purpose. No new parameter context is provided.

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

Purpose5/5

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

The description clearly states the action 'Remove old snapshots' on a specific resource 'Iceberg table'. It distinguishes this tool from siblings like 'show_snapshots' which lists snapshots, as it is the only tool for removing snapshots.

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 is provided on when to use this tool versus alternatives such as 'optimize_manifests' or other maintenance operations. There is no mention of prerequisites, conditions, or situations where it should be avoided.

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/alaturqua/mcp-trino-python'

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