Snowflake MCP Server

Snowflake MCP Server

Enables Snowflake data operations through a Python FastAPI server with Prefect orchestration, deployable to Prefect Cloud.

Category
访问服务器

README

Snowflake MCP Server - Python/Prefect Version

A Python-based MCP server using FastAPI and Prefect for Snowflake data operations, deployable to Prefect Cloud.

🚀 Quick Start (Local Development)

Step 1: Install Python Dependencies

cd snowflake-mcp-server
pip install -r requirements.txt

Step 2: Configure Environment

Copy the example environment file:

cp .env.python.example .env

Edit .env with your Snowflake credentials:

SNOWFLAKE_ACCOUNT=your-account-identifier
SNOWFLAKE_USERNAME=your-username
SNOWFLAKE_PASSWORD=your-password
SNOWFLAKE_WAREHOUSE=COMPUTE_WH
SNOWFLAKE_DATABASE=TELECOM_ANALYTICS
SNOWFLAKE_ROLE=your-role
PORT=3000

Step 3: Run the Server Locally

python server.py

You should see:

🚀 Snowflake MCP Server (Python/Prefect) is starting!
   Local:    http://localhost:3000
   Health:   http://localhost:3000/health

Step 4: Test the Server

# Test health check
curl http://localhost:3000/health

# Test schemas
curl http://localhost:3000/mcp/schemas

# Test customers data
curl http://localhost:3000/mcp/customers

☁️ Deploy to Prefect Cloud

Prerequisites

  1. Prefect Cloud Account: Sign up at https://app.prefect.cloud/
  2. Prefect CLI: Already included in requirements.txt
  3. API Key: Get from Prefect Cloud settings

Step 1: Authenticate with Prefect Cloud

# Login to Prefect Cloud
prefect cloud login

# Or set API key directly
prefect config set PREFECT_API_KEY=your-api-key
prefect config set PREFECT_API_URL=https://api.prefect.cloud/api/accounts/[ACCOUNT_ID]/workspaces/[WORKSPACE_ID]

Step 2: Create Prefect Blocks for Secrets

Store your Snowflake credentials as Prefect Secret blocks:

# Create secrets in Prefect Cloud
prefect block register -m prefect.blocks.system

# Create each secret (you can also do this via Prefect Cloud UI)
python -c "
from prefect.blocks.system import Secret

Secret(value='your-account-identifier').save('snowflake-account')
Secret(value='your-username').save('snowflake-username')
Secret(value='your-password').save('snowflake-password')
Secret(value='COMPUTE_WH').save('snowflake-warehouse')
Secret(value='TELECOM_ANALYTICS').save('snowflake-database')
Secret(value='your-role').save('snowflake-role')
"

OR create secrets via Prefect Cloud UI:

  1. Go to https://app.prefect.cloud/
  2. Navigate to Blocks+Secret
  3. Create blocks named:
    • snowflake-account
    • snowflake-username
    • snowflake-password
    • snowflake-warehouse
    • snowflake-database
    • snowflake-role

Step 3: Deploy Flows to Prefect Cloud

# Deploy all flows
python deployment.py

This will deploy all Prefect flows to your Prefect Cloud workspace.

Step 4: Start a Prefect Agent

You need an agent running to execute the flows:

# Start an agent (keep this running)
prefect agent start -q default

For production, run the agent as a service or in a container.

Step 5: Run Flows from Prefect Cloud

Now you can trigger flows from:

  • Prefect Cloud UI: https://app.prefect.cloud/
  • API calls: Use Prefect's REST API
  • Scheduled runs: Configure in prefect.yaml

🌐 Alternative: Deploy as Web Service

If you want to deploy the FastAPI server (not just Prefect flows), use these platforms:

Option 1: Railway

# Install Railway CLI
npm install -g @railway/cli

# Login and deploy
railway login
railway init
railway up

Add environment variables in Railway dashboard.

Option 2: Render

  1. Create a new Web Service on https://render.com/
  2. Connect your GitHub repository
  3. Set build command: pip install -r requirements.txt
  4. Set start command: python server.py
  5. Add environment variables in Render dashboard

