Skip to main content
Glama
bpamiri

SQL Server MCP

by bpamiri

list_databases

Discover available databases on SQL Server by querying sys.databases, excluding system databases by default and respecting blocklist configurations to identify accessible data sources.

Instructions

List all available databases on the SQL Server.

Queries sys.databases to discover accessible databases. System databases
(master, tempdb, model, msdb) are excluded by default. Databases in the
blocklist (MSSQL_BLOCKED_DATABASES) are always excluded.

Args:
    include_system: If True, include system databases in the list

Returns:
    Dictionary with:
    - databases: List of available database names
    - current_database: The currently active database
    - count: Number of databases returned
    - blocked_count: Number of databases hidden due to blocklist

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
include_systemNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'list_databases' tool. It queries sys.databases, filters out blocked and system databases (unless include_system=True), and returns a dict with the list of databases, current database, count, and blocked count.
    @mcp.tool()
    def list_databases(include_system: bool = False) -> dict[str, Any]:
        """List all available databases on the SQL Server.
    
        Queries sys.databases to discover accessible databases. System databases
        (master, tempdb, model, msdb) are excluded by default. Databases in the
        blocklist (MSSQL_BLOCKED_DATABASES) are always excluded.
    
        Args:
            include_system: If True, include system databases in the list
    
        Returns:
            Dictionary with:
            - databases: List of available database names
            - current_database: The currently active database
            - count: Number of databases returned
            - blocked_count: Number of databases hidden due to blocklist
        """
        try:
            manager = get_connection_manager()
            config = manager.config
            blocked_databases = config.blocked_databases
    
            # Query all databases
            query = """
                SELECT name, database_id, state_desc
                FROM sys.databases
                WHERE state_desc = 'ONLINE'
                ORDER BY name
            """
            rows = manager.execute_query(query)
    
            # Filter databases
            databases = []
            blocked_count = 0
    
            for row in rows:
                db_name = row["name"]
                db_name_lower = db_name.lower()
    
                # Check if blocked
                if db_name_lower in blocked_databases:
                    blocked_count += 1
                    continue
    
                # Check if system database
                if not include_system and db_name_lower in SYSTEM_DATABASES:
                    continue
    
                databases.append(db_name)
    
            # Get current database
            current_db_query = "SELECT DB_NAME() AS current_database"
            current_db_result = manager.execute_query(current_db_query)
            current_database = current_db_result[0]["current_database"] if current_db_result else None
    
            return {
                "databases": databases,
                "current_database": current_database,
                "count": len(databases),
                "blocked_count": blocked_count,
            }
    
        except Exception as e:
            logger.error(f"Error listing databases: {e}")
            return {"error": str(e)}
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing key behaviors: it queries sys.databases, excludes system databases by default, respects a blocklist, and returns structured data. It doesn't mention authentication needs, rate limits, or whether it's read-only (though implied), leaving some gaps.

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 well-structured and front-loaded with the core purpose, followed by implementation details, parameter explanation, and return format. Every sentence adds value without redundancy, making it efficient and easy to parse.

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

Completeness5/5

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

Given the tool's low complexity (1 parameter), no annotations, and the presence of an output schema that documents return values, the description is complete. It covers purpose, behavior, parameter semantics, and output structure adequately without needing to explain return values in detail.

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

Parameters5/5

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

The description adds significant meaning beyond the input schema, which has 0% description coverage. It explains the include_system parameter's effect ('include system databases in the list'), compensating fully for the schema's lack of documentation and providing clear usage context.

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 ('List all available databases') and resource ('on the SQL Server'), distinguishing it from siblings like list_tables or list_stored_procs. It provides precise scope details about system databases and blocklist exclusions.

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 by specifying what databases are excluded and when to use the include_system parameter. However, it doesn't explicitly state when to choose this tool over alternatives like list_connections or describe_table, nor does it mention prerequisites like requiring an active connection.

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