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
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- servers/mcp_server_sqlite.py:64-78 (handler)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()
- servers/mcp_server_mysql.py:91-116 (handler)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()
- servers/mcp_server_oracle.py:101-126 (handler)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()