list_connections
View active database connections to monitor usage, identify sessions, and manage resources in SQL Server.
Instructions
List all active database connections.
Returns:
List of active connections with their details (name, host, database,
connection time, and active status).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mssql_mcp/server.py:169-194 (handler)The main MCP tool handler for 'list_connections', decorated with @mcp.tool(). It retrieves active connections from the manager and formats them for return.@mcp.tool() def list_connections() -> dict[str, Any]: """List all active database connections. Returns: List of active connections with their details (name, host, database, connection time, and active status). """ try: manager = get_connection_manager() connections = manager.list_connections() return { "connections": [ { "name": info.name, "host": info.host, "database": info.database, "connected_at": info.connected_at.isoformat(), "is_active": info.is_active, } for info in connections.values() ] } except Exception as e: logger.error(f"Error listing connections: {e}") return {"status": "error", "error": str(e)}
- src/mssql_mcp/connection.py:27-35 (schema)Dataclass defining the structure of ConnectionInfo, used to represent connection details in list_connections response.@dataclass class ConnectionInfo: """Information about an active database connection.""" name: str host: str database: str connected_at: datetime is_active: bool = True
- src/mssql_mcp/connection.py:144-146 (helper)ConnectionManager helper method that filters and returns active connections as dict[str, ConnectionInfo].def list_connections(self) -> dict[str, ConnectionInfo]: """Return all active connections.""" return {k: v for k, v in self._connections.items() if v.is_active}