メインコンテンツまでスキップ

Databricksで管理される MCP サーバーのメタ問題

備考

プレビュー

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

Databricksで管理される MCP サーバーを使用するAIエージェントを構築する場合は、 _metaを使用して、結果の制限、検索フィルタ、 SQLウェアハウスの選択などのツールの動作を制御します。 これにより、エージェントが動的に生成するクエリを柔軟に保ちながら、構成を事前に設定できます。

_metaパラメーターは、公式のMCP 仕様の一部です。

ツール呼び出しの引数と_metaパラメーター

Databricksで管理される MCP サーバーは、次の 2 つの方法で問題を処理します。

  • ツール呼び出しの引数 : LLM通常、ユーザー入力に基づいて動的に生成されるという問題
  • _meta問題 : 動作を決定論的に制御するためにエージェント コードで事前設定できる構成の問題

Databricks SQL MCP サーバー_metaの問題

Databricks SQL MCP サーバーでは、次の_meta問題がサポートされています。

パラメーター名

Type

説明

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ウェアハウスへの接続」を参照してください。

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_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
&quot;name&quot;: &quot;execute_sql&quot;,

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

# Meta parameters - specify which warehouse to use
&quot;_meta&quot;: {
&quot;warehouse_id&quot;: &quot;a1b2c3d4e5f67890&quot; # 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パラメーター

次の _meta パラメーターが、AI Search でサポートされています。

パラメーター名

Type

説明

columns

str

検索結果で返される列名のコンマ区切りリスト。

例: "id,text,metadata"

指定しない場合は、すべての列(「__」で始まる内部列を除く)が返されます。

columns_to_rerank

str

再ランキング モデルが再スコアリングに使用するコンテンツを持つ列名のコンマ区切りリスト。リランカーはこのコンテンツを使用してすべての検索結果のスコアを再調整し、関連性を向上させます。

例: "text,title,description"

指定しない場合は再ランク付けは実行されません。

filters

str

検索に適用するフィルターを含む JSON 文字列。有効な JSON である必要があります。

例: '{"updated_after": "2024-01-01"}'

指定しない場合はフィルターは適用されません。

include_score

bool

返される結果に類似度スコアを含めるかどうか。

サポートされている値: "true"または "false"

デフォルト: "false"

num_results

int

返される結果の数。

例: "5"

query_type

str

結果を取得するために使用する検索アルゴリズム。

サポートされている値: "ANN" (近似最近傍、デフォルト) または"HYBRID" (ベクトル検索とキーワード検索の組み合わせ)

デフォルト: "ANN"

score_threshold

float

結果をフィルタリングするための類似度スコアの最小しきい値。このしきい値を下回るスコアの結果は除外されます。

例: "0.7"

指定しない場合は、スコア フィルタリングは適用されません。

これらのパラメーターに関する詳細情報については、AI Search Python SDK ドキュメントを参照してください。

例: AI Search取得の最大結果数とフィルターの設定

この例では、_metaパラメーターを使用して、AIエージェントからの動的クエリを許可しながらAI検索の動作を制御する方法を示します。公式のPython MCP SDKを使用しています。

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

  • 応答時間を一定に保つために、検索結果を常に 3 項目に制限します。
  • 関連性を確保するため、最近のドキュメント(2024年1月1日以降に更新されたもの)のみを検索します。
  • ハイブリッド検索を使用すると、純粋なベクトル検索よりも精度が向上します。
  • 特定の列(ID、テキスト、メタデータ)のみを返す
  • 結果に類似度スコアを含める
  • 類似度スコアが0.5未満の結果を除外する
  • 関連性を高めるためにテキストとタイトルの列の再ランク付けを使用する

この例を実行するには、マネージド MCP 開発用の Python 環境をセットアップします

コード例を展開する

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
&quot;name&quot;: &quot;YOUR_CATALOG__YOUR_SCHEMA__YOUR_INDEX_NAME&quot;,

# Dynamic arguments - typically provided by your AI agent or user input
&quot;arguments&quot;: {
&quot;query&quot;: &quot;How do I reset my password?&quot; # This comes from your agent
},

# Meta parameters - preset configuration to control search behavior
&quot;_meta&quot;: {
&quot;num_results&quot;: &quot;3&quot;, # Limit to 3 results for consistent performance
&quot;filters&quot;: '{&quot;updated_after&quot;: &quot;2024-01-01&quot;}', # JSON string for date filtering
&quot;query_type&quot;: &quot;HYBRID&quot;, # Use hybrid search for better relevance
&quot;columns&quot;: &quot;id,text,metadata&quot;, # Return only specific columns
&quot;score_threshold&quot;: &quot;0.5&quot;, # Filter out results with similarity score &lt; 0.5
&quot;include_score&quot;: &quot;true&quot;, # Include similarity scores in results
&quot;columns_to_rerank&quot;: &quot;text,title&quot; # 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())

次のステップ