Databricks MCP Python API
- Setup:
Install
databricks-mcp
.pip install -U databricks-mcp
- class databricks_mcp.DatabricksOAuthClientProvider(workspace_client: WorkspaceClient)
Bases:
OAuthClientProvider
An OAuthClientProvider for Databricks. This class extends mcp.client.auth.OAuthClientProvider and can be used with the
mcp.client.streamable_http
to 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:
object
Note
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_client
from 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_client
from 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_model
when 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