Labsco
Snowflake-Labs logo

Snowflake Cortex AI

β˜… 291

from Snowflake-Labs

A server for Snowflake providing tools for its Cortex AI features, including Search, Analyst, and Complete.

πŸ”₯πŸ”₯βœ“ VerifiedFreeAdvanced setup

[DEPRECATED] Snowflake Cortex AI Model Context Protocol (MCP) Server

[!CAUTION] This project is deprecated and no longer maintained. Please migrate to the official Snowflake MCP Server. The official server is actively developed, fully supported by Snowflake, and continues to add new features.

This community MCP server previously provided tooling for Snowflake Cortex AI, object management, and SQL orchestration. It is no longer supported. For all new and existing use cases, please use the official Snowflake MCP Server instead.


<details> <summary>Legacy documentation (for reference only)</summary>

The MCP server supported the below capabilities:

  • Cortex Search: Query unstructured data in Snowflake as commonly used in Retrieval Augmented Generation (RAG) applications.
  • Cortex Analyst: Query structured data in Snowflake via rich semantic modeling.
  • Cortex Agent: Agentic orchestrator across structured and unstructured data retrieval
  • Object Management: Perform basic operations against Snowflake's most common objects such as creation, dropping, updating, and more.
  • SQL Execution: Run LLM-generated SQL managed by user-configured permissions.
  • Semantic View Querying: Discover and query Snowflake Semantic Views

Getting Started

Connecting to Snowflake

The MCP server uses the Snowflake Python Connector for all authentication and connection methods. Please refer to the official Snowflake documentation for comprehensive authentication options and best practices.

The MCP server honors the RBAC permissions assigned to the specified role (as passed in the connection parameters) or default role of the user (if no role is passed to connect).

Connection parameters can be passed as CLI arguments and/or environment variables. The server supports all authentication methods available in the Snowflake Python Connector, including:

  • Username/password authentication
  • Key pair authentication
  • OAuth authentication
  • Single Sign-On (SSO)
  • Multi-factor authentication (MFA)

Connection Parameters

Connection parameters can be passed as CLI arguments and/or environment variables:

ParameterCLI ArgumentsEnvironment VariableDescription
Account--accountSNOWFLAKE_ACCOUNTAccount identifier (e.g. xy12345.us-east-1)
Host--hostSNOWFLAKE_HOSTSnowflake host URL
User--user, --usernameSNOWFLAKE_USERUsername for authentication
Password--passwordSNOWFLAKE_PASSWORDPassword or programmatic access token
Role--roleSNOWFLAKE_ROLERole to use for connection
Warehouse--warehouseSNOWFLAKE_WAREHOUSEWarehouse to use for queries
Passcode in Password--passcode-in-password-Whether passcode is embedded in password
Passcode--passcodeSNOWFLAKE_PASSCODEMFA passcode for authentication
Private Key--private-keySNOWFLAKE_PRIVATE_KEYPrivate key for key pair authentication
Private Key File--private-key-fileSNOWFLAKE_PRIVATE_KEY_FILEPath to private key file
Private Key Password--private-key-file-pwdSNOWFLAKE_PRIVATE_KEY_FILE_PWDPassword for encrypted private key
Authenticator--authenticator-Authentication type (default: snowflake)
Connection Name--connection-name-Name of connection from connections.toml (or config.toml) file

[!WARNING] Deprecation Notice: The CLI arguments --account-identifier and --pat, as well as the environment variable SNOWFLAKE_PAT, are deprecated and will be removed in a future release. Please use --account and --password (or SNOWFLAKE_ACCOUNT and SNOWFLAKE_PASSWORD) instead.

Transport Configuration

The MCP server supports multiple transport mechanisms. For detailed information about MCP transports, see FastMCP Transport Protocols.

TransportDescriptionUse Case
stdioStandard input/output (default)Local development, MCP client integration
sse (legacy)Server-Sent EventsStreaming applications
streamable-httpStreamable HTTP transportContainer deployments, remote servers

Transport Customizations

Server customizations available for sse and streamable-http transports:

ParameterCLI ArgumentEnvironment VariableDefault
Host--server-hostSNOWFLAKE_MCP_HOST"0.0.0.0"
Port--portSNOWFLAKE_MCP_PORT9000
Endpoint--endpointSNOWFLAKE_MCP_ENDPOINT/mcp
Debug Logging--verboseSNOWFLAKE_MCP_VERBOSEfalse

