show_sessions
View active sessions in a CockroachDB cluster to monitor current queries and connection activity 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
- Core implementation of show_sessions tool: queries crdb_internal.cluster_sessions, filters active sessions if requested, formats and returns session details.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)}
- src/cockroachdb_mcp/server.py:487-499 (registration)MCP tool registration for 'show_sessions' using @mcp.tool() decorator, which delegates execution to the cluster module implementation.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)}