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

dbt-get-model

Retrieve a single dbt model including refs, sources, columns with catalog types, attached tests, and raw/compiled SQL.

Instructions

Get a single dbt model: refs, sources, columns (with catalog types if available), attached tests, raw/compiled SQL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
uniqueIdNodbt unique_id (e.g. 'model.us_dbt.users_dim')
nameNoModel name (resolved if uniqueId not provided)
includeCompiledSqlNoInclude compiled_code in response

Implementation Reference

  • The main handler function for the 'dbt-get-model' tool. Loads a dbt model by uniqueId or name from the manifest, resolves refs, sources, columns (with catalog types), attached tests, and raw/compiled SQL.
    export async function dbtGetModel(args: z.infer<typeof dbtGetModelSchema>): Promise<unknown> {
      const manifest = loadManifest();
      const catalog = loadCatalog();
      let node: DbtNode | undefined;
      if (args.uniqueId) {
        node = manifest.nodes[args.uniqueId];
      } else if (args.name) {
        node = Object.values(manifest.nodes).find((n) => isModel(n) && n.name === args.name);
      } else {
        throw new Error("Provide uniqueId or name");
      }
      if (!node) throw new Error(`Model not found: ${args.uniqueId ?? args.name}`);
    
      const refs = (node.refs ?? []).map(refKey);
      const sources = (node.sources ?? []).map((s) => s.join("."));
      const dependsOn = node.depends_on?.nodes ?? [];
    
      const catalogEntry = catalog?.nodes[node.unique_id];
      const columns = node.columns
        ? Object.values(node.columns).map((c) => ({
            name: c.name,
            dataType:
              catalogEntry?.columns?.[c.name]?.type ?? c.data_type ?? null,
            description: c.description,
            tags: c.tags ?? [],
          }))
        : [];
    
      // Tests attached to this model
      const tests: Array<{ uniqueId: string; name: string; column?: string; severity?: string }> = [];
      for (const t of Object.values(manifest.nodes)) {
        if (t.resource_type !== "test") continue;
        const dependsNodes = t.depends_on?.nodes ?? [];
        if (dependsNodes.includes(node.unique_id) || t.attached_node === node.unique_id) {
          tests.push({
            uniqueId: t.unique_id,
            name: t.name,
            column: t.column_name,
            severity: t.severity ?? t.config?.meta?.severity as string | undefined,
          });
        }
      }
    
      return {
        uniqueId: node.unique_id,
        name: node.name,
        package: node.package_name,
        schema: node.schema,
        database: node.database,
        alias: node.alias,
        materialized: node.config?.materialized,
        tags: node.tags ?? node.config?.tags ?? [],
        path: node.original_file_path,
        description: node.description,
        refs,
        sources,
        dependsOn,
        columns,
        tests,
        rawCode: node.raw_code,
        compiledCode: args.includeCompiledSql ? node.compiled_code : undefined,
      };
    }
  • Zod schema defining input parameters for dbt-get-model: uniqueId (optional), name (optional), and includeCompiledSql (boolean, default false).
    export const dbtGetModelSchema = z.object({
      uniqueId: z.string().optional().describe("dbt unique_id (e.g. 'model.us_dbt.users_dim')"),
      name: z.string().optional().describe("Model name (resolved if uniqueId not provided)"),
      includeCompiledSql: z.boolean().default(false).describe("Include compiled_code in response"),
    });
  • src/index.ts:78-78 (registration)
    Registration of the 'dbt-get-model' tool with the MCP server using the schema and wrapped handler.
    tool("dbt-get-model", "Get a single dbt model: refs, sources, columns (with catalog types if available), attached tests, raw/compiled SQL", dbtGetModelSchema.shape, wrapToolHandler(dbtGetModel));
  • Helper function 'refKey' used to extract the name from a ref entry (supports both array and object formats).
    function refKey(ref: string[] | { name: string; package?: string | null }): string {
      if (Array.isArray(ref)) return ref[ref.length - 1]!;
      return ref.name;
    }
  • Helper function 'isModel' used to check if a node is a model resource type.
    function isModel(node: DbtNode): boolean {
      return node.resource_type === "model";
    }
Behavior3/5

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

No annotations exist, so the description must fully disclose behavior. It lists returned components but omits details like resolution priority when both uniqueId and name are supplied, whether the call is read-only, or any potential side effects. It covers core output but lacks nuance.

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, well-structured sentence that front-loads the core purpose. Every element (refs, sources, columns, tests, SQL) is justified and presented without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple retrieval tool with three parameters and no annotations or output schema, the description covers the key information. However, it could clarify the resolution logic between uniqueId and name, and potentially mention error scenarios (e.g., model not found). It is mostly complete but not exhaustive.

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 input schema documents all three parameters (100% coverage). The description adds value by explaining what the model response contains (columns with catalog types, tests, etc.), which is not in the schema. This enhances understanding beyond the parameter names and descriptions.

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 clearly states the tool retrieves a single dbt model and enumerates the data included (refs, sources, columns, tests, SQL). This specificity distinguishes it from sibling tools like dbt-list-models (which lists all models) and dbt-get-source (which fetches a source).

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 the tool is for fetching a single model's details but does not explicitly compare with siblings or suggest when to use alternatives like dbt-list-models for browsing or dbt-graph for lineage. No 'when not to use' guidance is provided.

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