Snowflake管理の MCP サーバー

概要

注釈

Snowflakeはモデルコンテキストプロトコルリビジョン 2025-06-18 をサポートしています。

モデルコンテキストプロトコル( MCP )は、 オープンソース標準 であり、 AI エージェントがビジネスアプリケーションや、データベースやコンテンツリポジトリなどの外部データシステムと安全にやり取りできるようにします。 MCP は、エンタープライズビジネスが統合の課題を減らし、モデルから成果を迅速に提供できるようにします。リリース以来、 MCP はエージェントアプリケーションの基盤となり、ツールの呼び出しとデータの取得のための一貫性のある安全なメカニズムを提供しています。

The Snowflake-managed MCP server lets AI agents securely retrieve data from Snowflake accounts without needing to deploy separate infrastructure. You can configure the MCP server to serve Cortex Analyst, Cortex Search, and Cortex Agents as tools, along with custom tools and SQL executions on the standards-based interface. MCP clients discover and invoke these tools, and retrieve data required for the application. With managed MCP servers on Snowflake, you can build scalable enterprise-grade applications while maintaining access and privacy controls. The MCP server on Snowflake provides:

  • 標準化された統合: 急速に進化する標準に準拠した、ツールの検出と呼び出しのための統一されたインターフェース。

  • 包括的な認証: Snowflakeの組み込み OAuth サービスにより、 MCP 統合のための OAuth ベースの認証が可能になります。

  • 堅牢なガバナンス: ツールの検出と呼び出しを管理するための MCP サーバーとツールに対するロールベースのアクセス制御( RBAC )。

MCP ライフサイクルの詳細については、 ライフサイクル をご参照ください。MCP の実装例については、 マネージドSnowflake MCP サーバーを使い始める クイックスタートをご参照ください。

MCP server security recommendations

重要

When you configure hostnames for MCP server connections, use hyphens (-) instead of underscores (_). MCP servers have connection issues with hostnames containing underscores.

Using multiple MCP servers without verifying tools and descriptions could lead to vulnerabilities such as tool poisoning or tool shadowing. Snowflake recommends verifying third-party MCP servers before using them. This includes any MCP server from another Snowflake user or account. Verify all tools offered by third-party MCP servers.

We recommend using OAuth as the authentication method. Using hardcoded tokens can lead to token leakage.

When using a Programmatic Access Token (PAT), set it to use the least-privileged role allowed to work with MCP. This will help prevent leaking a secret with access to a highly-privileged role.

Configure proper permissions for the MCP server and tools following the least-privilege principle. Access to the MCP Server does not give access to the tools. Permission needs to be granted for each tool.

MCP サーバーオブジェクトの作成

ツールとその他のメタデータを指定してオブジェクトを作成します。必要な認証の後、サーバーに接続する MCP クライアントはこれらのツールを検出して呼び出すことができます。

  1. MCP サーバーを作成するデータベースとスキーマに移動します。

  2. MCP サーバーを作成します。

    CREATE [ OR REPLACE ] MCP SERVER [ IF NOT EXISTS ] <server_name>
      FROM SPECIFICATION $$
        tools:
          - name: "product-search"
            type: "CORTEX_SEARCH_SERVICE_QUERY"
            identifier: "database1.schema1.Cortex_Search_Service1"
            description: "cortex search service for all products"
            title: "Product Search"
    
          - name: "revenue-semantic-view"
            type: "CORTEX_ANALYST_MESSAGE"
            identifier: "database1.schema1.Semantic_View_1"
            description: "Semantic view for all revenue tables"
            title: "Semantic view for revenue"
      $$
    
    Copy

Snowflakeは現在、次のタイプのツールをサポートしています。

  • ** CORTEX_SEARCH_SERVICE_QUERY :** Cortex Search Serviceツール

  • ** CORTEX_ANALYST_MESSAGE :** Cortex Analystツール

  • SYSTEM_EXECUTE_SQL: SQL execution

  • CORTEX_AGENT_RUN: Cortex Agent tool

  • GENERIC: tool for UDFs and stored procedures

The following examples show how to configure different tool types:

Using the Analyst tool, your client can generate text from SQL. Use the following code to specify the tool configuration.

注釈

The Snowflake-managed MCP server only supports using semantic views with Cortex Analyst. It does not support semantic models.

tools:
  - name: "revenue-semantic-view"
    type: "CORTEX_ANALYST_MESSAGE"
    identifier: "database1.schema1.Semantic_View_1"
    description: "Semantic view for all revenue tables"
    title: "Semantic view for revenue"
Copy

Use the following examples to create and configure custom tools using UDFs and stored procedures:

The following examples demonstrate creating UDFs that can be used as custom tools:

-- create a simple udf
CREATE OR REPLACE FUNCTION MULTIPLY_BY_TEN(x FLOAT)
RETURNS FLOAT
LANGUAGE PYTHON
RUNTIME_VERSION = '3.8'
HANDLER = 'multiply_by_ten'
AS
$$
def multiply_by_ten(x: float) -> float:
  return x * 10
$$;

SHOW FUNCTIONS LIKE 'MULTIPLY_BY_TEN';

