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
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mssql_mcp/server.py:150-167 (handler)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)}
- src/mssql_mcp/connection.py:131-143 (helper)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
- src/mssql_mcp/connection.py:104-130 (helper)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