dbt-list-tests
List dbt tests, filtered by type (generic/singular), model attachment, or name substring, with configurable result limits.
Instructions
List dbt tests (generic or singular) optionally filtered to a specific model
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| attachedTo | No | Filter to tests attached to a specific model unique_id or name | |
| testKind | No | all | |
| search | No | Substring match against test name | |
| limit | No |
Implementation Reference
- src/index.ts:79-79 (registration)Registration of the dbt-list-tests tool with schema and handler on the MCP server.
tool("dbt-list-tests", "List dbt tests (generic or singular) optionally filtered to a specific model", dbtListTestsSchema.shape, wrapToolHandler(dbtListTests)); - src/tools/dbt-tests.ts:8-16 (schema)Zod schema for dbt-list-tests input: attachedTo, testKind (default 'all'), search, limit (default 500).
export const dbtListTestsSchema = z.object({ attachedTo: z .string() .optional() .describe("Filter to tests attached to a specific model unique_id or name"), testKind: z.enum(["generic", "singular", "all"]).default("all"), search: z.string().optional().describe("Substring match against test name"), limit: z.coerce.number().int().min(1).max(2000).default(500), }); - src/tools/dbt-tests.ts:18-51 (handler)Handler function dbtListTests: loads manifest, filters test nodes by kind/name/attached model, returns list of tests with metadata.
export async function dbtListTests(args: z.infer<typeof dbtListTestsSchema>): Promise<unknown> { const manifest = loadManifest(); let attachedId: string | undefined = args.attachedTo; if (attachedId && !manifest.nodes[attachedId]) { const found = Object.values(manifest.nodes).find((n) => n.name === attachedId); attachedId = found?.unique_id; } const out: Array<Record<string, unknown>> = []; const search = args.search?.toLowerCase(); for (const node of Object.values(manifest.nodes)) { if (!isTest(node)) continue; const isGeneric = !!node.test_metadata; if (args.testKind === "generic" && !isGeneric) continue; if (args.testKind === "singular" && isGeneric) continue; if (search && !node.name.toLowerCase().includes(search)) continue; if (attachedId) { const dependsNodes = node.depends_on?.nodes ?? []; if (!dependsNodes.includes(attachedId) && node.attached_node !== attachedId) continue; } out.push({ uniqueId: node.unique_id, name: node.name, package: node.package_name, kind: isGeneric ? "generic" : "singular", definition: node.test_metadata?.name, column: node.column_name, attachedTo: node.depends_on?.nodes?.[0], severity: node.severity, tags: node.tags ?? node.config?.tags ?? [], }); if (out.length >= args.limit) break; } return { count: out.length, tests: out }; } - src/tools/dbt-tests.ts:4-6 (helper)Helper function isTest() used to filter manifest nodes to test resources.
function isTest(node: DbtNode): boolean { return node.resource_type === "test"; } - src/index.ts:17-20 (helper)Import of dbtListTestsSchema and dbtListTests from src/tools/dbt-tests.ts
import { dbtListTestsSchema, dbtListTests, dbtGetTestSchema, dbtGetTest, } from "./tools/dbt-tests.js";