list_metrics
Retrieve a comprehensive list of available metrics from the dbt Semantic Layer. Use it as the initial step to identify relevant metrics for answering data or business-related queries.
Instructions
List all metrics from the dbt Semantic Layer.
If the user is asking a data-related or business-related question, this tool should be used as a first step to get a list of metrics that can be used with other tools to answer the question.
Examples:
"What are the top 5 products by revenue?"
"How many users did we have last month?"
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The MCP tool handler for list_metrics. It is decorated with @dbt_mcp_tool which likely generates the input/output schema from type hints and delegates to SemanticLayerFetcher.list_metrics.@dbt_mcp_tool( description=get_prompt("semantic_layer/list_metrics"), title="List Metrics", read_only_hint=True, destructive_hint=False, idempotent_hint=True, ) async def list_metrics( context: SemanticLayerToolContext, search: str | None = None ) -> list[MetricToolResponse]: return await context.semantic_layer_fetcher.list_metrics(search=search)
- Pydantic/dataclass defining the output schema for individual metrics returned by list_metrics tool.class MetricToolResponse: name: str type: MetricType label: str | None = None description: str | None = None metadata: str | None = None
- src/dbt_mcp/mcp/server.py:137-149 (registration)The call to register_sl_tools which registers all semantic layer tools (including list_metrics) to the DbtMCP FastMCP server instance.logger.info("Registering semantic layer tools") register_sl_tools( dbt_mcp, config_provider=config.semantic_layer_config_provider, client_provider=DefaultSemanticLayerClientProvider( config_provider=config.semantic_layer_config_provider, ), disabled_tools=disabled_tools, enabled_tools=enabled_tools, enabled_toolsets=enabled_toolsets, disabled_toolsets=disabled_toolsets, )
- src/dbt_mcp/semantic_layer/tools.py:157-164 (registration)The list of semantic layer tools that includes the list_metrics handler function, used in registration.SEMANTIC_LAYER_TOOLS = [ list_metrics, list_saved_queries, get_dimensions, get_entities, query_metrics, get_metrics_compiled_sql, ]
- The helper method in SemanticLayerFetcher that performs the actual GraphQL query to fetch metrics list and maps to MetricToolResponse objects.async def list_metrics(self, search: str | None = None) -> list[MetricToolResponse]: metrics_result = await submit_request( await self.config_provider.get_config(), {"query": GRAPHQL_QUERIES["metrics"], "variables": {"search": search}}, ) return [ MetricToolResponse( name=m.get("name"), type=m.get("type"), label=m.get("label"), description=m.get("description"), metadata=(m.get("config") or {}).get("meta", ""), ) for m in metrics_result["data"]["metricsPaginated"]["items"] ]