Example:

Copy & paste β€” that's it
export SNOWFLAKE_MCP_ENDPOINT="/my-mcp"
uvx snowflake-labs-mcp --service-config-file config.yaml --transport streamable-http

Using with MCP Clients

The MCP server is client-agnostic and will work with most MCP Clients that support basic functionality for MCP tools and (optionally) resources. Below are examples for local installation. For connecting to containerized deployments, see Connecting MCP Clients to Containers.

Cursor

Register the MCP server in Cursor by opening Cursor and navigating to Settings -> Cursor Settings -> MCP. Add the below:

Copy & paste β€” that's it
{
  "mcpServers": {
    "mcp-server-snowflake": {
      "command": "uvx",
      "args": [
        "snowflake-labs-mcp",
        "--service-config-file",
        "<path_to_file>/tools_config.yaml",
        "--connection-name",
        "default"
      ]
    }
  }
}

Add the MCP server as context in the chat.

<img src="https://sfquickstarts.s3.us-west-1.amazonaws.com/misc/mcp/Cursor.gif" width="800"/>

For troubleshooting Cursor server issues, view the logs by opening the Output panel and selecting Cursor MCP from the dropdown menu.

fast-agent

Update the fastagent.config.yaml mcp server section with the configuration file path and connection name:

Copy & paste β€” that's it
# MCP Servers
mcp:
    servers:
        mcp-server-snowflake:
            command: "uvx"
            args: ["snowflake-labs-mcp", "--service-config-file", "<path_to_file>/tools_config.yaml", "--connection-name", "default"]
<img src="https://sfquickstarts.s3.us-west-1.amazonaws.com/misc/mcp/fast-agent.gif" width="800"/>

Microsoft Visual Studio Code + GitHub Copilot

For prerequisites, environment setup, step-by-step guide and instructions, please refer to this blog.

<img src="https://sfquickstarts.s3.us-west-1.amazonaws.com/misc/mcp/dash-dark-mcp-copilot.gif"/>

Codex

Register the MCP server in codex by adding the following to ~/.codex/config.toml

Copy & paste β€” that's it
[mcp_servers.mcp-server-snowflake]
command = "uvx"
args = [
    "snowflake-labs-mcp",
    "--service-config-file",
    "<path_to_file>/tools_config.yaml",
    "--connection-name",
    "default"
]

After editing, the snowflake mcp should appear in the output of codex mcp list run from the terminal.

Container Deployment

Deploy the MCP server as a container for remote access or production environments. This guide provides step-by-step instructions for both Docker and Docker Compose deployments.

Connecting MCP Clients to Containers

Once your MCP server is running in a container, you can connect various MCP clients to it. The connection configuration is the same across all clients - only the configuration format differs.

Connection URL Format:

  • Local deployment: http://localhost:9000/snowflake-mcp
  • Remote deployment: http://<hostname>:<port>/snowflake-mcp

Claude Desktop

Add this to your claude_desktop_config.json:

Copy & paste β€” that's it
{
  "mcpServers": {
    "mcp-server-snowflake": {
      "url": "http://localhost:9000/snowflake-mcp"
    }
  }
}

Cursor

Add this to your MCP settings in Cursor (Settings -> Cursor Settings -> MCP):

Copy & paste β€” that's it
{
  "mcpServers": {
    "mcp-server-snowflake": {
      "url": "http://localhost:9000/snowflake-mcp"
    }
  }
}

fast-agent

Add this to your fastagent.config.yaml:

Copy & paste β€” that's it
# MCP Servers
mcp:
    servers:
        mcp-server-snowflake:
            url: "http://localhost:9000/snowflake-mcp"

Notes:

  • For remote deployments, replace localhost:9000 with your server's hostname and port
  • Ensure your firewall allows connections on port 9000 (or your configured port)
  • For production deployments, consider using HTTPS and proper authentication

Cortex Services

Instances of Cortex Agent (in agent_services section), Cortex Search (in search_services section), and Cortex Analyst (in analyst_services section) of the configuration file will be served as tools. Leave these sections blank to omit such tools.

Only Cortex Agent objects are supported in the MCP server. That is, only Cortex Agent objects pre-configured in Snowflake can be leveraged as tools. See Cortex Agent Run API for more details.

