Databricksで管理される MCP サーバーのメタパラメーター
プレビュー
この機能は パブリック プレビュー段階です。
Databricks マネージド MCP サーバーを使用する AI エージェントを構築する際は、結果の制限、検索フィルター、SQL ウェアハウスの選択など、ツールの動作を設定するために _meta パラメーターを使用します。このアプローチにより、エージェントが動的に生成するクエリの柔軟性を維持しながら、構成を事前に設定できます。
_metaパラメーターは、公式のMCP 仕様の一部です。
ツール呼び出しの引数と_metaパラメーター
Databricks の管理対象 MCP サーバーは、パラメーターを 2 つの方法で処理します。
- ツール呼び出し引数 :LLMがユーザー入力に基づいて通常動的に生成するパラメーター
_metaパラメーター : 動作を決定論的に設定するためにエージェント コードで事前に設定できる構成パラメーター
Databricks SQL MCP サーバーの_metaパラメーター
Databricks SQL MCPサーバーは、次の_metaパラメーターをサポートしています:
パラメーター名 | Type | 説明 |
|---|---|---|
|
| クエリの実行に使用するSQLウェアハウスのID。 例: 指定されていない場合、システムはリソースとアクセス許可に基づいてウェアハウスを自動的に選択します。 |
例: Databricks SQL クエリの SQL ウェアハウスを指定する
この例では、公式のPython MCP SDKを使用して、warehouse_id _metaパラメーターを使用して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())
AI検索MCPサーバー_metaパラメーター
AI Search は次の _meta パラメーターをサポートしています。
パラメーター名 | Type | 説明 |
|---|---|---|
|
| 検索結果で返す列名のコンマ区切りリスト。 例: 指定されていない場合、すべての列 (「__」で始まる内部列を除く) が返されます。 |
|
| 再スコアリングにリランキングモデルが使用する、列名のコンマ区切りリスト。リランカーはこのコンテンツを使用してすべての検索結果を再スコアリングし、関連性を向上させます。 例: 指定されていない場合、再ランク付けは実行されません。 |
|
| 検索に適用するフィルターを含むJSON文字列。有効なJSONである必要があります。 例: 指定しない場合、フィルターは適用されません。 |
|
| 類似度スコアを返された結果に含めるかどうか。 サポートされている値: デフォルト: |
|
| 返される結果の数。 例: |
|
| 結果を取得するために使用する検索アルゴリズム。 サポートされている値: デフォルト: |
|
| 結果をフィルタリングするための最小類似度スコア閾値。この閾値を下回るスコアの結果は除外されます。 例: 指定しない場合、スコアフィルタリングは適用されません。 |
これらのパラメーターに関する詳細な情報については、AI Search Python SDKドキュメントを参照してください。
例: AI Search 検索の最大結果とフィルターを構成する
この例では、_metaパラメーターを使用してAI検索の動作を構成し、公式Python MCP SDKを使用してAIエージェントからの動的クエリを可能にする方法を示します。
このシナリオでは、次のようにします:
- 応答時間の一貫性を保つため、検索結果は常に厳密に3項目に制限してください。
- 関連性を確認するために、最新のドキュメント (2024年1月1日以降に更新されたもの) のみで検索します。
- 純粋なベクトル検索よりも高精度なハイブリッド検索を使用します。
- 特定の列 (ID、テキスト、およびメタデータ) のみを返します。
- 結果に類似度スコアを含めます。
- 類似度スコアが0.5未満の結果を除外します。
- 関連性を向上させるには、テキスト列とタイトル列で再ランキングを使用します。
この例を実行するには、マネージドMCP開発用のPython環境をセットアップします。
コード例を展開
# 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_vector_search_tool_call_with_meta():
# Initialize Databricks workspace client for authentication
workspace_client = WorkspaceClient()
# Construct the MCP server URL for your specific catalog and schema
# Replace <workspace-hostname>, YOUR_CATALOG, and YOUR_SCHEMA with your values
mcp_server_url = "https://<workspace-hostname>/api/2.0/mcp/ai-search/YOUR_CATALOG/YOUR_SCHEMA"
# 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 both dynamic and preset parameters
request = CallToolRequest(
method="tools/call",
params={
# Tool name follows the pattern: CATALOG__SCHEMA__INDEX_NAME
"name": "YOUR_CATALOG__YOUR_SCHEMA__YOUR_INDEX_NAME",
# Dynamic arguments - typically provided by your AI agent or user input
"arguments": {
"query": "How do I reset my password?" # This comes from your agent
},
# Meta parameters - preset configuration to control search behavior
"_meta": {
"num_results": "3", # Limit to 3 results for consistent performance
"filters": '{"updated_after": "2024-01-01"}', # JSON string for date filtering
"query_type": "HYBRID", # Use hybrid search for better relevance
"columns": "id,text,metadata", # Return only specific columns
"score_threshold": "0.5", # Filter out results with similarity score < 0.5
"include_score": "true", # Include similarity scores in results
"columns_to_rerank": "text,title" # Use reranker on these columns for better quality
}
}
)
# 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_vector_search_tool_call_with_meta())