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

dbt-graph

Traverse dbt's parent and child maps to return upstream and downstream nodes (models, sources, tests) up to a given depth.

Instructions

Walk dbt parent_map / child_map to return upstream and downstream nodes (model/source/test) up to a given depth

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
uniqueIdNodbt unique_id
nameNoModel name (resolved if uniqueId not provided)
upstreamDepthNo
downstreamDepthNo

Implementation Reference

  • The main handler function for the 'dbt-graph' tool. It loads the manifest, resolves the starting node by uniqueId or name, then walks parent_map (upstream) and child_map (downstream) BFS-style up to configurable depth. Returns start node info, upstream nodes with depth, and downstream nodes with depth.
    export async function dbtGraph(args: z.infer<typeof dbtGraphSchema>): Promise<unknown> {
      const manifest = loadManifest();
      let startId = args.uniqueId;
      if (!startId && args.name) {
        const found = Object.values(manifest.nodes).find((n) => n.name === args.name);
        startId = found?.unique_id;
      }
      if (!startId) throw new Error(`Node not found: ${args.uniqueId ?? args.name}`);
    
      const parent = manifest.parent_map ?? {};
      const child = manifest.child_map ?? {};
    
      function walk(map: Record<string, string[]>, id: string, depth: number): Map<string, number> {
        const out = new Map<string, number>();
        const queue: Array<[string, number]> = [[id, 0]];
        while (queue.length) {
          const [cur, d] = queue.shift()!;
          if (d >= depth) continue;
          for (const next of map[cur] ?? []) {
            if (out.has(next)) continue;
            out.set(next, d + 1);
            queue.push([next, d + 1]);
          }
        }
        return out;
      }
    
      function describe(id: string): { uniqueId: string; name: string; resourceType: string } {
        const node = manifest.nodes[id] ?? manifest.sources[id] ?? manifest.macros[id];
        return {
          uniqueId: id,
          name: node?.name ?? id.split(".").pop() ?? id,
          resourceType: node?.resource_type ?? "unknown",
        };
      }
    
      const upstream = walk(parent, startId, args.upstreamDepth);
      const downstream = walk(child, startId, args.downstreamDepth);
      return {
        start: describe(startId),
        upstream: Array.from(upstream).map(([id, depth]) => ({ ...describe(id), depth })),
        downstream: Array.from(downstream).map(([id, depth]) => ({ ...describe(id), depth })),
      };
    }
  • Zod schema for dbt-graph input validation: uniqueId (optional), name (optional fallback for resolution), upstreamDepth (default 2, max 10), downstreamDepth (default 2, max 10).
    export const dbtGraphSchema = z.object({
      uniqueId: z.string().optional().describe("dbt unique_id"),
      name: z.string().optional().describe("Model name (resolved if uniqueId not provided)"),
      upstreamDepth: z.coerce.number().int().min(0).max(10).default(2),
      downstreamDepth: z.coerce.number().int().min(0).max(10).default(2),
    });
  • src/index.ts:91-91 (registration)
    Registration of the 'dbt-graph' tool with the MCP server via tool(). Name, description, schema shape, and wrapped handler are provided.
    tool("dbt-graph", "Walk dbt parent_map / child_map to return upstream and downstream nodes (model/source/test) up to a given depth", dbtGraphSchema.shape, wrapToolHandler(dbtGraph));
  • Helper function 'describe' that resolves a unique_id to its name and resource_type from manifest.nodes, manifest.sources, or manifest.macros.
    function describe(id: string): { uniqueId: string; name: string; resourceType: string } {
      const node = manifest.nodes[id] ?? manifest.sources[id] ?? manifest.macros[id];
      return {
        uniqueId: id,
        name: node?.name ?? id.split(".").pop() ?? id,
        resourceType: node?.resource_type ?? "unknown",
      };
    }
  • Helper function 'walk' that performs BFS traversal on a parent_map/child_map to find connected nodes up to a given depth.
    function walk(map: Record<string, string[]>, id: string, depth: number): Map<string, number> {
      const out = new Map<string, number>();
      const queue: Array<[string, number]> = [[id, 0]];
      while (queue.length) {
        const [cur, d] = queue.shift()!;
        if (d >= depth) continue;
        for (const next of map[cur] ?? []) {
          if (out.has(next)) continue;
          out.set(next, d + 1);
          queue.push([next, d + 1]);
        }
      }
      return out;
    }
Behavior3/5

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

No annotations are present, so the description must carry the burden. It explains the traversal behavior (parent/child maps) but does not disclose if the operation is read-only, whether it has side effects, or performance implications. Adequate but not fully transparent.

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?

Single sentence conveying the core functionality with no unnecessary words. Front-loaded with action and resource.

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 no output schema and 4 parameters, the description is brief but covers the basic purpose. However, it does not specify what the tool returns (e.g., list of unique IDs), leaving ambiguity. Could be more complete for a traversal tool.

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

Parameters2/5

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

Schema coverage is 50% with descriptions for uniqueId and name, and min/max for depths. The description adds only the concept of depth control, not details on each parameter. Minimal added value beyond schema.

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 it walks parent/child maps to return upstream and downstream nodes (models, sources, tests) up to a given depth, with a specific verb and resource, distinguishing it from sibling tools like dbt-get-model.

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 (e.g., dbt-get-model for single nodes) or when not to use it. No context about prerequisites or trade-offs.

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