Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions knowledge_base/mcp_and_model_services/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.databricks
44 changes: 44 additions & 0 deletions knowledge_base/mcp_and_model_services/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# MCP and model services

This Declarative Automation Bundles example defines an AI Gateway model service, a model provider service, and an MCP service in a Unity Catalog schema.
The model service routes chat requests to a Databricks foundation model. The model provider service connects to Anthropic with relayed authentication. The MCP service exposes the tools of an external MCP server.

For more information, see the [bundle resources documentation](https://docs.databricks.com/aws/en/dev-tools/bundles/resources#model_services).

## Prerequisites

* Databricks CLI v1.20.0 or above, authenticated with OAuth (`databricks auth login`)
* `jq`
* A Unity Catalog catalog where you can create schemas
* A schema-level HTTP connection to an MCP server. See [Register an external MCP server](https://docs.databricks.com/aws/en/ai-gateway/register-mcp-service).

## Usage

1. Select a pay-per-token foundation model from the `system.ai` schema, for example `system.ai.databricks-claude-sonnet-4-6`.

2. Deploy the bundle. Replace the placeholders with your catalog, model, and connection:
```bash
databricks bundle deploy --var catalog=<catalog> --var chat_model=<model> --var mcp_connection=<connection>
```

3. Send a chat request to the model service. The schema name is `<catalog>.dev_<your_user>_ai_services`:
```bash
databricks api post /ai-gateway/mlflow/v1/chat/completions --json '{
"model": "<catalog>.dev_<your_user>_ai_services.chat",
"messages": [{"role": "user", "content": "What is Databricks?"}]
}'
```

4. List the tools of the MCP service. The command gets the host and a token from the CLI:
```bash
curl -X POST "$(databricks auth describe --output json | jq -r .details.host)/ai-gateway/mcp-services/<catalog>.dev_<your_user>_ai_services.docs" \
-H "Authorization: Bearer $(databricks auth token | jq -r .access_token)" \
-H "Accept: application/json, text/event-stream" \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}'
```

5. Remove the services and the schema:
```bash
databricks bundle destroy --var catalog=<catalog> --var chat_model=<model> --var mcp_connection=<connection>
```
23 changes: 23 additions & 0 deletions knowledge_base/mcp_and_model_services/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
bundle:
name: mcp_and_model_services
# AI Gateway services can only be deployed with the direct deployment engine.
engine: direct

include:
- resources/*.yml

variables:
catalog:
description: Existing Unity Catalog catalog for the services schema.
chat_model:
# Example: system.ai.databricks-claude-sonnet-4-6
description: Pay-per-token foundation model in system.ai, as catalog.schema.model.
mcp_connection:
description: Schema-level HTTP connection to an MCP server, as catalog.schema.connection.

targets:
dev:
mode: development
default: true
workspace:
root_path: /Workspace/bundle-examples/${bundle.name}/dev/${workspace.current_user.short_name}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resources:
schemas:
ai_services:
catalog_name: ${var.catalog}
name: ai_services
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
resources:
model_provider_services:
anthropic:
parent: schemas/${resources.schemas.ai_services.id}
model_provider_service_id: anthropic
comment: Anthropic provider with relayed authentication.
config:
provider_type: EXTERNAL_MODEL_PROVIDER_TYPE_ANTHROPIC
allow_all_targets: true
anthropic:
# Each request supplies its own Anthropic credential. No key is stored.
relayed: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resources:
model_services:
chat:
parent: schemas/${resources.schemas.ai_services.id}
model_service_id: chat
comment: Routes chat requests to a Databricks foundation model.
config:
routing:
destinations:
- name: primary
destination_type: DESTINATION_TYPE_PAY_PER_TOKEN_FOUNDATION_MODEL
pay_per_token_config:
model: models/${var.chat_model}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resources:
mcp_services:
docs:
parent: schemas/${resources.schemas.ai_services.id}
mcp_service_id: docs
comment: Exposes the tools of an external MCP server.
config:
source_connection:
# The connection holds the MCP server URL and credentials.
name: connections/${var.mcp_connection}