Repository navigation
Add a Databricks toolset for Unity Gateway MCP Services #74198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
firasbouzazi
wants to merge
7
commits into
apache:main
Choose a base branch
from
firasbouzazi:claude/vibrant-dijkstra-533yw4
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,254
−1
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bf15333
Add a Databricks toolset for Unity AI Gateway MCP Services
firasbouzazi b5eea8d
Keep Unity MCP requests from waiting on other toolsets' blocking calls
firasbouzazi 6b3e4ab
Document the Unity Catalog privileges MCP Services need
firasbouzazi e60246e
Note that MCP Service callers must be assigned to the workspace
firasbouzazi fd1dbdf
Report Unity MCP tool errors the model can fix as retries
firasbouzazi 6402af7
Judge each Unity MCP failure by its own error, not shared state
firasbouzazi 51e27b3
Install the MCP client for Databricks provider development
firasbouzazi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1078,6 +1078,7 @@ Maxime | |
| MaxRuntimeInSeconds | ||
| mb | ||
| MCP | ||
| mcp | ||
| md | ||
| mem | ||
| memcached | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| .. Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| .. http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| .. Unless required by applicable law or agreed to in writing, | ||
| software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations | ||
| under the License. | ||
|
|
||
|
|
||
| Databricks Toolsets | ||
| =================== | ||
|
|
||
| Toolsets give agents from the :doc:`Common AI provider <apache-airflow-providers-common-ai:index>` | ||
| tools backed by Databricks. They need the ``common.ai`` extra: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| pip install 'apache-airflow-providers-databricks[common.ai]' | ||
|
|
||
| .. toctree:: | ||
| :maxdepth: 1 | ||
| :glob: | ||
|
|
||
| * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| .. Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| .. http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| .. Unless required by applicable law or agreed to in writing, | ||
| software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations | ||
| under the License. | ||
|
|
||
| .. _howto/toolset:DatabricksUnityMCPToolset: | ||
|
|
||
| Unity Gateway MCP Services | ||
| ========================== | ||
|
|
||
| Use :class:`~airflow.providers.databricks.toolsets.unity_mcp.DatabricksUnityMCPToolset` to give an | ||
| agent the tools of a Unity Gateway MCP Service: either one Databricks provides for workspace tools | ||
| and SaaS applications, such as ``system.ai.google_calendar``, or an external MCP server registered as | ||
| an MCP Service in Unity Catalog. The toolset works with | ||
| :class:`~airflow.providers.common.ai.operators.agent.AgentOperator`, ``@task.agent``, and the LangChain | ||
| bridge of the Common AI provider. | ||
|
|
||
| The Dag names the service by its three-level Unity Catalog name, ``catalog.schema.service``, and the | ||
| :ref:`Databricks connection <howto/connection:databricks>` to use. The toolset builds the service URL, | ||
| ``https://<workspace host>/ai-gateway/mcp-services/<catalog.schema.service>``, from the connection's | ||
| host, so neither the gateway URL nor a token appears in Dag code, and the connection's token is only | ||
| sent to that workspace, over HTTPS. A connection whose ``schema`` is ``http`` is rejected unless its | ||
| host is a loopback address. Requests go through the proxy in the connection's ``proxies`` extra, if | ||
| set. Service names may contain only ASCII letters, digits and ``_`` in each part; any other name is | ||
| rejected before a request is made. | ||
|
|
||
| .. exampleinclude:: /../../databricks/tests/system/databricks/example_databricks_unity_mcp.py | ||
| :language: python | ||
| :start-after: [START howto_toolset_databricks_unity_mcp] | ||
| :end-before: [END howto_toolset_databricks_unity_mcp] | ||
|
|
||
| The service name and connection ID are templated when the toolset is passed to ``AgentOperator`` or | ||
| ``@task.agent``. | ||
|
|
||
| Caller identity and authentication | ||
| ---------------------------------- | ||
|
|
||
| MCP Services need a workspace enabled for Unity Catalog, in a region where Model Serving is | ||
| supported. | ||
|
|
||
| The gateway runs every tool call as the identity of the connection's credentials. That identity needs | ||
| ``EXECUTE`` on the MCP Service, ``USE CATALOG`` and ``USE SCHEMA`` on its parent catalog and schema | ||
| (``EXECUTE`` alone is not enough), and an assignment to the workspace. It needs no privilege on the | ||
| Unity Catalog connection behind the service. On the built-in ``system.ai`` services, account users | ||
| hold these privileges by default (see `MCP Services | ||
| <https://docs.databricks.com/aws/en/agents/mcp-tools/mcp-services>`__). The gateway exposes only the | ||
| tools selected for the service, and the service's policies apply. Grant the identity only the services | ||
| the agent should use. | ||
|
|
||
| Built-in services that act on a user's own data, such as ``system.ai.google_calendar`` or | ||
| ``system.ai.gmail``, need that identity to complete a one-time OAuth login first, for example by | ||
| opening the service in Catalog Explorer and clicking **Login**. | ||
|
|
||
| The toolset sends the connection's token as a bearer token, so the connection must use one of these | ||
| authentication modes of the Databricks connection: | ||
|
|
||
| * a personal access token (the identity is the token's user or service principal); | ||
| * service principal OAuth (``service_principal_oauth``); | ||
| * Azure AD: a service principal, a managed identity, or ``DefaultAzureCredential``; | ||
| * workload identity federation (Kubernetes, AWS IAM, or a supplied token provider). | ||
|
|
||
| For service principal OAuth, the OAuth secret must allow the ``all-apis`` scope, which the connection | ||
| requests; a secret restricted to narrower scopes fails (see `OAuth for service principals | ||
| <https://docs.databricks.com/aws/en/dev-tools/auth/oauth-m2m>`__). Username and password | ||
| authentication is not supported. A token is fetched from the connection for | ||
| every request, so OAuth and Azure AD tokens are refreshed during a long agent run and when the toolset | ||
| reconnects. Tokens minted for the toolset are masked in task logs. | ||
|
|
||
| Errors and retries | ||
| ------------------ | ||
|
|
||
| When the MCP server answers a tool call with an error, such as invalid arguments, the error goes to the | ||
| model, which can correct the call and try again. | ||
|
|
||
| When the gateway gives no answer of its own, a tool call that was already sent may or may not have | ||
| run, and repeating a tool that changes data could apply the change twice. The toolset never retries | ||
| it: the task fails with one of these exceptions from :mod:`airflow.providers.databricks.exceptions`, | ||
| which are also raised for failures while connecting and listing tools: | ||
|
|
||
| .. list-table:: | ||
| :header-rows: 1 | ||
|
|
||
| * - Exception | ||
| - Cause | ||
| * - ``DatabricksUnityMCPAccessDeniedError`` | ||
| - The gateway will not let the identity invoke the service: no service has that name, the | ||
| identity lacks ``EXECUTE`` on the service or ``USE CATALOG`` / ``USE SCHEMA`` on its parents, | ||
| or the credentials are invalid. A missing service is reported like a missing privilege. | ||
| * - ``DatabricksUnityMCPThrottledError`` | ||
| - HTTP 429. Its ``retry_after`` attribute holds the ``Retry-After`` delay in seconds, when given. | ||
| * - ``DatabricksUnityMCPTransportError`` | ||
| - The gateway could not be reached, or the connection dropped. | ||
| * - ``DatabricksUnityMCPError`` | ||
| - Any other gateway error, or a failure to get a token from the connection. | ||
|
|
||
| The exceptions carry the HTTP status in ``http_status_code`` when it is known. When the agent runs | ||
| several tool calls of the toolset at once, the status of a failed call cannot be told apart from the | ||
| others', so the error is reported as ``DatabricksUnityMCPError`` without it. Use task retries for | ||
| calls that are safe to repeat. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
providers/databricks/src/airflow/providers/databricks/toolsets/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apache-airflow-providers-common-ai[mcp]. Otherwise fastmcp isn't installed byuv syncandtest_unity_mcp.pyskips.