Databricks SQL (ダタブリックス SQL)

Important

この機能は パブリック プレビュー段階です

Databricks SQL MCPサーバーは、Azure Databricksが管理するMCPサーバーで、エージェントがUnityカタログのテーブルに対してAI生成SQLを実行し、データの読み書きを行い、Unityカタログの権限で管理されます。 AIコーディングツールからデータパイプラインを構築するために使うのが良いでしょう。 クエリは非同期で実行されます。エージェントはツールを呼び出してクエリを開始し、応答が完了するまでポーリングを行います。

URL パターン OAuth スコープ
https://<workspace-hostname>/api/2.0/mcp/sql sql

_meta パラメーター

_meta パラメータとは、エージェントコード内でMCPサーバーの挙動を決定論的に設定するための設定値であり、ツール呼び出し時に動的に生成されるのではなく、 Databricks SQL MCPサーバーは以下の _meta パラメータをサポートしています:

パラメーター名 タイプ Description
warehouse_id str クエリの実行に使用する SQL ウェアハウスの ID。
例: "a1b2c3d4e5f67890"
指定しない場合、リソースとアクセス許可に基づいて倉庫が自動的に選択されます。

例: Databricks SQL クエリの SQL ウェアハウスを指定する

この例では、warehouse_id_meta パラメーターを使用して、公式の Python MCP SDK を使用して Databricks SQL MCP サーバーからクエリを実行する SQL ウェアハウスを指定する方法を示します。

このシナリオでは、次の操作を行います。

  • システムがクエリを自動的に選択するのではなく、クエリ実行に特定の SQL ウェアハウスを使用する
  • 専用ウェアハウスにクエリをルーティングして一貫したパフォーマンスを確認する

この例を実行するには、 マネージド MCP 開発用に Python 環境を設定します

SQL ウェアハウス ID を見つけるには、「 SQL ウェアハウスへの接続」を参照してください。

# Import required libraries for MCP client and Databricks authentication
import asyncio
from databricks.sdk import WorkspaceClient
from databricks_mcp.oauth_provider import DatabricksOAuthClientProvider
from mcp.client.streamable_http import streamablehttp_client
from mcp.client.session import ClientSession
from mcp.types import CallToolRequest, CallToolResult

async def run_dbsql_tool_call_with_meta():
    # Initialize Databricks workspace client for authentication
    workspace_client = WorkspaceClient()

    # Construct the MCP server URL for DBSQL
    # Replace <workspace-hostname> with your workspace hostname
    mcp_server_url = "https://<workspace-hostname>/api/2.0/mcp/sql"

    # Establish connection to the MCP server with OAuth authentication
    async with streamablehttp_client(
        url=mcp_server_url,
        auth=DatabricksOAuthClientProvider(workspace_client),
    ) as (read_stream, write_stream, _):

        # Create an MCP session for making tool calls
        async with ClientSession(read_stream, write_stream) as session:
            # Initialize the session before making requests
            await session.initialize()

            # Create the tool call request with warehouse_id in _meta
            request = CallToolRequest(
                method="tools/call",
                params={
                    # Tool name for executing SQL queries
                    "name": "execute_sql",

                    # Dynamic arguments - typically provided by your AI agent
                    "arguments": {
                        "query": "SELECT * FROM my_catalog.my_schema.my_table LIMIT 10"
                    },

                    # Meta parameters - specify which warehouse to use
                    "_meta": {
                        "warehouse_id": "a1b2c3d4e5f67890"  # Your SQL warehouse ID
                    }
                }
            )

            # Send the request and get the response
            response = await session.send_request(request, CallToolResult)
            return response

# Execute the async function and get results
response = asyncio.run(run_dbsql_tool_call_with_meta())