diff --git a/knowledge_base/mcp_and_model_services/.gitignore b/knowledge_base/mcp_and_model_services/.gitignore new file mode 100644 index 0000000..15bcc6d --- /dev/null +++ b/knowledge_base/mcp_and_model_services/.gitignore @@ -0,0 +1 @@ +.databricks diff --git a/knowledge_base/mcp_and_model_services/README.md b/knowledge_base/mcp_and_model_services/README.md new file mode 100644 index 0000000..53ea768 --- /dev/null +++ b/knowledge_base/mcp_and_model_services/README.md @@ -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= --var chat_model= --var mcp_connection= + ``` + +3. Send a chat request to the model service. The schema name is `.dev__ai_services`: + ```bash + databricks api post /ai-gateway/mlflow/v1/chat/completions --json '{ + "model": ".dev__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/.dev__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= --var chat_model= --var mcp_connection= + ``` diff --git a/knowledge_base/mcp_and_model_services/databricks.yml b/knowledge_base/mcp_and_model_services/databricks.yml new file mode 100644 index 0000000..48da65b --- /dev/null +++ b/knowledge_base/mcp_and_model_services/databricks.yml @@ -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} diff --git a/knowledge_base/mcp_and_model_services/resources/ai_services.schema.yml b/knowledge_base/mcp_and_model_services/resources/ai_services.schema.yml new file mode 100644 index 0000000..3eada6d --- /dev/null +++ b/knowledge_base/mcp_and_model_services/resources/ai_services.schema.yml @@ -0,0 +1,5 @@ +resources: + schemas: + ai_services: + catalog_name: ${var.catalog} + name: ai_services diff --git a/knowledge_base/mcp_and_model_services/resources/anthropic.model_provider_service.yml b/knowledge_base/mcp_and_model_services/resources/anthropic.model_provider_service.yml new file mode 100644 index 0000000..47167a0 --- /dev/null +++ b/knowledge_base/mcp_and_model_services/resources/anthropic.model_provider_service.yml @@ -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: {} diff --git a/knowledge_base/mcp_and_model_services/resources/chat.model_service.yml b/knowledge_base/mcp_and_model_services/resources/chat.model_service.yml new file mode 100644 index 0000000..aceb9f5 --- /dev/null +++ b/knowledge_base/mcp_and_model_services/resources/chat.model_service.yml @@ -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} diff --git a/knowledge_base/mcp_and_model_services/resources/docs.mcp_service.yml b/knowledge_base/mcp_and_model_services/resources/docs.mcp_service.yml new file mode 100644 index 0000000..eedb7c6 --- /dev/null +++ b/knowledge_base/mcp_and_model_services/resources/docs.mcp_service.yml @@ -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}