Skip to main content
Glama

list_functions

Discover functions and procedures in a PostgreSQL schema to understand available database operations and their signatures.

Instructions

List all functions and procedures in a schema.

Args:
    schema: Schema name (default: public)
    
Returns:
    List of functions with name, arguments, and return type

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNopublic

Implementation Reference

  • MCP tool handler and registration for 'list_functions'. This decorated function handles tool execution, delegates to PostgresClient, and formats output using FunctionSummary models.
    @mcp.tool()
    @handle_db_error
    def list_functions(schema: str = "public") -> dict:
        """List all functions and procedures in a schema.
        
        Args:
            schema: Schema name (default: public)
            
        Returns:
            List of functions with name, arguments, and return type
        """
        client = get_client()
        functions = client.list_functions(schema)
        
        return {
            "schema": schema,
            "functions": [FunctionSummary.from_row(f).model_dump() for f in functions],
        }
  • Core implementation in PostgresClient that executes the SQL query against pg_proc to retrieve function metadata from the database.
    def list_functions(self, schema: str = "public") -> list[dict]:
        """List functions and procedures in a schema.
        
        Args:
            schema: Schema name
            
        Returns:
            List of function dicts
        """
        query = """
            SELECT 
                p.proname AS routine_name,
                n.nspname AS routine_schema,
                pg_get_function_result(p.oid) AS return_type,
                pg_get_function_arguments(p.oid) AS argument_types,
                CASE p.prokind
                    WHEN 'f' THEN 'function'
                    WHEN 'p' THEN 'procedure'
                    WHEN 'a' THEN 'aggregate'
                    WHEN 'w' THEN 'window'
                    ELSE 'unknown'
                END AS routine_type
            FROM pg_proc p
            JOIN pg_namespace n ON n.oid = p.pronamespace
            WHERE n.nspname = %s
                AND p.proname NOT LIKE 'pg_%'
            ORDER BY p.proname
        """
        with self.get_cursor() as cursor:
            cursor.execute(query, (schema,))
            return [dict(row) for row in cursor.fetchall()]
  • Pydantic model defining the output schema for function summaries, used in the tool response for type validation and serialization.
    class FunctionSummary(BaseModel):
        """Function/procedure info."""
        
        name: str
        schema_name: str = "public"
        return_type: Optional[str] = None
        argument_types: str = ""
        func_type: str = "function"  # function, procedure, aggregate
        
        @classmethod
        def from_row(cls, row: dict) -> "FunctionSummary":
            return cls(
                name=row.get("routine_name", row.get("proname", "")),
                schema_name=row.get("routine_schema", row.get("nspname", "public")),
                return_type=row.get("data_type", row.get("return_type")),
                argument_types=row.get("argument_types", ""),
                func_type=row.get("routine_type", "function").lower(),
            )
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states what the tool does (listing functions) and the return format, but does not mention any behavioral traits such as permissions required, rate limits, pagination, or error handling. This is a significant gap for a tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, with the core purpose stated first, followed by structured sections for args and returns. Every sentence adds value, though the formatting with separate sections is slightly verbose but still efficient.

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 low complexity (1 parameter, no output schema, no annotations), the description is somewhat complete but lacks depth. It covers the purpose, parameter semantics, and return format, but misses behavioral context like permissions or limitations, which is important for a database query tool with no structured annotations.

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 description adds meaningful context for the single parameter 'schema' by specifying it as the schema name with a default value of 'public', which is not covered in the input schema (0% schema description coverage). This compensates well for the lack of schema documentation, though it could include more details like format or constraints.

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 'functions and procedures in a schema', making the purpose specific and understandable. However, it does not explicitly distinguish this tool from sibling tools like 'list_tables' or 'list_views', which list other database objects, missing an opportunity for full differentiation.

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 functions in a given schema, but provides no explicit guidance on when to use this tool versus alternatives like 'describe_table' or 'query'. The context is clear but lacks any when/when-not statements or named alternatives, leaving usage somewhat open to interpretation.

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/JaviMaligno/postgres-mcp'

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