Skip to content

Snowflake-Labs/snowflake-cortex-agent-mcp-server

Repository files navigation

Snowflake Cortex Model Context Protocol (MCP) Server (Experimental)

This project implements a Model Context Protocol (MCP) server for seamless integration with Snowflake Cortex APIs. It enables developers to access Snowflake Cortex insights directly within their development environments, such as Visual Studio Code (VSCode).

If you do not have VSCode installed, you can download it here.

Install Snowflake Cortex Agent MCP Server

Important

  • Disclaimer: This project is experimental and intended for development and evaluation purposes only. It is not officially supported by Snowflake.
  • This is still a work in progress and may not be suitable for production use. Use at your own risk.

Prerequisites

DB Setup

Ensure you have Snowflake CLI installed and configured with your account details. Preferred to have user with ACCOUNTADMIN role to create the required database objects, before strip down to fine-grained access control for the MCP demo.

Create Database Objects

Important

Edit the scripts/data/support_tickets.yaml and update the KAMESH_MCP_DEMO to match your DB that you will be using for the demo i.e $SNOWFLAKE_MCP_DEMO_DATABASE.

Run the following SQL commands in your Snowflake account to create the necessary database objects:

./scripts/setup.sh

Programmatic Access Token

We will be using a programmatic access token to authenticate with the Snowflake Cortex APIs. You can create a token by following these steps:

./scripts/pat.sh

Verify if the programmatic access token is created successfully and working:

 snow connection test -x \
    --user "$SA_USER" \
    --role "$SNOWFLAKE_MCP_DEMO_ROLE"

Verify if the service user is able to access the database objects created in the previous step:

 curl --location \
   "https://$SNOWFLAKE_ACCOUNT.snowflakecomputing.com/api/v2/databases/$SNOWFLAKE_MCP_DEMO_DATABASE/schemas/data/cortex-search-services/invoice_search_service:query" \
   --header 'X-Snowflake-Authorization-Token-Type: PROGRAMMATIC_ACCESS_TOKEN' \
   --header 'Content-Type: application/json' --header 'Accept: application/json' \
   --header "Authorization: Bearer $SNOWFLAKE_PASSWORD" \
    --data '{ "query": "What kind of service does Gregory have?","columns": ["CHUNK",
                "FILE_NAME"],"limit": 1}'

Quick Start (Easy-way)

Click "Install Cortex Agent Server" badge

(OR)

Run the Snowflake Cortex MCP Server using Docker, follow these steps:

  1. Pull the Docker image:

    docker pull ghcr.io/kameshsampath/snowflake-cortex-mcp/server:latest
  2. Run the Docker container:

    There is a .env.template file in the repository that you can copy to .env and fill in the required values for your Snowflake account, user, password, warehouse, semantic model file, Cortex search service, and LLM model. This will help you avoid typing them directly in the command line.

    docker run -it --rm --name snowflake-cortex-agent \
      --env-file .env \
      ghcr.io/kameshsampath/snowflake-cortex-mcp/server:latest

    This command will start the Snowflake Cortex MCP Server in a Docker container, allowing you to interact with it using the Model Context Protocol.

MCP Client Configuration

Now from any MCP compatible client, such as VSCode or Claude Desktop, add the following MCP server configuration:

{
  "mcpServers": {
    "snowflake-cortex-agent": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "--name",
        "snowflake-cortex-agent",
        "-e",
        "SNOWFLAKE_ACCOUNT_URL",
        "-e",
        "SNOWFLAKE_USER",
        "-e",
        "SNOWFLAKE_PASSWORD",
        "-e",
        "SEMANTIC_MODEL_FILE",
        "-e",
        "CORTEX_SEARCH_SERVICE",
        "-e",
        "SNOWFLAKE_WAREHOUSE",
        "-e",
        "CORTEX_AGENT_LLM_MODEL",
        "ghcr.io/kameshsampath/snowflake-cortex-mcp/server:latest"
      ],
      "env": {
        "SNOWFLAKE_ACCOUNT_URL": "https://${input:snowflake_account}.snowflakecomputing.com",
        "SNOWFLAKE_USER": "${input:snowflake_user}",
        "SNOWFLAKE_PASSWORD": "${input:snowflake_password}",
        "SEMANTIC_MODEL_FILE": "${input:semantic_model_file}",
        "CORTEX_SEARCH_SERVICE": "${input:cortex_search_service}",
        "SNOWFLAKE_WAREHOUSE": "${input:snowflake_warehouse}",
        "CORTEX_AGENT_LLM_MODEL": "${input:cortex_agent_llm_model}"
      }
    }
  }
}

Tip

The repo already has one .vscode/mcp.json that helps you get started with the MCP server configuration in VSCode.

Building and Running Locally(Hard-way)

To build and run the Snowflake Cortex MCP Server locally using uv:

  1. Clone the repository:

    git clone https://github.com/kameshsampath/snowflake-cortex-mcp-server.git
    cd snowflake-cortex-mcp-server
  2. Create and activate a Python virtual environment:

    uv venv
    source .venv/bin/activate
  3. Install dependencies with uv:

    uv sync
  4. Set required environment variables:

    export SNOWFLAKE_ACCOUNT_URL="https://<your_account>.snowflakecomputing.com"
    export SNOWFLAKE_USER="<your_username>"
    export SNOWFLAKE_PASSWORD="<your_password>"
    export SNOWFLAKE_WAREHOUSE="<your_warehouse>"
    export SEMANTIC_MODEL_FILE="<stage_path_to_semantic_model>"
    export CORTEX_SEARCH_SERVICE="<cortex_search_service_name>"
    export CORTEX_AGENT_LLM_MODEL="<llm_model_name>"
  5. Run the MCP server:

    uv run snowflake_cortex_mcp_server

The server should now be running locally and ready to accept MCP requests.

References

About

A MCP Server to use Snowflake Cortex Agents

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages