Skip to main content
Glama

compile

Generate executable SQL from dbt model, test, and analysis files. Validate complex Jinja logic and macro usage by inspecting compiled output directly.

Instructions

dbt compile generates executable SQL from source model, test, and analysis files.

The compile command is useful for visually inspecting the compiled output of model files. This is useful for validating complex jinja logic or macro usage.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'compile' MCP tool. It invokes the shared _run_dbt_command helper with the 'compile' argument to execute `dbt compile` via subprocess.
    def compile() -> str: return _run_dbt_command(["compile"])
  • Shared helper function that executes dbt CLI commands via subprocess.Popen, handling flags, selectors, timeouts, and output capture. Used by 'compile' and other dbt CLI tools.
    def _run_dbt_command( command: list[str], selector: str | None = None, resource_type: list[str] | None = None, is_selectable: bool = False, is_full_refresh: bool | None = False, vars: str | None = None, ) -> str: try: # Commands that should always be quiet to reduce output verbosity verbose_commands = [ "build", "compile", "docs", "parse", "run", "test", "list", ] if is_full_refresh is True: command.append("--full-refresh") if vars and isinstance(vars, str): command.extend(["--vars", vars]) if selector: selector_params = str(selector).split(" ") command.extend(["--select"] + selector_params) if isinstance(resource_type, Iterable): command.extend(["--resource-type"] + resource_type) full_command = command.copy() # Add --quiet flag to specific commands to reduce context window usage if len(full_command) > 0 and full_command[0] in verbose_commands: main_command = full_command[0] command_args = full_command[1:] if len(full_command) > 1 else [] full_command = [main_command, "--quiet", *command_args] # We change the path only if this is an absolute path, otherwise we can have # problems with relative paths applied multiple times as DBT_PROJECT_DIR # is applied to dbt Core and Fusion as well (but not the dbt Cloud CLI) cwd_path = config.project_dir if os.path.isabs(config.project_dir) else None # Add appropriate color disable flag based on binary type color_flag = get_color_disable_flag(config.binary_type) args = [config.dbt_path, color_flag, *full_command] process = subprocess.Popen( args=args, cwd=cwd_path, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.DEVNULL, text=True, ) output, _ = process.communicate(timeout=config.dbt_cli_timeout) return output or "OK" except subprocess.TimeoutExpired: return "Timeout: dbt command took too long to complete." + ( " Try using a specific selector to narrow down the results." if is_selectable else "" )
  • ToolDefinition registration for the 'compile' tool, including description from prompts and annotations indicating it's read-only and idempotent.
    fn=compile, description=get_prompt("dbt_cli/compile"), annotations=create_tool_annotations( title="dbt compile", read_only_hint=True, destructive_hint=False, idempotent_hint=True, ), ),
  • Function to register all dbt CLI tools (including 'compile') on the FastMCP server, respecting enable/disable configs.
    def register_dbt_cli_tools( dbt_mcp: FastMCP, config: DbtCliConfig, *, disabled_tools: set[ToolName], enabled_tools: set[ToolName], enabled_toolsets: set[Toolset], disabled_toolsets: set[Toolset], ) -> None: register_tools( dbt_mcp, tool_definitions=create_dbt_cli_tool_definitions(config), disabled_tools=disabled_tools, enabled_tools=enabled_tools, enabled_toolsets=enabled_toolsets, disabled_toolsets=disabled_toolsets, )
  • Invocation of dbt CLI tool registration (including 'compile') during MCP server initialization when dbt_cli_config is provided.
    dbt_mcp, config=config.dbt_cli_config, disabled_tools=disabled_tools, enabled_tools=enabled_tools, enabled_toolsets=enabled_toolsets, disabled_toolsets=disabled_toolsets, )

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