-- test return json/variant
CREATE OR REPLACE FUNCTION CALCULATE_PRODUCT_AND_SUM(x FLOAT, y FLOAT)
RETURNS VARIANT
LANGUAGE PYTHON
RUNTIME_VERSION = '3.8'
HANDLER = 'calculate_values'
AS
$$
import json

def calculate_values(x: float, y: float) -> dict:
  """
  Calculates the product and sum of two numbers and returns them in a dictionary.
  The dictionary is converted to a VARIANT (JSON) in the SQL return.
  """
  product = x * y
  sum_val = x + y

  return {
      "product": product,
      "sum": sum_val
  }
$$;

-- test return list/array
CREATE OR REPLACE FUNCTION GET_NUMBERS_IN_RANGE(x FLOAT, y FLOAT)
RETURNS ARRAY -- Use ARRAY to explicitly state a list is being returned
LANGUAGE PYTHON
RUNTIME_VERSION = '3.8'
HANDLER = 'get_numbers'
AS
$$
def get_numbers(x: float, y: float) -> list:
  """
  Returns a list of integers between x (exclusive) and y (inclusive).
  Assumes x < y.
  """
  # Ensure x and y are treated as integers for range generation
  start = int(x) + 1
  end = int(y) + 1 # range() is exclusive on the stop value

  # Use a list comprehension to generate the numbers
  # The Python list will be converted to a Snowflake ARRAY.
  return list(range(start, end))
$$;
Copy
  1. MCP サーバーを表示するには、次のコマンドを使用します。

    SHOW MCP SERVERS IN DATABASE <database_name>;
    SHOW MCP SERVERS IN SCHEMA <schema_name>;
    SHOW MCP SERVERS IN ACCOUNT;
    
    Copy

    The following shows the output of the command:

    |               created_on               |       name        | database_name | schema_name |    owner     |           comment            |
    ------------------------------------------+-------------------+---------------+-------------+--------------+------------------------------
    | Fri, 23 Jun 1967 07:00:00.123000 +0000 | TEST_MCP_SERVER   | TEST_DATABASE | TEST_SCHEMA | ACCOUNTADMIN | [NULL]                       |
    | Fri, 23 Jun 1967 07:00:00.123000 +0000 | TEST_MCP_SERVER_2 | TEST_DATABASE | TEST_SCHEMA | ACCOUNTADMIN | Test MCP server with comment |
    
  2. MCP サーバーについて説明するには、次のコマンドを使用します。

    DESCRIBE MCP SERVER <server_name>;
    
    Copy

    The following shows the output of the command:

    |      name       | database_name | schema_name |    owner     | comment |     server_spec        |               created_on               |
    ------------------------------------------------------------------------------------------------------+-------------------------------------
    | TEST_MCP_SERVER | TEST_DATABASE | TEST_SCHEMA | ACCOUNTADMIN | [NULL]  | {"version":1,"tools":[{"name":"product-search","identifier":"db.schema.search_service","type":"CORTEX_SEARCH_SERVICE_QUERY"}]} | Fri, 23 Jun 1967 07:00:00.123000 +0000 |
    
  3. MCP サーバーを削除するには、次のコマンドを使用します。

    DROP MCP SERVER <server_name>;
    
    Copy

アクセス制御

次の権限を使用して、 MCP オブジェクトとその基礎となるツールへのアクセスを管理できます

権限

オブジェクト

説明

OWNERSHIP

MCP オブジェクト

オブジェクト設定の更新に必要です

MODIFY

MCP オブジェクト

オブジェクト設定の更新、削除、記述、表示、使用( tools/listtools/call )を提供します

USAGE

MCP オブジェクト

MCP サーバーに接続し、ツールを検出するために必要です

USAGE

Cortex Search Service

MCP サーバーでCortex Searchツールを起動するために必要です

SELECT

セマンティックビュー

MCP サーバーでCortex Analystツールを起動するために必要です

USAGE

Cortex Agent

Required to invoke the Cortex Agent as a tool in the MCP server

USAGE

User-defined function (UDF) or stored procedure

Required to invoke the UDF or stored procedure as a tool in the MCP server

OAuth 認証の設定

MCP クライアントの認証を構成します。Snowflakeが管理する MCP サーバーは、 MCP プロトコルの 認証 推奨事項に沿った OAuth 2.0 をサポートします。Snowflakeが管理する MCP サーバーは、動的なクライアント登録をサポートしていません。

  1. まず、セキュリティ統合を作成します。このコマンドについては、 CREATE SECURITY INTEGRATION (Snowflake OAuth) をご参照ください。

    CREATE [ OR REPLACE ] SECURITY INTEGRATION [IF NOT EXISTS] <integration_name>
      TYPE = OAUTH
      OAUTH_CLIENT = GENERIC
      ENABLED = TRUE
      OAUTH_CLIENT_TYPE = 'CONFIDENTIAL'
      OAUTH_REDIRECT_URI = '<redirect_URI>'
    
    Copy
  2. 次に、システム関数を呼び出して、クライアント設定用のクライアントIDとキーを取得します。統合名は大文字と小文字を区別し、大文字である必要があります。

    SELECT SYSTEM$SHOW_OAUTH_CLIENT_SECRETS('<integration_name>');
    
    Copy

