Skip to main content

Use custom MCP servers in agents

After hosting a custom MCP server as a Databricks app, connect to it from notebooks, local development, or agent code using the databricks-mcp Python library.

To host a custom MCP server, see Host a custom MCP server.

Connect to the custom MCP server

Click the tabs to see how to connect to an MCP server from various environments.

Authenticate to your workspace using OAuth as described in Set up your environment.

The following example shows how to connect to the custom MCP server and list available tools:

Python
from databricks_mcp import DatabricksMCPClient
from databricks.sdk import WorkspaceClient

# Replace with your deployed app URL
# Example: https://mcp-my-server-6051921418418893.aws.databricksapps.com/mcp
mcp_server_url = "https://<app-url>/mcp"

databricks_cli_profile = "DEFAULT"
workspace_client = WorkspaceClient(profile=databricks_cli_profile)

mcp_client = DatabricksMCPClient(server_url=mcp_server_url, workspace_client=workspace_client)

# List available tools
tools = mcp_client.list_tools()
print(f"Available tools: {tools}")

Example notebooks: Build an agent with Databricks MCP servers

The following notebooks show how to author LangGraph and OpenAI agents that call MCP tools with custom MCP servers hosted on Databricks apps.

LangGraph MCP tool-calling agent

Open notebook in new tab

OpenAI MCP tool-calling agent

Open notebook in new tab

Next steps

The apps cookbook provides end-to-end code examples for integrating MCP servers with different frameworks:

For complete source code and additional examples, see the Databricks Apps Cookbook repository.