Option 3: Google Cloud Run

# Build and deploy
gcloud run deploy snowflake-mcp-server \
  --source . \
  --platform managed \
  --region us-central1 \
  --allow-unauthenticated

Option 4: AWS App Runner

  1. Create a Dockerfile:
FROM python:3.11-slim

WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 3000
CMD ["python", "server.py"]
  1. Deploy via AWS App Runner console

📋 Available Endpoints

Health Check

GET /health

List Schemas

GET /mcp/schemas

List Tables

GET /mcp/tables/{schema}

Execute Query

POST /mcp/query
Content-Type: application/json

{
  "query": "SELECT * FROM CUSTOMER_DATA.CUSTOMERS LIMIT 10"
}

Get Customers

GET /mcp/customers

Get Service Tickets

GET /mcp/tickets

Get Usage Metrics

GET /mcp/usage

Get Billing History

GET /mcp/billing

Get All Data

GET /mcp/all

🔧 Prefect Flow Management

View Flows

# List all flows
prefect flow ls

# View flow runs
prefect flow-run ls

Trigger a Flow Manually

# Run a specific flow
prefect deployment run 'get-customers-flow/get-customers'

Monitor Flows

Visit your Prefect Cloud dashboard:

  • Flow Runs: See all executions
  • Logs: View detailed logs
  • Metrics: Monitor performance

🔒 Security Best Practices

For Production:

  1. Use Prefect Secret Blocks: Never hardcode credentials
  2. Enable HTTPS: Use reverse proxy (nginx, Caddy)
  3. Add Authentication: Implement API keys or OAuth
  4. Rate Limiting: Add rate limiting middleware
  5. IP Whitelisting: Restrict access to known IPs
  6. Rotate Credentials: Change passwords regularly

Example: Add API Key Authentication

# Add to server.py
from fastapi import Header, HTTPException

API_KEY = os.getenv("API_KEY")

async def verify_api_key(x_api_key: str = Header(...)):
    if x_api_key != API_KEY:
        raise HTTPException(status_code=401, detail="Invalid API Key")
    return x_api_key

# Add to endpoints
@app.get("/mcp/customers", dependencies=[Depends(verify_api_key)])
async def get_customers():
    ...

🐛 Troubleshooting

Error: "Import prefect could not be resolved"

Solution: Install dependencies

pip install -r requirements.txt

Error: "Unable to connect to Snowflake"

Solution: Check credentials and network

# Test Snowflake connection
python -c "
import snowflake.connector
conn = snowflake.connector.connect(
    account='your-account',
    user='your-user',
    password='your-password'
)
print('✅ Connected!')
"

Error: "Prefect API authentication failed"

Solution: Re-authenticate

prefect cloud login

Error: "No agent available"

Solution: Start a Prefect agent

prefect agent start -q default

📊 Differences from Node.js Version

Feature Node.js Version Python Version
Framework Express FastAPI
Orchestration None Prefect
Deployment Manual Prefect Cloud
Type Safety JavaScript Python + Pydantic
Async Support Callbacks async/await
Monitoring Manual Prefect Dashboard

🎯 Next Steps

  1. Deploy to Prefect Cloud: Follow deployment steps above
  2. Set up monitoring: Use Prefect Cloud dashboard
  3. Configure schedules: Edit prefect.yaml for automated runs
  4. Add more flows: Create custom Prefect flows for your use case
  5. Integrate with ICA: Connect to IBM ICA Context Studio

📝 Files Overview

  • server.py: Main FastAPI application with Prefect flows
  • requirements.txt: Python dependencies
  • deployment.py: Prefect deployment script
  • prefect.yaml: Prefect configuration
  • .env.python.example: Environment variables template
  • README_PYTHON.md: This file

🆘 Support

For issues:

  1. Check Prefect Cloud logs
  2. Review server logs: python server.py
  3. Test Snowflake connection
  4. Verify environment variables

Version: 2.0.0 (Python/Prefect)
Last Updated: 2026-06-02
Framework: FastAPI + Prefect
Deployment Target: Prefect Cloud

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选