dbt-get-test
Retrieve a single dbt test's definition, parameters, attached models, and latest run result by providing its unique identifier.
Instructions
Get a single dbt test: definition, parameters, attached models, latest run result
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uniqueId | Yes | dbt unique_id of the test (e.g. 'test.proj.unique_users_id') |
Implementation Reference
- src/tools/dbt-tests.ts:57-94 (handler)Main handler for dbt-get-test. Loads the manifest, looks up the test by uniqueId, and returns the test definition, parameters, attached nodes, and latest run result from run_results.json.
export async function dbtGetTest(args: z.infer<typeof dbtGetTestSchema>): Promise<unknown> { const manifest = loadManifest(); const node = manifest.nodes[args.uniqueId]; if (!node || !isTest(node)) throw new Error(`Test not found: ${args.uniqueId}`); let latestResult: unknown = null; try { const runResults = loadRunResults(); const result = runResults.results.find((r) => r.unique_id === args.uniqueId); if (result) { latestResult = { status: result.status, executionTime: result.execution_time, message: result.message, failures: result.failures, generatedAt: runResults.metadata.generated_at, invocationId: runResults.metadata.invocation_id, }; } } catch { // run_results.json may be absent } return { uniqueId: node.unique_id, name: node.name, package: node.package_name, kind: node.test_metadata ? "generic" : "singular", testDefinition: node.test_metadata?.name, testKwargs: node.test_metadata?.kwargs, column: node.column_name, severity: node.severity, attachedNodes: node.depends_on?.nodes ?? [], tags: node.tags ?? node.config?.tags ?? [], rawCode: node.raw_code, latestResult, }; } - src/tools/dbt-tests.ts:53-55 (schema)Zod schema for dbt-get-test input validation. Requires a single string parameter 'uniqueId'.
export const dbtGetTestSchema = z.object({ uniqueId: z.string().describe("dbt unique_id of the test (e.g. 'test.proj.unique_users_id')"), }); - src/index.ts:80-80 (registration)Registration of the 'dbt-get-test' tool with the MCP server, wiring it to the schema and handler.
tool("dbt-get-test", "Get a single dbt test: definition, parameters, attached models, latest run result", dbtGetTestSchema.shape, wrapToolHandler(dbtGetTest)); - src/index.ts:17-20 (registration)Import of the dbtGetTest handler and schema from the dbt-tests module into the main index file.
import { dbtListTestsSchema, dbtListTests, dbtGetTestSchema, dbtGetTest, } from "./tools/dbt-tests.js"; - src/tools/dbt-tests.ts:4-6 (helper)Helper function used by dbtGetTest (and dbtListTests) to check if a node is a test resource.
function isTest(node: DbtNode): boolean { return node.resource_type === "test"; }