Skip to main content
Glama
bpamiri

SQL Server MCP

by bpamiri

list_tables

Discover database tables and views in SQL Server with optional filtering by schema, name pattern, or view inclusion to analyze database structure.

Instructions

List all tables and views in the database.

Args:
    schema: Filter by schema name (e.g., 'dbo'). If not specified, returns all schemas.
    include_views: Include views in results (default: True)
    pattern: Filter by name pattern using SQL LIKE syntax (e.g., 'Cust%', '%Order%')

Returns:
    Dictionary with:
    - tables: List of table/view info (schema, name, type)
    - count: Number of results

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNo
include_viewsNo
patternNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'list_tables' tool, decorated with @mcp.tool(). It queries INFORMATION_SCHEMA.TABLES to list tables and views, applying optional filters for schema, inclusion of views, and name pattern. Returns a dictionary with the list of tables and count, or an error message.
    @mcp.tool()
    def list_tables(
        schema: str | None = None,
        include_views: bool = True,
        pattern: str | None = None,
    ) -> dict[str, Any]:
        """List all tables and views in the database.
    
        Args:
            schema: Filter by schema name (e.g., 'dbo'). If not specified, returns all schemas.
            include_views: Include views in results (default: True)
            pattern: Filter by name pattern using SQL LIKE syntax (e.g., 'Cust%', '%Order%')
    
        Returns:
            Dictionary with:
            - tables: List of table/view info (schema, name, type)
            - count: Number of results
        """
        try:
            manager = get_connection_manager()
    
            # Build query with optional filters
            query = """
                SELECT
                    TABLE_SCHEMA as [schema],
                    TABLE_NAME as [name],
                    TABLE_TYPE as [type]
                FROM INFORMATION_SCHEMA.TABLES
                WHERE TABLE_CATALOG = DB_NAME()
            """
    
            params: list[Any] = []
    
            if schema:
                query += " AND TABLE_SCHEMA = %s"
                params.append(schema)
    
            if not include_views:
                query += " AND TABLE_TYPE = 'BASE TABLE'"
    
            if pattern:
                query += " AND TABLE_NAME LIKE %s"
                params.append(pattern)
    
            query += " ORDER BY TABLE_SCHEMA, TABLE_NAME"
    
            rows = manager.execute_query(query, tuple(params) if params else None)
    
            # Convert rows to list of dicts
            tables = [
                {
                    "schema": row["schema"],
                    "name": row["name"],
                    "type": "TABLE" if row["type"] == "BASE TABLE" else "VIEW",
                }
                for row in rows
            ]
    
            return {
                "tables": tables,
                "count": len(tables),
            }
    
        except Exception as e:
            logger.error(f"Error listing tables: {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 the full burden. It effectively discloses that this is a read operation (listing), describes filtering behavior, and specifies the return format. However, it doesn't mention potential limitations like pagination, rate limits, or authentication requirements.

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?

Perfectly structured with a clear purpose statement followed by organized sections for Args and Returns. Every sentence earns its place, providing essential information without redundancy. The description is appropriately sized and front-loaded.

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 moderate complexity, no annotations, and the presence of an output schema, the description is complete. It explains what the tool does, documents all parameters thoroughly, and references the return structure, making it fully adequate for agent understanding.

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 schema has 0% description coverage, so the description fully compensates by explaining all three parameters with clear semantics, examples, and default values. It adds significant value beyond the bare schema, making parameter usage understandable.

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 tables and views') and resource ('in the database'), distinguishing it from siblings like list_databases, list_stored_procs, or describe_table. It precisely defines the scope of what is being listed.

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

Usage Guidelines3/5

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

The description implies usage for retrieving database objects, but provides no explicit guidance on when to use this tool versus alternatives like list_databases or describe_table. It mentions filtering capabilities but doesn't contrast with other listing 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