Skip to main content
Glama
bpamiri
by bpamiri

disconnect

Close all active connections to the SQL Server database to free resources, ensure clean shutdowns, or prepare for maintenance. Returns disconnection status and count of closed connections.

Instructions

Close all connections to the SQL Server database.

Returns: Disconnection status and count of closed connections.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the 'disconnect' MCP tool. It calls disconnect_all on the connection manager and returns a status dictionary.
    @mcp.tool() def disconnect() -> dict[str, Any]: """Close all connections to the SQL Server database. Returns: Disconnection status and count of closed connections. """ try: manager = get_connection_manager() closed = manager.disconnect_all() return { "status": "disconnected", "connections_closed": closed, } except Exception as e: logger.error(f"Error during disconnect: {e}") return {"status": "error", "error": str(e)}
  • Core logic for disconnecting all managed connections by iterating and calling disconnect(name) on each.
    def disconnect_all(self) -> int: """Close all connections. Returns: Count of closed connections """ names = list(self._connections.keys()) count = 0 for name in names: if self.disconnect(name): count += 1 return count
  • Low-level disconnect method for a specific connection name, which closes the pymssql connection and updates tracking.
    def disconnect(self, name: str = "default") -> bool: """Close a named connection. Args: name: Name of the connection to close Returns: True if connection was closed, False if not found """ if name not in self._connections: return False try: if self._connection: self._connection.close() self._connection = None self._connections[name].is_active = False del self._connections[name] logger.info(f"Disconnected connection '{name}'") return True except pymssql.Error as e: logger.warning(f"Error during disconnect: {e}") return False

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/mssql-mcp'

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