list_views
List all views in the current database, returning each view name on a separate line.
Instructions
List all views in the current database.
Returns: str: A formatted string containing all view names, one per line
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- tools/sql_tools.py:69-79 (handler)Handler function for list_views: executes 'SHOW FULL TABLES WHERE Table_type = 'VIEW'' and returns view names as a newline-separated string.
def list_views(self) -> str: """List all views in the current database. Returns: str: A formatted string containing all view names, one per line """ with self.get_connection() as conn: cursor = conn.cursor() cursor.execute("SHOW FULL TABLES WHERE Table_type = 'VIEW'") views = [view[0] for view in cursor.fetchall()] return "\n".join(views) - server.py:13-13 (registration)Registration of list_views as an MCP tool on the server using the @mcp.tool() decorator pattern.
mcp.tool()(sql_tools.list_views) - tools/sql_tools.py:19-43 (helper)Helper context manager that provides the database connection used by list_views and other SQL tools.
@contextmanager def get_connection(self): """Context manager for database connections. Yields: mysql.connector.connection: Database connection object Raises: Error: If connection to the database fails """ connection = None try: connection = mysql.connector.connect( host=self.host, user=self.user, password=self.password, database=self.database ) yield connection except Error as e: print(f"Error connecting to MySQL database: {e}") raise finally: if connection and connection.is_connected(): connection.close()