Skip to main content
Glama

handle_diagnose_locks

Analyzes and resolves lock contention in Redshift clusters by identifying active locks, filtering by process ID, table name, or wait time, and providing detailed reports for troubleshooting.

Instructions

Identifies active lock contention in the cluster.

Fetches all current lock information and then filters it based on the
optional target PID, target table name, and minimum wait time.
Formats the results into a list of contention details and a summary.

Args:
    ctx: The MCP context object.
    target_pid: Optional: Filter results to show locks held by or waited
                for by this specific process ID (PID).
    target_table_name: Optional: Filter results for locks specifically on
                       this table name (schema qualification recommended
                       if ambiguous).
    min_wait_seconds: Minimum seconds a lock must be in a waiting state
                      to be included. Defaults to 5.

Returns:
    A list of dictionaries, where each dictionary represents a row
    from the lock contention query result.

Raises:
    DataApiError: If fetching the initial lock information fails.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
min_wait_secondsNo
target_pidNo
target_table_nameNo

Implementation Reference

  • The core handler function for the 'handle_diagnose_locks' tool. It loads and executes a SQL script to diagnose locks, applies optional filters, and returns the results.
    @mcp.tool()
    async def handle_diagnose_locks(
        ctx: Context,
        target_pid: Optional[int] = None,
        target_table_name: Optional[str] = None,
        min_wait_seconds: int = 5,
    ) -> List[Dict[str, Any]]:
        """Identifies active lock contention in the cluster.
    
        Fetches all current lock information and then filters it based on the
        optional target PID, target table name, and minimum wait time.
        Formats the results into a list of contention details and a summary.
    
        Args:
            ctx: The MCP context object.
            target_pid: Optional: Filter results to show locks held by or waited
                        for by this specific process ID (PID).
            target_table_name: Optional: Filter results for locks specifically on
                               this table name (schema qualification recommended
                               if ambiguous).
            min_wait_seconds: Minimum seconds a lock must be in a waiting state
                              to be included. Defaults to 5.
    
        Returns:
            A list of dictionaries, where each dictionary represents a row
            from the lock contention query result.
    
        Raises:
            DataApiError: If fetching the initial lock information fails.
        """
        ctx.info("Starting lock diagnosis...")
        ctx.debug(
            f"Lock diagnosis filters - PID: {target_pid}, Table: {target_table_name}, MinWait: {min_wait_seconds}s"
        )
    
        lock_script: str = "locks/blocking_pids.sql"
        all_locks: List[Dict[str, Any]] = []
    
        try:
            sql: str = load_sql(lock_script)
            config: DataApiConfig = get_data_api_config()
            all_locks: List[Dict[str, Any]] = await execute_sql(config=config, sql=sql)
            ctx.debug(f"Retrieved {len(all_locks)} raw lock entries.")
    
        except (
            SqlScriptNotFoundError,
            DataApiError,
            SqlExecutionError,
            ClientError,
            Exception,
        ) as e:
            ctx.error(f"Failed to retrieve lock information: {e}", exc_info=True)
            raise DataApiError(f"Failed to retrieve lock information: {e}")
    
        ctx.info("Lock diagnosis completed.")
        return all_locks
  • Imports the 'diagnose_locks' handler module (and others) into the FastMCP server context, triggering automatic tool registration via the @mcp.tool() decorator.
    from .tools.handlers import (  # noqa: E402
        check_cluster_health,
        diagnose_locks,
        diagnose_query_performance,
        execute_ad_hoc_query,
        get_table_definition,
        inspect_table,
        monitor_workload,
    )
    
    
    from .resources import handlers as resource_handlers  # noqa: E402
    
    
    from .prompts import handlers as prompt_handlers  # noqa: E402
    
    
    _ = (
        check_cluster_health,
        diagnose_locks,
        diagnose_query_performance,
        execute_ad_hoc_query,
        get_table_definition,
        inspect_table,
        monitor_workload,
        resource_handlers,
        prompt_handlers,
    )
  • Exposes the 'handle_diagnose_locks' function via __init__.py for easy import in the server registration.
    # src/redshift_utils_mcp/tools/handlers/__init__.py
    """Exports tool handlers."""
    from .check_cluster_health import handle_check_cluster_health
    from .diagnose_locks import handle_diagnose_locks
    from .diagnose_query_performance import handle_diagnose_query_performance
    from .execute_ad_hoc_query import handle_execute_ad_hoc_query
    from .get_table_definition import handle_get_table_definition
    from .inspect_table import handle_inspect_table
    from .monitor_workload import handle_monitor_workload
    
    __all__ = [
        "handle_check_cluster_health",
        "handle_diagnose_locks",
        "handle_diagnose_query_performance",
        "handle_execute_ad_hoc_query",
        "handle_get_table_definition",
        "handle_inspect_table",
        "handle_monitor_workload",
    ]
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by explaining the tool's multi-step behavior: fetching all lock information, applying optional filters, formatting results into list+summary structure, and potential error conditions (DataApiError). It doesn't mention permissions, rate limits, or side effects, leaving some behavioral gaps.

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 appropriately sized and well-structured with clear sections (purpose, args, returns, raises). While efficient, the parameter explanations could be slightly more concise, and the purpose statement could be more front-loaded before diving into implementation details.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a diagnostic tool with 3 parameters, no annotations, and no output schema, the description provides good coverage: clear purpose, parameter semantics, return format (list of dictionaries), and error conditions. It could improve by explaining the summary structure or providing example output, but overall it's reasonably complete given the context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description fully compensates by providing detailed semantic explanations for all three parameters: target_pid (filter by process ID), target_table_name (filter by table with schema qualification note), and min_wait_seconds (minimum waiting time with default). The descriptions add meaningful context beyond basic schema types.

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 tool's purpose with specific verbs ('identifies', 'fetches', 'filters', 'formats') and resource ('active lock contention in the cluster'). It distinguishes itself from siblings by focusing specifically on lock diagnostics rather than general health, performance, or table operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context through parameter explanations (filtering by PID, table name, wait time) but doesn't explicitly state when to use this tool versus alternatives like handle_check_cluster_health or handle_diagnose_query_performance. No explicit when-not-to-use guidance or named alternatives are provided.

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

Related 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/vinodismyname/redshift-utils-mcp'

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