Skip to main content
Glama
dbt-labs
by dbt-labs

get_model_details

Retrieve detailed information about a specific dbt model, including compiled SQL, descriptions, column names, and types, by providing the model name.

Instructions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
model_nameYes

Implementation Reference

  • The main execution handler for the get_model_details tool. It delegates to ResourceDetailsFetcher.fetch_details for the core logic.
    @dbt_mcp_tool(
        description=get_prompt("discovery/get_model_details"),
        title="Get Model Details",
        read_only_hint=True,
        destructive_hint=False,
        idempotent_hint=True,
    )
    async def get_model_details(
        context: DiscoveryToolContext,
        name: str | None = NAME_FIELD,
        unique_id: str | None = UNIQUE_ID_FIELD,
    ) -> list[dict]:
        return await context.resource_details_fetcher.fetch_details(
            resource_type=AppliedResourceType.MODEL,
            unique_id=unique_id,
            name=name,
        )
  • Core helper function in ResourceDetailsFetcher that executes the GraphQL query for model details (and other resources), handling name/unique_id normalization and package resolution.
    async def fetch_details(
        self,
        resource_type: AppliedResourceType,
        name: str | None = None,
        unique_id: str | None = None,
    ) -> list[dict]:
        normalized_name = name.strip().lower() if name else None
        normalized_unique_id = unique_id.strip().lower() if unique_id else None
        environment_id = (
            await self.api_client.config_provider.get_config()
        ).environment_id
        if not normalized_name and not normalized_unique_id:
            raise InvalidParameterError("Either name or unique_id must be provided")
        if (
            normalized_name
            and normalized_unique_id
            and normalized_name != normalized_unique_id.split(".")[-1]
        ):
            raise InvalidParameterError(
                f"Name and unique_id do not match. The unique_id does not end with {normalized_name}."
            )
        if not normalized_unique_id:
            assert normalized_name is not None, "Name must be provided"
            packages_result = await asyncio.gather(
                self.api_client.execute_query(
                    self.GET_PACKAGES_QUERY,
                    variables={"resource": "macro", "environmentId": environment_id},
                ),
                self.api_client.execute_query(
                    self.GET_PACKAGES_QUERY,
                    variables={"resource": "model", "environmentId": environment_id},
                ),
            )
            raise_gql_error(packages_result[0])
            raise_gql_error(packages_result[1])
            macro_packages = packages_result[0]["data"]["environment"]["applied"][
                "packages"
            ]
            model_packages = packages_result[1]["data"]["environment"]["applied"][
                "packages"
            ]
            if not macro_packages and not model_packages:
                raise InvalidParameterError("No packages found for project")
            unique_ids = [
                f"{resource_type.value.lower()}.{package_name}.{normalized_name}"
                for package_name in macro_packages + model_packages
            ]
        else:
            unique_ids = [normalized_unique_id]
        query = self.GQL_QUERIES[resource_type]
        variables = {
            "environmentId": environment_id,
            "filter": {
                "uniqueIds": unique_ids,
                "types": [self.RESOURCE_TYPE_TO_GQL_TYPE[resource_type]],
            },
            "first": len(unique_ids),
        }
        get_details_result = await self.api_client.execute_query(query, variables)
        raise_gql_error(get_details_result)
        edges = get_details_result["data"]["environment"]["applied"]["resources"][
            "edges"
        ]
        if not edges:
            return []
        return [e["node"] for e in edges]
  • Registration of the get_model_details tool in the DISCOVERY_TOOLS list, which is used by register_discovery_tools to add it to the MCP server.
    DISCOVERY_TOOLS = [
        get_mart_models,
        get_all_models,
        get_model_details,
        get_model_parents,
        get_model_children,
        get_model_health,
        get_exposures,
        get_exposure_details,
        get_all_sources,
        get_source_details,
        get_macro_details,
        get_seed_details,
        get_semantic_model_details,
        get_snapshot_details,
        get_test_details,
    ]
  • Pydantic Field definitions used in the tool's input schema for unique_id and name parameters.
    UNIQUE_ID_FIELD = Field(
        default=None,
        description="Fully-qualified unique ID of the resource. "
        "This will follow the format `<resource_type>.<package_name>.<resource_name>` "
        "(e.g. `model.analytics.stg_orders`). "
        "Strongly preferred over the `name` parameter for deterministic lookups.",
    )
    NAME_FIELD = Field(
        default=None,
        description="The name of the resource. "
        "This is not required if `unique_id` is provided. "
        "Only use name when `unique_id` is unknown.",
    )
  • Mappings in ResourceDetailsFetcher that link MODEL resource type to the specific GraphQL query 'get_model_details.gql' for fetching details.
    GQL_QUERIES: ClassVar[dict[AppliedResourceType, str]] = {
        AppliedResourceType.MODEL: GET_MODELS_DETAILS_QUERY,
        AppliedResourceType.SOURCE: GET_SOURCES_QUERY,
        AppliedResourceType.EXPOSURE: GET_EXPOSURES_QUERY,
        AppliedResourceType.TEST: GET_TESTS_QUERY,
        AppliedResourceType.SEED: GET_SEEDS_QUERY,
        AppliedResourceType.SNAPSHOT: GET_SNAPSHOTS_QUERY,
        AppliedResourceType.MACRO: GET_MACROS_QUERY,
        AppliedResourceType.SEMANTIC_MODEL: GET_SEMANTIC_MODELS_QUERY,
    }
Install Server

Other Tools

Related 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/dbt-labs/dbt-mcp'

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