Building a Data Stack Live with AI AgentsLivestream August 18

Skip to main content

list_macros

List all macros (table and scalar macros) in a MotherDuck database with their schema and parameters.

Description

The list_macros tool returns the macros defined in a specified database, including their schema, type, and parameter names. You can optionally filter by schema or keywords. Macros encapsulate reusable SQL logic; knowing which ones exist helps the AI assistant reuse them instead of rebuilding the logic in every query.

Input parameters

ParameterTypeRequiredDescription
databasestringYesDatabase name to list macros from
schemastringNoSchema name (defaults to all schemas)
keywordsstringNoFilter macros by name (case-insensitive, any word can match)
limitnumberNoMaximum results to return (default: 100, maximum: 500)

Output schema

{
"success": boolean,
"database": string, // Database name
"schema": string, // Schema filter used ("all" if not specified)
"macros": [ // List of macros (on success)
{
"schema": string, // Schema name
"name": string, // Macro name
"type": string, // Macro type
"parameters": [string] // Parameter names
}
],
"count": number, // Number of macros returned
"totalCount": number, // Total number of matching macros
"truncated": boolean, // Present when results were cut to fit the limit
"error": string // Error message (on failure)
}

Example usage

List all macros in a database:

Are there any reusable macros in analytics_db?

The AI assistant will call the tool with:

{
"database": "analytics_db"
}

Filter by keywords:

{
"database": "analytics_db",
"keywords": "fiscal"
}

Success response example

{
"success": true,
"database": "analytics_db",
"schema": "all",
"macros": [
{
"schema": "main",
"name": "fiscal_quarter",
"type": "macro",
"parameters": ["date_col"]
}
],
"count": 1,
"totalCount": 1
}
  • list_views — List views in a database.
  • list_tables — List tables and views with their comments.
  • query — Run a query that uses a macro.