Skip to main content
Glama
nolleh
by nolleh

list_views

Retrieve all views from a specified schema in Vertica databases to analyze database structure and access available data perspectives.

Instructions

List all views in a schema.

Args:
    ctx: FastMCP context for progress reporting and logging
    schema: Schema name (default: public)

Returns:
    View information as a string

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNopublic

Implementation Reference

  • The handler function for the 'list_views' tool. It connects to Vertica, executes a query against v_catalog.views to fetch views in the given schema, formats the results, and returns them as a string. Includes the @mcp.tool() decorator for registration.
    @mcp.tool()
    async def list_views(
        ctx: Context,
        schema: str = "public"
    ) -> str:
        """List all views in a schema.
    
        Args:
            ctx: FastMCP context for progress reporting and logging
            schema: Schema name (default: public)
    
        Returns:
            View information as a string
        """
        await ctx.info(f"Listing views in schema: {schema}")
    
        # Get or create connection manager
        manager = await get_or_create_manager(ctx)
        if not manager:
            return "Error: Failed to initialize database connection. Check configuration."
    
        query = """
        SELECT
            table_name,
            view_definition
        FROM v_catalog.views
        WHERE table_schema = %s
        ORDER BY table_name;
        """
    
        conn = None
        cursor = None
        try:
            conn = manager.get_connection()
            cursor = conn.cursor()
            cursor.execute(query, (schema,))
            views = cursor.fetchall()
    
            if not views:
                return f"No views found in schema: {schema}"
    
            result = f"Views in schema {schema}:\n\n"
            for view in views:
                result += f"View: {view[0]}\n"
                result += f"Definition:\n{view[1]}\n\n"
    
            return result
    
        except Exception as e:
            error_msg = f"Error listing views: {str(e)}"
            await ctx.error(error_msg)
            return error_msg
        finally:
            if cursor:
                cursor.close()
            if conn:
                manager.release_connection(conn)

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/nolleh/mcp-vertica'

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