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

Databricksで管理される MCP サーバーのメタパラメーター

備考

プレビュー

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

Databricks マネージド MCP サーバーを使用する AI エージェントを構築する際は、結果の制限、検索フィルター、SQL ウェアハウスの選択など、ツールの動作を設定するために _meta パラメーターを使用します。このアプローチにより、エージェントが動的に生成するクエリの柔軟性を維持しながら、構成を事前に設定できます。

_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 ウェアハウスを指定する

この例では、公式のPython MCP SDKを使用して、warehouse_id _metaパラメーターを使用して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パラメーター

AI Search は次の _meta パラメーターをサポートしています。

パラメーター名

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検索の動作を構成し、公式Python MCP SDKを使用してAIエージェントからの動的クエリを可能にする方法を示します。

このシナリオでは、次のようにします:

  • 応答時間の一貫性を保つため、検索結果は常に厳密に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())

次のステップ