disconnect
Close all active connections to the SQL Server database and return the disconnection status with 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, decorated with @mcp.tool(). It calls ConnectionManager.disconnect_all() via the global manager and returns a status dict with the number of closed connections.@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/server.py:150-150 (registration)The @mcp.tool() decorator registers the disconnect function as an MCP tool.@mcp.tool()
- src/mssql_mcp/connection.py:131-143 (helper)ConnectionManager.disconnect_all() method, invoked by the tool handler. Closes all tracked connections by calling self.disconnect() on each and returns the count.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)Core ConnectionManager.disconnect() method that closes the pymssql.Connection and removes it from 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