Skip to main content
Glama
bpamiri

SQL Server MCP

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

Output 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
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden. It discloses the action ('Close all connections') and return information ('Disconnection status and count of closed connections'), which helps understand the tool's behavior. However, it doesn't mention potential side effects (e.g., whether this affects active queries, requires specific permissions, or has rate limits).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly concise with two sentences that each earn their place: the first states the action, the second describes the return value. It's front-loaded with the core purpose and wastes no words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has no parameters, an output schema exists, and no annotations are provided, the description covers the essential purpose and return information well. However, for a potentially destructive operation like closing all connections, additional context about prerequisites or side effects would enhance completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has 0 parameters with 100% schema description coverage, so the schema already fully documents the lack of inputs. The description appropriately doesn't add parameter information beyond what the schema provides, maintaining focus on the tool's purpose and behavior.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Close all connections') and target resource ('SQL Server database'), distinguishing it from sibling tools like 'list_connections' or 'connect'. It uses precise verbs and identifies the exact scope of operation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context (when you want to close database connections) but doesn't explicitly state when to use this versus alternatives like 'list_connections' for monitoring or 'connect' for establishing connections. It provides clear purpose but lacks explicit comparison to sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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