Databricks AI Dev Kit

repository·main·Indexed 23 days ago

https://github.com/databricks-solutions/ai-dev-kit

A toolkit providing tools, skills, and integrations for AI-assisted development on the Databricks platform. It includes the Databricks Builder App, a web-based interface that integrates Claude Code with a 'Skills' system for product-specific workflows such as jobs, pipelines, SQL, and Unity Catalog operations. The kit bridges local AI coding agents with Databricks resources and includes an MCP server.

Tokens
37.2K
Snippets
71
Records
190
Agent score
83%

What's inside AI Dev Kit

  1. Overview of Databricks Builder App

    main

    The Databricks Builder App is a web application providing a Claude Code agent interface designed for building on Databricks. It uses a 'Skills' system to supply product-specific workflows (such as jobs, pipelines, SQL, and Unity Catalog operations). Claude executes these workflows using either the authenticated Databricks CLI or short Python SDK scripts.

    Security Warning: This application wraps Claude Code. Projects created by different users are not strongly isolated (e.g., no microVM or Docker isolation for Claude sessions). Only grant access to trusted users.

  2. Available installation and usage options

    main

    Depending on your goal, you can use different components of the Databricks AI ecosystem:

    • Install Skills: The recommended starting point to add Databricks skills to your user or existing project folder.
    • Genie Code Skills: For uploading selected skills into your workspace specifically for Genie Code.
    • Visual Builder App: A web-based UI for Databricks development (located in databricks-builder-app/).
    • MCP Tools: A standalone Model Context Protocol (MCP) server that exposes Databricks actions to AI clients. While skills are generally recommended, this is useful if a custom MCP server is required.
  3. Audit log tracking for MCP Server API calls

    main

    All API calls made through the MCP server are tagged with a custom User-Agent header, allowing you to filter calls in the system.access.audit system table. The project name is automatically detected from the git remote URL.

    Header Format: databricks-ai-dev-kit/0.1.0 databricks-sdk-py/... project/<auto-detected-repo-name>

    Note: Audit log entries may take 2–10 minutes to appear. The workspace must have Unity Catalog enabled to query system.access.audit.

  4. Configure agent context and session management

    main

    Configuring Context

    You can provide additional context to the agent via optional parameters in stream_agent_response to guide its execution:

    • warehouse_id: Default SQL warehouse.
    • cluster_id: Default cluster for Python execution.
    • default_catalog: Default Unity Catalog.
    • default_schema: Default schema.
    • workspace_folder: Workspace folder for file uploads.

    Session Management

    To resume a conversation, capture the session_id from a result event and pass it into subsequent calls to stream_agent_response.

    # Resume conversation using session_id
    async for event in stream_agent_response(
        project_id="demo",
        message="What did I just ask?",
        session_id=session_id,  # Pass the ID captured from a previous 'result' event
    ):
        ...
  5. Differentiate between Databricks CLI auth and FMAPI auth

    main

    The Builder App separates authentication for model serving (Claude) from authentication for executing skills (Bash/CLI).

    FMAPI Auth (Claude / Titles)

    Used for model serving. It utilizes an FMAPI OAuth token obtained via get_fmapi_token. In deployed mode, this token is written to <project>/.anthropic_token and read by get_anthropic_token.sh.

    Databricks CLI Auth (Skills / Bash / CLI)

    Used for workspace actions. It uses a request-scoped workspace token.

    • In Deployed Mode: Uses the X-Forwarded-Access-Token header. If this header is omitted, invoke_agent fails with a 401 error; it does not fall back to the FMAPI token or the ambient app service principal.
    • In Local Mode: Uses the DATABRICKS_TOKEN environment variable.
    • Configuration: The token is written to <project>/.databrickscfg and managed via DATABRICKS_CONFIG_FILE, DATABRICKS_CONFIG_PROFILE=DEFAULT, and DATABRICKS_AUTH_TYPE=pat.

    Note: For cross-workspace calls, you must provide both target_databricks_host and target_databricks_token.

    Security Warning: .anthropic_token and .databrickscfg files must not be included in Lakebase project backups.

  6. How Databricks Builder App works

    main

    The application architecture consists of three main layers:

    1. Web Application: A React frontend (Chat UI, Project Selector, Conversation List) communicating via SSE with a FastAPI backend (endpoints: /api/invoke_agent, /api/projects, /api/conversations).
    2. Claude Code Session: Each user message spawns a session via claude-agent-sdk. The session has access to:
      • Built-in Tools: Read, Write, Edit, Bash, Glob, Grep, and Skill.
      • Skills: CLI or Python SDK workflows for Databricks products (jobs, pipelines, SQL, UC, etc.).
      • Context: Uses project-scoped .databrickscfg for the Databricks CLI/WorkspaceClient and mcp_servers={}.
    3. Databricks Workspace: The target environment containing SQL Warehouses, Clusters, Unity Catalog, and Workspace assets.
  7. Choose between Genie Code and AI Dev Kit for AI-assisted development

    main

    Databricks provides two primary paths for AI-assisted coding depending on your preferred environment:

    1. Genie Code: A free, first-party AI coding experience built directly into the Databricks workspace. It has native access to your notebooks, jobs, and Unity Catalog data. Best for users working primarily within the Databricks UI.
    2. AI Dev Kit: Brings Databricks expertise, tutorials, and official agent skills to your existing local IDE or AI coding agent (e.g., Claude Code, Cursor, GitHub Copilot, Gemini CLI, Windsurf, etc.). Best for developers who want to build on Databricks using their preferred local development tools.
  8. Understand Local vs Deployed modes in Builder App

    main

    The Builder App operates in two distinct modes based on the presence of the DATABRICKS_CLIENT_ID environment variable. This distinction changes how Claude configuration is handled and how authentication is performed.

    Local Mode

    • Detection: DATABRICKS_CLIENT_ID is unset.
    • Claude Config: Uses the default ~/.claude directory.
    • Authentication: Uses ANTHROPIC_API_KEY and ANTHROPIC_BASE_URL via _build_claude_auth.
    • Warning: Never set CLAUDE_CONFIG_DIR in local mode, as it will disconnect claude login / Keychain credentials and break local chat functionality.

    Deployed Mode (Apps)

    • Detection: DATABRICKS_CLIENT_ID is set (detected via is_deployed_mode()).
    • Claude Config: Uses CLAUDE_CONFIG_DIR=<project>/.claude.
    • Authentication: Uses project apiKeyHelper, .anthropic_token, and .claude/settings.json.
  9. How the Databricks MCP Server architecture works

    main

    The Databricks MCP (Model Context Protocol) Server acts as a bridge between AI coding assistants (MCP Clients like Claude Code or Cursor) and the Databricks Workspace.

    1. MCP Client: An AI assistant that initiates requests via the MCP Protocol (typically over stdio). It uses a configuration file (e.g., .mcp.json) to discover available tools.
    2. databricks-mcp-server: Built using FastMCP, this server exposes specific Databricks capabilities as tools. It uses @mcp.tool decorators to wrap Python modules (such as tools/sql.py, tools/compute.py, etc.) into actionable MCP tools.
    3. databricks-tools-core: The server imports logic from this core library, which provides high-level abstractions for Databricks features like SQL, Compute, Jobs, Unity Catalog, and Vector Search.
    4. Databricks SDK: The core library ultimately communicates with the Databricks Workspace using the official Databricks SDK.
  10. Authenticate the Databricks MCP Server

    main

    The server uses the Databricks Unified Authentication chain. To ensure your MCP client can authenticate with your workspace, you must provide credentials via environment variables in the client's MCP configuration env block.

    If you have a profile configured in ~/.databrickscfg, use: DATABRICKS_CONFIG_PROFILE="your-profile"

    Option 2: Explicit host and token

    If you do not use profiles, provide the host and token directly: DATABRICKS_HOST="https://your-workspace.cloud.databricks.com" DATABRICKS_TOKEN="your-token"

  11. Authentication flow for Production and Development environments

    main

    The Databricks Builder App uses a unified authentication mechanism that ensures the agent uses the identity of the requesting user for all Databricks CLI and Python SDK operations.

    Environment Differences

    • Production (Databricks Apps): Credentials are provided via request headers: X-Forwarded-User and X-Forwarded-Access-Token (set by the Databricks Apps proxy).
    • Development (Local): Credentials are provided via environment variables: DATABRICKS_HOST and DATABRICKS_TOKEN.

    Authentication Mechanism

    1. The backend extracts credentials from the headers or env vars.
    2. A project-scoped .databrickscfg file is written to the project directory with mode 0600.
    3. The environment is configured using:
      • DATABRICKS_CONFIG_FILE: Points to the project-scoped .databrickscfg.
      • DATABRICKS_CONFIG_PROFILE: Set to DEFAULT.
      • DATABRICKS_AUTH_TYPE: Set to pat.
    4. The databricks CLI and Python WorkspaceClient() inherit this environment.

    Security Note: In Databricks Apps, inherited service-principal variables are cleared to prevent the agent from using the app's identity instead of the user's. If X-Forwarded-Access-Token is missing in Production, the system fails with a 401 error.

  12. Project persistence and backup structure

    main

    Projects are stored on the local filesystem and are automatically backed up to a PostgreSQL database (Lakebase) to ensure durability.

    Project Directory Structure

    projects/
      <project-uuid>/
        .claude/
          skills/        # Copied skills for this project
        src/             # User's code files
        ...

    Backup Process

    • Trigger: The project is marked for backup after every agent interaction.
    • Frequency: A background worker runs every 10 minutes.
    • Storage: Projects are zipped and stored in PostgreSQL.
    • Restoration: If a project is missing from the local filesystem, it is automatically restored from the PostgreSQL backup upon access.