CREATE MCP SERVER

创建一个新的 MCP(模型上下文协议)服务器或替换现有的 MCP 服务器。

See also:

DESCRIBE MCP SERVER, DROP MCP SERVER , SHOW MCP SERVERS

语法

CREATE [ OR REPLACE ] MCP SERVER [ IF NOT EXISTS ] <name>
  FROM SPECIFICATION $$<specification_yaml>$$

参数

name

指定 MCP 服务器标识符的字符串;对于在 MCP 服务器中创建任务的架构必须是唯一的。

In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example, "My object"). Identifiers enclosed in double quotes are also case-sensitive.

For more information, see Identifier requirements.

FROM SPECIFICATION $$specification_yaml$$

指定 MCP 服务器所使用的工具和配置的 YAML 规范。

The specification must include a tools array with one or more tool definitions. Each tool must specify:

  • name: Unique identifier for the tool
  • type: Tool type (see supported tool types)
  • title: Human-readable title for the tool
  • description: Description of what the tool does

支持的工具类型:

  • CORTEX_SEARCH_SERVICE_QUERY: Cortex Search Service tool
  • CORTEX_ANALYST_MESSAGE: Cortex Analyst tool
  • SYSTEM_EXECUTE_SQL: SQL execution tool
  • CORTEX_AGENT_RUN: Cortex Agent tool
  • GENERIC: Custom tool for UDFs and stored procedures

特定于工具的要求:

For CORTEX_SEARCH_SERVICE_QUERY, CORTEX_ANALYST_MESSAGE, and CORTEX_AGENT_RUN tools:

  • identifier: Fully qualified name of the underlying object (for example, database.schema.object_name)

For GENERIC tools:

  • identifier: Fully qualified name of the UDF or stored procedure
  • config: Configuration object specifying:
    • type: Either function (for UDF) or procedure (for stored procedure)
    • warehouse: Warehouse to use for execution
    • input_schema: JSON schema defining the function/procedure parameters

访问控制要求

A role used to execute this operation must have the following privileges at a minimum:

PrivilegeObject
CREATE MCP SERVERSchema
USAGESchema

对于引用其他对象的工具,需要额外的权限:

PrivilegeObject
USAGECortex Search Service (for CORTEX_SEARCH_SERVICE_QUERY tools)
SELECTSemantic View (for CORTEX_ANALYST_MESSAGE tools)
USAGECortex Agent (for CORTEX_AGENT_RUN tools)
USAGEUser-defined function or stored procedure (for GENERIC tools)
USAGEWarehouse (for GENERIC tools)

Operating on an object in a schema requires at least one privilege on the parent database and at least one privilege on the parent schema.

For instructions on creating a custom role with a specified set of privileges, see Creating custom roles.

For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.

使用说明

  • The OR REPLACE and IF NOT EXISTS clauses are mutually exclusive. They can’t both be used in the same statement.
  • CREATE OR REPLACE <object> statements are atomic. That is, when an object is replaced, the old object is deleted and the new object is created in a single transaction.

  • CREATE OR REPLACE <object> statements are atomic. That is, when an object is replaced, the old object is deleted and the new object is created in a single transaction.

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

  • The MCP server specification is stored as metadata and can be viewed using DESCRIBE MCP SERVER.

  • 可以在单个 MCP 服务器规范中定义多个工具。

  • 工具名称在单个 MCP 服务器中必须是唯一的。

  • 关于元数据:

    Attention

    Customers should ensure that no personal data (other than for a User object), sensitive data, export-controlled data, or other regulated data is entered as metadata when using the Snowflake service. For more information, see Metadata fields in Snowflake.

示例

示例 1:创建具有 Cortex Search 和 Analyst 工具的 MCP 服务器

CREATE MCP SERVER my_mcp_server
  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"
  $$;

示例 2:创建具有 SQL 执行工具的 MCP 服务器

CREATE MCP SERVER sql_exec_server
  FROM SPECIFICATION $$
    tools:
      - title: "SQL Execution Tool"
        name: "sql_exec_tool"
        type: "SYSTEM_EXECUTE_SQL"
        description: "A tool to execute SQL queries against the connected Snowflake database."
  $$;

示例 3:创建具有自定义 UDF 工具的 MCP 服务器

CREATE MCP SERVER custom_tools_server
  FROM SPECIFICATION $$
    tools:
      - title: "Multiply by Ten"
        identifier: "example_database.agents.multiply_by_ten"
        name: "multiply_by_ten"
        type: "GENERIC"
        description: "Multiplies input value by ten and returns the result."
        config:
          type: "function"
          warehouse: "compute_service_warehouse"
          input_schema:
            type: "object"
            properties:
              x:
                description: "A number to be multiplied by ten"
                type: "number"
  $$;

示例 4:创建具有自定义存储过程工具的 MCP 服务器

CREATE MCP SERVER procedure_tools_server
  FROM SPECIFICATION $$
    tools:
      - title: "Calculate Values"
        identifier: "example_database.agents.calculate_values_sp"
        name: "calculate_values_sp"
        type: "GENERIC"
        description: "Calculates the product and sum of two numbers and returns them in a JSON object."
        config:
          type: "procedure"
          warehouse: "compute_service_warehouse"
          input_schema:
            type: "object"
            properties:
              x:
                description: "First number"
                type: "number"
              y:
                description: "Second number"
                type: "number"
  $$;

示例 5:创建具有代理工具的 MCP 服务器

CREATE MCP SERVER agent_server
  FROM SPECIFICATION $$
    tools:
      - title: "Customer Service Agent"
        name: "customer_agent"
        type: "CORTEX_AGENT_RUN"
        identifier: "support_db.agents_schema.customer_service_agent"
        description: "Agent that handles customer service inquiries"
  $$;