カスタム MCP クライアントを使用して MCP サーバーと対話する

カスタム MCP クライアントを構築している場合、次のセクションではクライアントが対話するSnowflakeエンドポイントを示します。

注釈

Snowflake MCP サーバーは現在、ツール機能のみをサポートしています。

MCP サーバーの初期化

認証後、次の API エンドポイントに GET と POST コールを発行してサーバーを初期化します。

POST /api/v2/databases/{database}/schemas/{schema}/mcp-servers/{name}
    {
        "jsonrpc": "2.0",
        "id": 1,
        "method": "initialize",
        "params": { "protocolVersion": "2025-06-18" }
    }
Copy

次の例はその応答を示しています。

{
    "jsonrpc": "2.0", // passthrough from req
    "id": 1, // passthrough from req
    "result": {
        "proto_version": "2025-06-18",
        "capabilities": {
            "tools": {
                "listChanged": false
            }
        },
        "server_info": {
            "name": "<snowflake-mcp-name>",
            "title": "Snowflake Server: <snowflake-mcp-name>",
            "version": "1.0.0"
        }
    }
}
Copy

ツールを検出して呼び出す

MCP クライアントは、 tools/listtools/call リクエストでツールを検出し、呼び出すことができます。

ツールを検出するには、 ツール/リストリクエスト に示すように、 POST コールを発行します。

POST /api/v2/databases/{database}/schemas/{schema}/mcp-servers/{name}
    {
        "jsonrpc": "2.0",
        "id": 1,
        "method": "tools/list",
        "params": {}
    }
Copy

次の例はその応答を示しています。

{
    "jsonrpc": "2.0", // passthrough from req
    "id": 1, // passthrough from req
    "result": {
        "tools": [ // search
            {
                "name":"product-search",
                "description":"Test search tool",
                "inputSchema": {
                    "type": "object",
                    "description": "A search query and additional parameters for search.",
                    "properties": {
                        "query": {
                            "description": "Unstructured text query.  Exactly one of 'query' or 'multi_index_query' must be specified.",
                            "type": "string"
                        },
                        "columns": {
                            "description": "List of columns to return.",
                            "type": "array",
                            "items": {
                                "type": "string"
                            }
                        },
                        "filter": {
                            "description": "Filter query.",
                            "type": "object"
                        },
                        "limit": {
                            "description": "Max number of results to return.",
                            "type": "integer",
                            "default": 10
                        }
                    }
                },
                "outputSchema": {
                    "type": "object",
                    "description": "Search results.",
                    "properties": {
                        "results": {
                            "description": "List of result rows.",
                            "type": "array",
                            "items": {
                                "type": "object",
                                "additionalProperties": true,
                                "description": "Map of column names to values (as bytes)."
                            }
                        },
                    "request_id": {
                        "description": "ID of the request.",
                        "type": "string"
                    }
                },
                "required": ["results", "request_id"]
            }
          },
          { // analyst
              "name":"revenue-semantic-view",
              "description":"Test tool",
              "inputSchema": {
                  "type": "object",
                  "description": "A message and additional parameters for Cortex Analyst.",
                  "properties": {
                      "message": {
                          "description": "The user’s question.",
                          "type": "string"
                      }
                  }
              }
          }
        ]
    }
}
Copy

ツールを呼び出すには、 ツール/コールリクエスト に示すように、 POST コールを発行します。

For the Analyst tool, your client passes messages in the request. The SQL statement is listed in the output. You must pass the name of the tool that you're invoking in the request in the name parameter.

POST /api/v2/databases/<database>/schemas/<schema>/mcp-servers/<name>
    {
        "jsonrpc": "2.0",
        "id": 1,
        "method": "tools/call",
        "params": {
            "name": "test-analyst",
            "arguments": {
                "message ": "text"
            }
        }
    }
Copy

次の例はその応答を示しています。

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "content": [
            {
                "type": "text",
                "text": "string"
            }
        ]
    }
}
Copy

検索ツールのリクエストでは、クライアントはクエリと次のオプション引数を渡すことができます。

  • フィルター

  • 制限

The search results and request ID are returned in the output. You must pass the name of the tool that you're invoking in the request as the name parameter.

POST /api/v2/databases/{database}/schemas/{schema}/mcp-servers/{name}
    {
        "jsonrpc": "2.0",
        "id": 1,
        "method": "tools/call",
        "params": {
            "name": "product-search",
            "arguments": {
                "query": "Hotels in NYC",
                "columns": array of strings,
                "filter": json,
                "limit": int
            }
        }
  }
Copy

次の例はその応答を示しています。

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "results": {}
    }
}
Copy

制限事項

Snowflake管理の MCP サーバーは、 MCP プロトコル内のリソース、プロンプト、ルート、通知、バージョンネゴシエーション、ライフサイクルフェーズ、サンプリングといった構成要素をサポートしていません。

非ストリーミング応答のみがサポートされています。