Skip to main content
Glama
bpamiri

SQL Server MCP

by bpamiri

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
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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)}
  • 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
  • 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}

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/bpamiri/pymssql-mcp'

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