MCP API and SDK reference
Use these examples to automate MCP setup. The API represents each MCP as an McpService resource. For the workspace UI, see External MCP servers. For access controls and policies, see Govern an MCP.
Prerequisites
- Have your MCP server URL and authentication details ready, or use an existing HTTP connection.
- Check the registration permissions or update and delete permissions for your operation.
- Install and authenticate the Databricks CLI or your chosen SDK. SDK snippets assume an authenticated workspace client.
Replace main.default.my_mcp, the connection name, and data-team with your own values. Creating MCPs with SQL commands such as CREATE MCP SERVICE isn't supported.
API operations
The MCP REST API provides these operations. Follow each link for its fields, permissions, and responses.
Operation | Use it to |
|---|---|
Register an MCP server through an HTTP connection. | |
Find MCPs you can access in a schema. | |
Read an MCP's configuration and current | |
Change the comment, connection, tool selection, or rate limits. | |
Remove a registered MCP. | |
Sign in or re-authenticate the caller with the provider. | |
Read the caller's provider login state. | |
Revoke the caller's provider credential. |
To discover and call tools, use an MCP client with the MCP URL, https://<workspace-hostname>/ai-gateway/mcp-services/<catalog>.<schema>.<service>. These management APIs use the unity-catalog OAuth scope. MCP tool calls use ai-gateway.
Create a connection
Create a schema-level HTTP connection to your MCP server. These examples connect to https://mcp.example.com/mcp with a bearer token. For OAuth and other authentication settings, see HTTP connection settings.
For REST or CLI, save this request as connection.json, replacing the URL and token with your server's values. Keep this credential file out of source control.
{
"name": "my_connection",
"parent": "schemas/main.default",
"connection_type": "HTTP",
"options": {
"host": "https://mcp.example.com",
"port": "443",
"base_path": "/mcp",
"bearer_token": "<mcp-server-token>"
}
}
- REST API
- CLI
- Python SDK
Send the request to the Connections API:
databricks api post /api/2.1/unity-catalog/connections --json @connection.json
databricks connections create --json @connection.json
Make the server's bearer token available in the MCP_SERVER_TOKEN environment variable.
import os
from databricks.sdk import WorkspaceClient
from databricks.sdk.service import catalog as c
w = WorkspaceClient()
connection = w.connections.create(
name="my_connection",
parent="schemas/main.default",
connection_type=c.ConnectionType.HTTP,
options={
"host": "https://mcp.example.com",
"port": "443",
"base_path": "/mcp",
"bearer_token": os.environ["MCP_SERVER_TOKEN"],
},
)
The connection's full name is main.default.my_connection. Reference it as connections/main.default.my_connection when creating the MCP below. If the connection already exists, use its name and skip this step.
Create an MCP
The MCP references an existing HTTP connection. To limit the tools it exposes, configure tool selection.
- REST API
- CLI
- Terraform
- Bundles (Beta)
- Python SDK
- Go SDK
- Go Modular SDK
- Java SDK
- JS Modular SDK
Send a POST to /api/2.1/unity-catalog/mcp-services, passing parent and mcp_service_id as query parameters. config.source_connection.name identifies the Unity Catalog HTTP connection to the MCP server. Set include_tool_selectors to restrict tools, or omit it to expose all tools. See Choose available tools.
databricks api post \
"/api/2.1/unity-catalog/mcp-services?parent=schemas/main.default&mcp_service_id=my_mcp" \
--json '{
"comment": "External MCP server",
"config": {
"source_connection": {
"name": "connections/main.default.my_connection"
}
}
}'
Pass the parent schema and MCP name, and supply the configuration with --json. Set include_tool_selectors to restrict tools, or omit it to expose all tools.
databricks ai-gateway create-mcp-service schemas/main.default my_mcp --json '{
"comment": "External MCP server",
"config": {
"source_connection": {
"name": "connections/main.default.my_connection"
}
}
}'
Create and manage an MCP with the Databricks Terraform provider and the databricks_ai_gateway_mcp_service resource:
resource "databricks_ai_gateway_mcp_service" "example" {
parent = "schemas/main.default"
mcp_service_id = "my_mcp"
comment = "External MCP server"
config = {
source_connection = {
name = "connections/main.default.my_connection"
}
}
}
Define the MCP in a bundle and deploy it with databricks bundle deploy. MCP resources require Databricks CLI version 1.17.0 and above and the direct deployment engine.
resources:
mcp_services:
my_mcp:
parent: schemas/main.default
mcp_service_id: my_mcp
comment: External MCP server
config:
source_connection:
name: connections/main.default.my_connection
Create and manage an MCP with the Databricks SDK for Python:
from databricks.sdk import WorkspaceClient
from databricks.sdk.service import catalog as c
w = WorkspaceClient()
mcp_service = w.ai_gateway.create_mcp_service(
parent="schemas/main.default",
mcp_service_id="my_mcp",
mcp_service=c.McpService(
comment="External MCP server",
config=c.McpServiceConfig(
source_connection=c.McpServiceConfigSourceConnection(
name="connections/main.default.my_connection"
),
),
),
)
Create and manage an MCP with the Databricks SDK for Go:
mcpService, err := w.AiGateway.CreateMcpService(ctx, catalog.CreateMcpServiceRequest{
Parent: "schemas/main.default",
McpServiceId: "my_mcp",
McpService: catalog.McpService{
Comment: "External MCP server",
Config: &catalog.McpServiceConfig{
SourceConnection: &catalog.McpServiceConfigSourceConnection{
Name: "connections/main.default.my_connection",
},
},
},
})
Create and manage an MCP Service with the Databricks AI Gateway SDK for Go. Optional fields are pointers, so the example uses a one-line helper, func ptr[T any](v T) *T { return &v }.
mcpService, err := c.CreateMcpService(ctx, aigateway.CreateMcpServiceRequest{
Parent: ptr("schemas/main.default"),
McpServiceId: ptr("my_mcp"),
McpService: &aigateway.McpService{
Comment: ptr("External MCP server"),
Config: &aigateway.McpServiceConfig{
Source: &aigateway.McpServiceConfig_Source_SourceConnection{
SourceConnection: aigateway.McpServiceConfig_SourceConnection{
Name: ptr("connections/main.default.my_connection"),
},
},
},
},
})
Create and manage an MCP with the Databricks SDK for Java:
McpService mcpService =
w.aiGateway()
.createMcpService(
new CreateMcpServiceRequest()
.setParent("schemas/main.default")
.setMcpServiceId("my_mcp")
.setMcpService(
new McpService()
.setComment("External MCP server")
.setConfig(
new McpServiceConfig()
.setSourceConnection(
new McpServiceConfigSourceConnection()
.setName("connections/main.default.my_connection")))));
Create and manage an MCP with the JavaScript SDK:
const created = await client.createMcpService({
parent: 'schemas/main.default',
mcpServiceId: 'my_mcp',
mcpService: {
comment: 'External MCP server',
config: {
source: {
$case: 'sourceConnection',
sourceConnection: { name: 'connections/main.default.my_connection' },
},
},
},
});
Find an MCP
List the MCPs you can access in a schema, then get an MCP's configuration by its resource name. For built-in MCPs, use schemas/system.ai as the parent.
- REST API
- CLI
- Python SDK
databricks api get \
"/api/2.1/unity-catalog/mcp-services?parent=schemas/main.default&view=FULL"
databricks api get "/api/2.1/unity-catalog/mcp-services/main.default.my_mcp"
When the list response includes next_page_token, pass it as page_token in the next request. Continue until next_page_token is absent or empty.
databricks ai-gateway list-mcp-services --parent schemas/main.default --view FULL
databricks ai-gateway get-mcp-service mcp-services/main.default.my_mcp
from databricks.sdk import WorkspaceClient
from databricks.sdk.service import catalog as c
w = WorkspaceClient()
for service in w.ai_gateway.list_mcp_services(
parent="schemas/main.default",
view=c.ListMcpServicesRequestView.FULL,
):
print(service.name)
service = w.ai_gateway.get_mcp_service(name="mcp-services/main.default.my_mcp")
List responses use BASIC view by default, which omits source-connection details and rate-limit principal names. Use FULL to include those fields. The CLI and Python iterator handle pagination for you.
Grant access
These examples grant EXECUTE on the MCP. For the full access requirements, including parent permissions, see Share an MCP.
- REST API
- CLI
- Terraform
- Bundles (Beta)
- Python SDK
- Go SDK
- Java SDK
databricks api patch \
"/api/2.1/unity-catalog/permissions/mcp_service/main.default.my_mcp" \
--json '{
"changes": [
{ "principal": "data-team", "add": ["EXECUTE"] }
]
}'
Grant EXECUTE with the Databricks CLI:
databricks grants update mcp_service main.default.my_mcp \
--json '{"changes": [{"principal": "data-team", "add": ["EXECUTE"]}]}'
Grant EXECUTE with the Databricks Terraform provider and the databricks_grant resource:
resource "databricks_grant" "example" {
mcp_service = "main.default.my_mcp"
principal = "data-team"
privileges = ["EXECUTE"]
}
Add a grants block to the MCP resource in your bundle and redeploy to grant access.
resources:
mcp_services:
my_mcp:
parent: schemas/main.default
mcp_service_id: my_mcp
comment: External MCP server
config:
source_connection:
name: connections/main.default.my_connection
grants:
- principal: data-team
privileges: [EXECUTE]
Grant EXECUTE with the Databricks SDK for Python:
from databricks.sdk.service import catalog as c
w.grants.update(
securable_type="mcp_service",
full_name="main.default.my_mcp",
changes=[c.PermissionsChange(principal="data-team", add=[c.Privilege.EXECUTE])],
)
Grant EXECUTE with the Databricks SDK for Go:
_, err := w.Grants.Update(ctx, catalog.UpdatePermissions{
SecurableType: "mcp_service",
FullName: "main.default.my_mcp",
Changes: []catalog.PermissionsChange{{
Principal: "data-team",
Add: []catalog.Privilege{catalog.PrivilegeExecute},
}},
})
Grant EXECUTE with the Databricks SDK for Java:
w.grants().update(
new UpdatePermissions()
.setSecurableType("mcp_service")
.setFullName("main.default.my_mcp")
.setChanges(Arrays.asList(
new PermissionsChange().setPrincipal("data-team").setAdd(Arrays.asList(Privilege.EXECUTE)))));
Manage provider sign-in
For MCPs that use per-user OAuth, each caller signs in to the external provider. For interactive sign-in, follow External services setup.
The credential APIs are in Beta. To integrate them into your own OAuth flow:
- Create the caller's credential with the OAuth exchange fields:
authorization_code,pkce_verifier, andoauth_redirect_uri. - Check the credential status.
provisioning_info.statemust beACTIVEbefore the credential is usable.NOT_FOUNDmeans the caller has no credential yet. - To sign out, delete the caller's credential.
These operations manage the calling user's credential. The caller needs access to the MCP.
Update an MCP
These examples update the MCP comment. The MCP name cannot be changed.
Set update_mask to the fields you want to change, such as comment, config.source_connection.name, config.include_tool_selectors, or config.rate_limits. Using config replaces the whole configuration and clears omitted optional fields. When changing the connection, the MCP owner also needs USE CONNECTION on the new connection.
For a conditional update, first get the MCP and pass its etag with the update. The update succeeds only if the MCP hasn't changed since that read. URL-encode the etag when adding it to a REST query string.
- REST API
- CLI
- Terraform
- Bundles (Beta)
- Python SDK
- Go SDK
- Go Modular SDK
- Java SDK
- JS Modular SDK
databricks api patch \
"/api/2.1/unity-catalog/mcp-services/main.default.my_mcp?update_mask=comment" \
--json '{"comment": "Updated: governs an MCP server"}'
databricks ai-gateway update-mcp-service mcp-services/main.default.my_mcp comment \
--json '{"comment": "Updated: governs an MCP server"}'
Edit comment (or any other mutable field) on the databricks_ai_gateway_mcp_service resource and re-apply. Changes apply in place.
Edit comment (or any other mutable field) in the bundle resource and run databricks bundle deploy. Changes apply in place.
from databricks.sdk.service import catalog as c
from databricks.sdk.common.types.fieldmask import FieldMask
updated = w.ai_gateway.update_mcp_service(
name="mcp-services/main.default.my_mcp",
update_mask=FieldMask(["comment"]),
mcp_service=c.McpService(comment="Updated: governs an MCP server"),
)
updated, err := w.AiGateway.UpdateMcpService(ctx, catalog.UpdateMcpServiceRequest{
Name: "mcp-services/main.default.my_mcp",
UpdateMask: *fieldmask.New([]string{"comment"}),
McpService: catalog.McpService{Comment: "Updated: governs an MCP server"},
})
mask, err := types.NewFieldMask[aigateway.McpService]("comment")
updated, err := c.UpdateMcpService(ctx, aigateway.UpdateMcpServiceRequest{
McpService: &aigateway.McpService{
Name: ptr("mcp-services/main.default.my_mcp"),
Comment: ptr("Updated: governs an MCP server"),
},
UpdateMask: mask,
})
McpService updated =
w.aiGateway()
.updateMcpService(
new UpdateMcpServiceRequest()
.setName("mcp-services/main.default.my_mcp")
.setUpdateMask(FieldMask.newBuilder().addPaths("comment").build())
.setMcpService(new McpService().setComment("Updated: governs an MCP server")));
import { mcpServiceFieldMask } from '@databricks/sdk-aigateway/v1';
const updated = await client.updateMcpService({
mcpService: {
name: 'mcp-services/main.default.my_mcp',
comment: 'Updated: governs an MCP server',
},
updateMask: mcpServiceFieldMask('comment'),
});
Example: update tool selection
To expose only tools whose names start with get_:
databricks api patch \
"/api/2.1/unity-catalog/mcp-services/main.default.my_mcp?update_mask=config.include_tool_selectors" \
--json '{
"config": {
"include_tool_selectors": ["get_*"]
}
}'
An empty include_tool_selectors list exposes all tools. See Choose available tools for the UI steps.
Delete an MCP
Delete only the MCP you intend to remove. Clients configured with its URL can no longer call it.
You can also pass the MCP's current etag to make deletion conditional on it not having changed since the last read. URL-encode the etag in REST query strings.
- REST API
- CLI
- Terraform
- Bundles (Beta)
- Python SDK
- Go SDK
- Go Modular SDK
- Java SDK
- JS Modular SDK
databricks api delete "/api/2.1/unity-catalog/mcp-services/main.default.my_mcp"
databricks ai-gateway delete-mcp-service mcp-services/main.default.my_mcp
Remove the MCP resource from your configuration and run terraform apply. Review the plan before applying it.
Remove the MCP resource from the bundle and run databricks bundle deploy. Review the deployment changes before applying them.
w.ai_gateway.delete_mcp_service(name="mcp-services/main.default.my_mcp")
err := w.AiGateway.DeleteMcpService(ctx, catalog.DeleteMcpServiceRequest{
Name: "mcp-services/main.default.my_mcp",
})
err := c.DeleteMcpService(ctx, aigateway.DeleteMcpServiceRequest{
Name: ptr("mcp-services/main.default.my_mcp"),
})
w.aiGateway().deleteMcpService(new DeleteMcpServiceRequest().setName("mcp-services/main.default.my_mcp"));
await client.deleteMcpService({ name: 'mcp-services/main.default.my_mcp' });