Important
SQL モデル コンテキスト プロトコル (MCP) サーバーは、Data API Builder バージョン 1.7 以降で使用できます。
注
このセクションで説明する SQL MCP Server 2.0 の機能は現在プレビュー段階であり、一般公開前に変更される可能性があります。 詳細については、「 バージョン 2.0 の新機能」を参照してください。
SQL MCP Server は、汎用データ操作言語 (DML) ツールを使用してテーブルとビューを公開します。 ストアド プロシージャの場合は、エンティティに custom-tool: true 設定して、プロシージャが名前付きの専用ツールとして MCP ツールリストに表示されるようにすることができます。 AI エージェントは、名前で検出し、その説明を確認し、直接呼び出します。SQL は必要ありません。
Important
カスタム ツール名はエンティティ名から派生しますが、 snake_caseに変換されます。 たとえば、 GetProductById という名前のエンティティは、MCP ツール リストに get_product_by_id されます。 ツールを呼び出すときは、snake_case名を使用します。 PascalCase エンティティ名は、ツール名として使用できません。
この記事の残りの部分では、ストアド プロシージャによってサポートされるカスタム MCP ツールを追加、構成、テストする方法について説明します。
前提条件
- データ API ビルダー バージョン 2.0 以降
- 少なくとも 1 つのストアド プロシージャを含む SQL Server データベース
- MCP が有効になっている既存の
dab-config.json - DAB CLI がインストールされている
構成で MCP を有効にする
まだ行っていない場合は、ランタイム セクションで MCP を有効にします。
dab configure --runtime.mcp.enabled true
これにより、 dab-config.jsonに次のものが追加されます。
{
"runtime": {
"mcp": {
"enabled": true
}
}
}
ストアド プロシージャをカスタム ツールとして追加する
dab addと--source.type stored-procedureで--mcp.custom-tool trueを使用します。
dab add GetProductById \
--source dbo.get_product_by_id \
--source.type "stored-procedure" \
--permissions "anonymous:execute" \
--mcp.custom-tool true
これにより、 dab-config.jsonで次のエンティティが生成されます。
{
"entities": {
"GetProductById": {
"source": {
"object": "dbo.get_product_by_id",
"type": "stored-procedure"
},
"graphql": {
"enabled": true,
"operation": "mutation",
"type": {
"singular": "GetProductById",
"plural": "GetProductByIds"
}
},
"rest": {
"enabled": true,
"methods": [
"post"
]
},
"permissions": [
{
"role": "anonymous",
"actions": [
{
"action": "execute"
}
]
}
],
"mcp": {
"custom-tool": true
}
}
}
}
Important
custom-tool プロパティは、ストアド プロシージャ エンティティでのみ有効です。 テーブルまたはビュー エンティティに設定すると、起動時に構成エラーが発生します。
説明を追加してエージェントの精度を向上させる
説明がない場合、エージェントには技術名 GetProductByIdのみが表示されます。 説明を使用して、何を行い、いつ使用するかを理解します。
dab update GetProductById \
--description "Returns full product details including pricing and inventory for a given product ID"
{
"entities": {
"GetProductById": {
"description": "Returns full product details including pricing and inventory for a given product ID",
"source": {
"object": "dbo.get_product_by_id",
"type": "stored-procedure"
},
"fields": [],
"graphql": {
"enabled": true,
"operation": "mutation",
"type": {
"singular": "GetProductById",
"plural": "GetProductByIds"
}
},
"rest": {
"enabled": true,
"methods": [
"post"
]
},
"permissions": [
{
"role": "anonymous",
"actions": [
{
"action": "execute"
}
]
}
],
"mcp": {
"custom-tool": true
}
}
}
}
ツールがツールの一覧に表示されていることを確認する
DAB を起動し、 tools/list MCP エンドポイントを呼び出して、ツールが登録されていることを確認します。
dab start
MCP クライアントが tools/listを呼び出すと、応答には DML ツールと共にカスタム ツールが含まれます。
{
"tools": [
{
"name": "get_product_by_id",
"description": "Returns full product details including pricing and inventory for a given product ID",
"inputSchema": {
"type": "object",
"properties": {}
}
}
]
}
注
ツール名はsnake_case (たとえば、get_product_by_id エンティティのGetProductById) を使用します。
inputSchemaは現在、空のpropertiesを返します。 エージェントは、ツールの説明と describe_entities に依存して、正しいパラメーターを決定します。
複数のカスタム ツールを構成する
同じ構成で複数のストアド プロシージャをカスタム ツールとして登録できます。
dab add SearchProducts \
--source dbo.search_products \
--source.type "stored-procedure" \
--permissions "anonymous:execute" \
--mcp.custom-tool true \
--description "Full-text search across product names and descriptions"
dab add GetOrderSummary \
--source dbo.get_order_summary \
--source.type "stored-procedure" \
--permissions "authenticated:execute" \
--mcp.custom-tool true \
--description "Returns order totals and line item counts for a given customer"
ツールを呼び出すことができるロールを制御する
カスタム ツールでは、他のすべての DAB エンティティと同じロールベースのアクセス制御 (RBAC) が考慮されます。 エンティティに permissions を設定して、プロシージャを実行できるロールを制限します。
{
"entities": {
"GetOrderSummary": {
"source": {
"object": "dbo.get_order_summary",
"type": "stored-procedure"
},
"graphql": {
"enabled": true,
"operation": "mutation",
"type": {
"singular": "GetOrderSummary",
"plural": "GetOrderSummarys"
}
},
"rest": {
"enabled": true,
"methods": [
"post"
]
},
"permissions": [
{
"role": "authenticated",
"actions": [
{
"action": "execute"
}
]
}
],
"mcp": {
"custom-tool": true
}
}
}
}
エージェントが anonymous ロールを使用して呼び出すと、 get_order_summary は tools/list に表示されないため、直接 tools/call はアクセス許可エラーを返します。
カスタム ツールを削除せずに無効にする
エンティティを削除せずにエージェントからツールを非表示にするには、 custom-tool を false に設定します。
dab update GetProductById \
--mcp.custom-tool false
エンティティは構成に残り、後で --mcp.custom-tool true設定して再度有効にすることができます。