show_sessions
View active database sessions in a CockroachDB cluster to monitor current queries and connections for performance analysis and troubleshooting.
Instructions
Show active sessions in the cluster.
Args:
active_only: Only show sessions with active queries.
Returns:
List of sessions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| active_only | No |
Implementation Reference
- src/cockroachdb_mcp/server.py:486-499 (handler)MCP tool handler for 'show_sessions'. Registered with @mcp.tool() decorator and delegates execution to the cluster helper function.@mcp.tool() async def show_sessions(active_only: bool = True) -> dict[str, Any]: """Show active sessions in the cluster. Args: active_only: Only show sessions with active queries. Returns: List of sessions. """ try: return await cluster.show_sessions(active_only) except Exception as e: return {"status": "error", "error": str(e)}
- Underlying helper function that executes the SQL query against crdb_internal.cluster_sessions to retrieve and format session information.async def show_sessions(active_only: bool = True) -> dict[str, Any]: """Show active sessions in the cluster. Args: active_only: Only show active sessions. Returns: List of sessions. """ conn = await connection_manager.ensure_connected() try: query = """ SELECT session_id, node_id, user_name, client_address, application_name, active_queries, start FROM crdb_internal.cluster_sessions """ if active_only: query += " WHERE active_queries != '{}'" query += " ORDER BY start DESC" async with conn.cursor() as cur: await cur.execute(query) rows = await cur.fetchall() sessions = [] for row in rows: sessions.append( { "session_id": row.get("session_id"), "node_id": row.get("node_id"), "user": row.get("user_name"), "client_address": row.get("client_address"), "application": row.get("application_name"), "active_queries": row.get("active_queries"), "started": str(row.get("start")) if row.get("start") else None, } ) return {"sessions": sessions, "count": len(sessions)} except Exception as e: return {"status": "error", "error": str(e)}