Ensure all services have accurate context names for service name, database, schema, etc. Ideal descriptions are both highly descriptive and mutually exclusive.

The semantic_model value in analyst services should be a fully-qualified semantic view OR semantic YAML file in a Snowflake stage:

  • For a semantic view: MY_DATABASE.MY_SCHEMA.MY_SEMANTIC_VIEW
  • For a semantic YAML file: @MY_DATABASE.MY_SCHEMA.MY_STAGE/my_semantic_file.yaml (Note the @.)

Object Management

The MCP server includes dozens of tools narrowly scoped to fulfill basic operation management. It is recommended to use Snowsight directly for advanced object management.

The MCP server currently supports creating, dropping, creating or altering, describing, and listing the below object types. To enable these tools, set object_manager to True in the configuration file under other_services.

Copy & paste β€” that's it
- Database
- Schema
- Table
- View
- Warehouse
- Compute Pool
- Role
- Stage
- User
- Image Repository

Please note that these tools are also governed by permissions captured in the configuration file under sql_statement_permissions. Object management tools to create and create or alter objects are governed by the Create permission. Object dropping is governed by the Drop permission.

It is likely that more actions and objects will be included in future releases.

SQL Execution

The general SQL tool will provide a way to execute generic SQL statements generated by the MCP client. Users have full control over the types of SQL statement that are approved in the configuration file.

Listed in the configuration file under sql_statement_permissions are sqlglot expression types. Those marked as False will be stopped before execution. Those marked with True will be executed (or prompt the user for execution based on the MCP client settings).

To enable the SQL execution tool, set query_manager to True in the configuration file under other_services. To allow all SQL expressions to pass the additional validation, set All to True.

Not all Snowflake SQL commands are mapped in sqlglot and you may find some obscure commands have yet to be captured in the configuration file. Setting Unknown to True will allow these uncaptured commands to pass the additional validation. You may also add new expression types directly to honor specific ones.

Below are some examples of sqlglot expression types with accompanying Snowflake SQL command examples:

SQLGlot Expression TypeSQL Command
AlterALTER TABLE my_table ADD COLUMN new_column VARCHAR(50);
CommandCALL my_procedure('param1_value', 123);<br/>GRANT ROLE analyst TO USER user1;<br/>SHOW TABLES IN SCHEMA my_database.my_schema;
CommentCOMMENT ON TABLE my_table IS 'This table stores customer data.';
CommitCOMMIT;
CreateCREATE TABLE my_table ( id INT, name VARCHAR(255), email VARCHAR(255) );<br/>CREATE OR ALTER VIEW my_schema.my_new_view AS SELECT id, name, created_at FROM my_schema.my_table WHERE created_at >= '2023-01-01';
DeleteDELETE FROM my_table WHERE id = 101;
DescribeDESCRIBE TABLE my_table;
DropDROP TABLE my_table;
ErrorCOPY INTO my_table FROM @my_stage/data/customers.csv FILE_FORMAT = (TYPE = CSV SKIP_HEADER = 1 FIELD_DELIMITER = ',');<br/>REVOKE ROLE analyst FROM USER user1;<br/>UNDROP TABLE my_table;
InsertINSERT INTO my_table (id, name, email) VALUES (102, 'Jane Doe', 'jane.doe@example.com');
MergeMERGE INTO my_table AS target USING (SELECT 103 AS id, 'John Smith' AS name, 'john.smith@example.com' AS email) AS source ON target.id = source.id WHEN MATCHED THEN UPDATE SET target.name = source.name, target.email = source.email WHEN NOT MATCHED THEN INSERT (id, name, email) VALUES (source.id, source.name, source.email);
RollbackROLLBACK;
SelectSELECT id, name FROM my_table WHERE id < 200 ORDER BY name;
TransactionBEGIN;
TruncateTableTRUNCATE TABLE my_table;
UpdateUPDATE my_table SET email = 'new.email@example.com' WHERE name = 'Jane Doe';
UseUSE DATABASE my_database;

Semantic View Querying

Several tools support the discovery and querying of Snowflake Semantic Views and their components. Semantic Views can be listed and described. In addition, you can list their metrics and dimensions. Lastly, you can query Semantic Views directly.

To enable these tools, set semantic_manager to True in the configuration file under other_services.

Troubleshooting