Skip to main content
Glama
us-all
by us-all

dbt-get-macro

Retrieve a dbt macro's signature and raw SQL, and find all nodes that call it.

Instructions

Get a dbt macro: signature, raw SQL, and reverse-lookup of nodes that call it

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
uniqueIdNodbt unique_id (e.g. 'macro.proj.my_macro')
nameNoMacro name (resolved if uniqueId not provided)

Implementation Reference

  • The main handler function for the dbt-get-macro tool. It loads the manifest, finds the macro by uniqueId or name, performs a reverse-lookup of all nodes/models that depend on it (usages), and returns the macro with its signature, raw SQL, and usage info.
    export async function dbtGetMacro(args: z.infer<typeof dbtGetMacroSchema>): Promise<unknown> {
      const manifest = loadManifest();
      let macro = args.uniqueId ? manifest.macros[args.uniqueId] : undefined;
      if (!macro && args.name) {
        macro = Object.values(manifest.macros).find((m) => m.name === args.name);
      }
      if (!macro) throw new Error(`Macro not found: ${args.uniqueId ?? args.name}`);
    
      // Find usages: any node whose depends_on.macros includes this macro
      const usages: string[] = [];
      for (const n of [...Object.values(manifest.nodes), ...Object.values(manifest.macros)]) {
        if ((n.depends_on?.macros ?? []).includes(macro.unique_id)) {
          usages.push(n.unique_id);
        }
      }
    
      return {
        uniqueId: macro.unique_id,
        name: macro.name,
        package: macro.package_name,
        path: macro.original_file_path,
        arguments: macro.arguments ?? [],
        description: macro.description,
        rawCode: macro.raw_code,
        dependsOnMacros: macro.depends_on?.macros ?? [],
        usages,
        usageCount: usages.length,
      };
    }
  • Zod schema for dbt-get-macro input validation: accepts optional 'uniqueId' (e.g. macro.proj.my_macro) or optional 'name' (macro name, used as fallback if uniqueId not provided).
    export const dbtGetMacroSchema = z.object({
      uniqueId: z.string().optional().describe("dbt unique_id (e.g. 'macro.proj.my_macro')"),
      name: z.string().optional().describe("Macro name (resolved if uniqueId not provided)"),
    });
  • src/index.ts:85-85 (registration)
    Registration of the dbt-get-macro tool with its name, description, schema, and handler via tool() call.
    tool("dbt-get-macro", "Get a dbt macro: signature, raw SQL, and reverse-lookup of nodes that call it", dbtGetMacroSchema.shape, wrapToolHandler(dbtGetMacro));
  • The loadManifest() helper that reads and caches the dbt manifest.json file, which is used by the dbtGetMacro handler to look up macro definitions and their dependencies.
    export function loadManifest(): DbtManifest {
      return readWithCache<DbtManifest>("manifest", targetPath("manifest.json"));
    }
Behavior2/5

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

With no annotations, the description must disclose all behavioral traits. It does not mention any side effects, authentication requirements, or error scenarios. It implies a read operation but does not guarantee idempotency or rate limits. The description adds some value by listing return fields but omits broader behavioral context.

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

Conciseness5/5

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

The description is a single, front-loaded sentence that directly states the action and key outputs. No extraneous words; every part adds value. It is concise and well-structured.

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?

The tool is simple with two parameters and no output schema. The description lists the types of information returned but does not specify the structure or format of the output. While sufficient for a basic understanding, it lacks completeness regarding the response shape or what to expect in case of errors.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Both parameters have descriptions in the schema (100% coverage). The description does not add any extra meaning beyond what the schema already provides; it does not explain the relationship between uniqueId and name or provide usage examples. Baseline 3 is appropriate as the schema carries the detail.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a clear verb ('Get') and specifies the resource ('dbt macro'), and lists three specific outputs (signature, raw SQL, reverse-lookup). This distinguishes it from sibling tools like dbt-get-model and dbt-list-macros, which target different resources or actions.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. For example, it does not mention that dbt-list-macros lists all macros, or that this tool is for retrieving a single macro's details. No prerequisites, exclusions, or context for selection are given.

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/us-all/dbt-mcp-server'

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