Skip to main content
Glama
sharansahu

MCP SQL Agent

by sharansahu

list_tables

Retrieve a list of all tables within a database using the MCP SQL Agent. Simplifies schema exploration by providing a clear overview of available tables.

Instructions

List all tables in the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Handler function for the 'list_tables' MCP tool in the SQLite server implementation. Uses @mcp.tool() decorator for registration and executes a SQLite query to list all tables.
    @mcp.tool()
    def list_tables() -> str:
        """List all tables in the database"""
        conn = sqlite3.connect(db_path)
        try:
            tables_query = "SELECT name FROM sqlite_master WHERE type='table';"
            tables = conn.execute(tables_query).fetchall()
            table_list = "Available tables:\n"
            for (table_name,) in tables:
                table_list += f"- {table_name}\n"
            return table_list
        except Exception as e:
            return f"Error: {str(e)}"
        finally:
            conn.close()
  • Handler function for the 'list_tables' MCP tool in the MySQL server implementation. Uses @mcp.tool() decorator for registration and queries information_schema.TABLES.
    @mcp.tool()
    def list_tables() -> str:
        """List all tables in the database"""
        try:
            conn = mysql.connector.connect(**db_config)
            cursor = conn.cursor()
            
            tables_query = """
            SELECT TABLE_NAME 
            FROM information_schema.TABLES 
            WHERE TABLE_SCHEMA = %s
            """
            cursor.execute(tables_query, (db_config['database'],))
            tables = cursor.fetchall()
            
            table_list = "Available tables:\n"
            for (table_name,) in tables:
                table_list += f"- {table_name}\n"
            return table_list
        except Exception as e:
            return f"Error: {str(e)}"
        finally:
            if 'cursor' in locals():
                cursor.close()
            if 'conn' in locals():
                conn.close()
  • Handler function for the 'list_tables' MCP tool in the Oracle server implementation. Uses @mcp.tool() decorator for registration and queries user_tables.
    @mcp.tool()
    def list_tables() -> str:
        """List all tables in the database"""
        try:
            conn = cx_Oracle.connect(**db_config)
            cursor = conn.cursor()
            
            tables_query = """
            SELECT table_name 
            FROM user_tables 
            ORDER BY table_name
            """
            cursor.execute(tables_query)
            tables = cursor.fetchall()
            
            table_list = "Available tables:\n"
            for (table_name,) in tables:
                table_list += f"- {table_name}\n"
            return table_list
        except Exception as e:
            return f"Error: {str(e)}"
        finally:
            if 'cursor' in locals():
                cursor.close()
            if 'conn' in locals():
                conn.close()
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action but doesn't cover aspects like pagination, sorting, rate limits, permissions required, or what the output includes (e.g., table names only or metadata). This leaves significant gaps for an agent to understand how to use it effectively.

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 a single, clear sentence with no wasted words. It's front-loaded with the core action and resource, making it easy to parse quickly. Every word earns its place by conveying essential information.

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

Completeness3/5

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

Given the tool's simplicity (0 parameters, output schema exists), the description is minimally adequate. However, with no annotations and siblings like 'search_tables', it lacks context on when to use it versus alternatives. The output schema should cover return values, but behavioral aspects like performance or limitations are missing.

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, and schema description coverage is 100%, so no parameter documentation is needed. The description doesn't add parameter details, but that's appropriate here, as there are no parameters to explain. A baseline of 4 is given for tools with no parameters.

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

Purpose4/5

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

The description clearly states the verb ('List') and resource ('all tables in the database'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'search_tables' or 'describe_table', which could offer similar functionality with different scopes or details.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives like 'search_tables' (for filtered searches) or 'describe_table' (for detailed metadata). The description implies a broad listing but doesn't specify use cases, prerequisites, or exclusions.

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

Related 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/sharansahu/mcp-sql'

If you have feedback or need assistance with the MCP directory API, please join our Discord server