使用说明
Snowflake Cortex AI模型上下文协议(MCP)服务器
此Snowflake MCP服务器为Snowflake Cortex AI、对象管理和SQL编排提供工具,将这些功能带入MCP生态系统。当连接到MCP客户端时(例如。 Claude桌面版, 快速代理, 代理编排框架),用户可以利用这些功能。
MCP服务器目前支持以下功能:
- 皮质搜索:在Snowflake中查询非结构化数据,如检索增强生成(RAG)应用程序中常用的。
- 皮质分析员:通过丰富的语义建模在Snowflake中查询结构化数据。
- 皮质剂:跨结构化和非结构化数据检索的代理编排器
- 对象管理:对Snowflake最常见的对象执行基本操作,如创建、删除、更新等。
- SQL执行:运行由用户配置的权限管理的LLM生成的SQL。
- 语义视图查询:发现和查询雪花语义视图
入门指南
服务配置
一个简单的配置文件用于驱动所有工具。一个例子可以在 services/configuration.yaml 下面是一个模板。此配置文件的路径将传递给服务器,其内容用于在启动时创建MCP服务器工具。
Cortex服务
可以添加许多Cortex代理、搜索和分析服务。理想的描述既具有高度的描述性,又相互排斥。 只有明确列出的Cortex服务才能作为MCP客户端中的工具使用。
其他服务
其他服务包括工具 对象管理, 查询执行,以及 语义视图使用.
这些工具组可以通过在中设置为True来启用 other_services 配置文件的一部分。
SQL语句权限
这 sql_statement_permissions 该部分确保只有经过批准的语句才能在任何有权更改Snowflake对象的工具上执行。
该列表包含SQL表达式类型。标有True的是允许的,标有False的是不允许的。请看 SQL执行 对于每种表达式类型的示例。
agent_services: # List all Cortex Agent services
- service_name: <service_name>
description: > # Describe contents of the agent service
<Agent service that ...>
database_name: <database_name>
schema_name: <schema_name>
- service_name: <service_name>
description: > # Describe contents of the agent service
<Agent service that ...>
database_name: <database_name>
schema_name: <schema_name>
search_services: # List all Cortex Search services
- service_name: <service_name>
description: > # Describe contents of the search service
<Search services that ...>
database_name: <database_name>
schema_name: <schema_name>
- service_name: <service_name>
description: > # Describe contents of the search service
<Search services that ...>
database_name: <database_name>
schema_name: <schema_name>
analyst_services: # List all Cortex Analyst semantic models/views
- service_name: <service_name> # Create descriptive name for the service
semantic_model: <semantic_yaml_or_view> # Fully-qualify semantic YAML model or Semantic View
description: > # Describe contents of the analyst service
<Analyst service that ...>
- service_name: <service_name> # Create descriptive name for the service
semantic_model: <semantic_yaml_or_view> # Fully-qualify semantic YAML model or Semantic View
description: > # Describe contents of the analyst service
<Analyst service that ...>
other_services: # Set desired tool groups to True to enable tools for that group
object_manager: True # Perform basic operations against Snowflake's most common objects such as creation, dropping, updating, and more.
query_manager: True # Run LLM-generated SQL managed by user-configured permissions.
semantic_manager: True # Discover and query Snowflake Semantic Views and their components.
sql_statement_permissions: # List SQL statements to explicitly allow (True) or disallow (False).
# - All: True # To allow everything, uncomment and set All: True.
- Alter: True
- Command: True
- Comment: True
- Commit: True
- Create: True
- Delete: True
- Describe: True
- Drop: True
- Insert: True
- Merge: True
- Rollback: True
- Select: True
- Transaction: True
- TruncateTable: True
- Unknown: False # To allow unknown or unmapped statement types, set Unknown: True.
- Update: True
- Use: True
[!注意] 以前版本的配置文件支持为列指定显式值,并为每个Cortex Search服务指定限制。相反,这些现在完全是基于用户提示的动态的。如果未指定,将返回搜索服务的默认search_columns,限制为10。
连接到Snowflake
MCP服务器使用 Snowflake Python连接器 适用于所有身份验证和连接方法。 请参阅Snowflake官方文档,了解全面的身份验证选项和最佳实践。
MCP服务器尊重分配给指定角色(在连接参数中传递)或用户默认角色(如果没有传递角色进行连接)的RBAC权限。
连接参数可以作为CLI参数和/或环境变量传递。服务器支持Snowflake Python连接器中可用的所有身份验证方法,包括:
- 用户名/密码验证
- 密钥对身份验证
- OAuth身份验证
- 单点登录(SSO)
- 多因素身份验证(MFA)
连接参数
连接参数可以作为CLI参数和/或环境变量传递:
| 参数 | CLI参数 | 环境变量 | 描述 |
|---|---|---|---|
| 帐户 | --帐户 | SNOWFLAKE_Account | 帐户标识符(例如xy12345.us-east-1) |
| 主机 | --主机 | SNOWFLAKE_Host | 雪花主机URL |
| 用户 | --用户,--用户名 | SNOWFLAKE_User | 身份验证用户名 |
| 密码 | --密码 | SNOWFLAKE_Password | 密码或编程访问令牌 |
| 角色 | --Role | SNOWFLAKE_Role | 用于连接的角色 |
| 仓库 | --仓库 | SNOWFLAKE_Warehouse | 用于查询的仓库 |
| 密码中的密码 | --密码中的通行码 | - | 密码中是否嵌入了通行码 |
| 密码 | --密码 | SNOWFLAKE_Passcode | MFA身份验证密码 |
| 私钥 | --私钥 | SNOWFLAKE_Private_Key | 密钥对身份验证私钥 |
| 私钥文件 | --私钥文件 | SNOWFLAKE_Private_Key_File | 私钥文件路径 |
| 私钥密码 | --私钥文件pwd | SNOWFLAKE_Private_Key_file_pwd | 加密私钥密码 |
| 身份验证器 | --身份验证器 | - | 身份验证类型(默认:雪花) |
| 连接名称 | --连接名称 | - | connections.toml(或config.toml)文件中的连接名称 |
[!警告] 弃用通知:CLI参数
--account-identifier和--pat,以及环境变量SNOWFLAKE_PAT,已弃用,并将在未来的版本中删除。请使用--account和--password(或SNOWFLAKE_ACCOUNT和SNOWFLAKE_PASSWORD)相反。
传输配置
MCP服务器支持多种传输机制。有关MCP传输的详细信息,请参阅 FastMCP传输协议.
| 运输 | 描述 | 用例 |
|---|---|---|
stdio |
标准输入/输出(默认) | 本地开发,MCP客户端集成 |
sse (传统) |
服务器发送事件 | 流媒体应用程序 |
streamable-http |
可流式HTTP传输 | 容器部署、远程服务器 |
用法
# Default stdio transport
uvx snowflake-labs-mcp --service-config-file config.yaml
# HTTP transport with custom endpoint
uvx snowflake-labs-mcp --service-config-file config.yaml --transport streamable-http --endpoint /my-endpoint
# For containers (uses streamable-http on port 9000)
uvx snowflake-labs-mcp --service-config-file config.yaml --transport streamable-http --endpoint /snowflake-mcp
运输定制
可用于的服务器自定义 sse 和 streamable-http 运输:
| 参数 | CLI参数 | 环境变量 | 默认值 |
|---|---|---|---|
| 主机 | --服务器主机 | SNOWFLAKE_MCP_Host | “0.0.0.0” |
| 端口 | --端口 | SNOWFLAKE_MCP_Port | 9000 |
| 端点 | --端点 | SNOWFLAKE_MCP_Endpoint | /MCP |
| 调试日志 | --verbose | SNOWFLAKE_MCP_verbose | false |
例子:
export SNOWFLAKE_MCP_ENDPOINT="/my-mcp"
uvx snowflake-labs-mcp --service-config-file config.yaml --transport streamable-http
与MCP客户端一起使用
MCP服务器与客户端无关,将与大多数支持MCP工具和(可选)资源基本功能的MCP客户端一起工作。以下是本地安装的示例。要连接到容器化部署,请参阅 将MCP客户端连接到容器.
克劳德桌面
要将此服务器与Claude Desktop集成为MCP客户端,请将以下内容添加到应用程序的服务器配置中。默认情况下,它位于:
- macOS:~/库/应用程序支持/Claude/Claude_desktop_config json
- Windows:%APPDATA%\Claude\Claude_desktop_config.json
设置服务配置文件的路径并配置连接方法:
{
"mcpServers": {
"mcp-server-snowflake": {
"command": "uvx",
"args": [
"snowflake-labs-mcp",
"--service-config-file",
"<path_to_file>/tools_config.yaml",
"--connection-name",
"default"
]
}
}
}
光标
通过打开光标并导航到设置->光标设置->MCP,在光标中注册MCP服务器。添加以下内容:
{
"mcpServers": {
"mcp-server-snowflake": {
"command": "uvx",
"args": [
"snowflake-labs-mcp",
"--service-config-file",
"<path_to_file>/tools_config.yaml",
"--connection-name",
"default"
]
}
}
}
在聊天中添加MCP服务器作为上下文。