Databricks MCP Python API
- Setup:
Install
databricks-mcp.pip install -U databricks-mcp
- class databricks_mcp.DatabricksOAuthClientProvider(workspace_client: WorkspaceClient)
Bases:
OAuthClientProviderAn OAuthClientProvider for Databricks. This class extends mcp.client.auth.OAuthClientProvider and can be used with the
mcp.client.streamable_httpto authorize the MCP Server with Databricks.- Usage:
from databricks_mcp.oauth_provider import DatabricksOAuthClientProvider from mcp.client.streamable_http import streamablehttp_client from mcp.client.session import ClientSession # Initialize the Databricks workspace client workspace_client = WorkspaceClient() async with streamablehttp_client( url="https://mcp-server-url", auth=DatabricksOAuthClientProvider(workspace_client), ) as (read_stream, write_stream, _): async with ClientSession(read_stream, write_stream) as session: await session.initialize()
- Parameters:
workspace_client (databricks.sdk.WorkspaceClient) – The Databricks workspace client used for authentication and requests.
- class databricks_mcp.DatabricksMCPClient(server_url: str, workspace_client: WorkspaceClient | None = None)
Bases:
objectNote
Experimental: This class may change or be removed in a future release without warning.
A client for interacting with a MCP(Model Context Protocol) servers on Databricks.
This class provides a simplified interface to communicate with a specified MCP server URL with Databricks Authorization. Additionally this client provides helpers to retrieve the dependent resources for Databricks Managed MCP Resources to enable automatic authorization in Model Serving.
- client
The Databricks workspace client used for authentication and requests.
- Type:
databricks.sdk.WorkspaceClient
- list_tools() List[Tool]
Lists the tools for the current MCP Server. This method uses the
streamablehttp_clientfrom mcp to fetch all the tools from the MCP server.- Returns:
A list of tools for the current MCP Server.
- Return type:
List[mcp.types.Tool]
- call_tool(tool_name: str, arguments: dict[str, Any] | None = None) CallToolResult
Calls the tool with the given name and input. This method uses the
streamablehttp_clientfrom mcp to call the tool.
- get_databricks_resources() List[DatabricksResource]
Returns a list of dependent Databricks resources for the current MCP server URL.
If authoring a custom code agent that runs tools from a Databricks Managed MCP server, call this method and pass the returned resources to
mlflow.pyfunc.log_modelwhen logging your agent, to enable your agent to authenticate to the MCP server and run tools when deployed.Note that this method only supports detecting resources for Databricks-managed MCP servers. For custom MCP servers or other MCP server URLs, this method returns an empty list
- databricks_mcp.register_mcp_server_via_dcr(connection_name: str, mcp_url: str, workspace_client: WorkspaceClient | None = None) str
Note
Experimental: This function may change or be removed in a future release without warning.
Register an MCP server via OAuth discovery and Dynamic Client Registration.
This function performs the complete OAuth discovery and DCR flow: 1. Check if Unity Catalog connection already exists (prevents duplicates) 2. Discover Protected Resource Metadata (header + well-known fallback) 3. Discover Authorization Server Metadata 4. Select OAuth scope following MCP spec priority order:
scope from WWW-Authenticate header (if present)
scopes_supported from Protected Resource Metadata (if available)
omit scope parameter (if neither available)
Perform Dynamic Client Registration with Databricks redirect URI
Create Unity Catalog connection with the registered client
- Args:
connection_name: Name for the Unity Catalog connection mcp_url: The MCP endpoint URL workspace_client: Optional WorkspaceClient instance. If None, a new one is created.
- Returns:
The workspace URL to view the connection
- Raises:
ValueError: If inputs are invalid RuntimeError: If any step of the discovery or registration process fails
- Example:
>>> connection_url = register_mcp_server_via_dcr( ... connection_name="my_mcp_connection", mcp_url="https://mcp.example.com/api" ... ) >>> print(connection_url) 'https://workspace.cloud.databricks.com/explore/connections/my_mcp_connection?o=1234567890&activeTab=overview'