metabase-mcp

metabase-mcp

Enables AI assistants to interact with Metabase for querying databases, executing SQL, managing dashboards, and automating analytics workflows.

Category
访问服务器

README

Metabase MCP Server - Connect AI Assistants to Your Metabase Analytics

PyPI version Python 3.12+ License: MIT FastMCP

A high-performance Model Context Protocol (MCP) server for Metabase, enabling AI assistants like Claude, Cursor, and other MCP clients to interact seamlessly with your Metabase instance. Query databases, execute SQL, manage dashboards, and automate analytics workflows with natural language through AI-powered database operations.

Perfect for: Data analysts, developers, and teams looking to integrate AI assistants with their Metabase business intelligence platform for automated SQL queries, dashboard management, and data exploration.

Key Features

Database Operations

  • List Databases: Browse all configured Metabase databases
  • Table Discovery: Explore tables with metadata and descriptions
  • Field Inspection: Get detailed field/column information with smart pagination

Query & Analytics

  • SQL Execution: Run native SQL queries with parameter support and templating
  • MongoDB Support: Execute native MongoDB queries with automatic JSON conversion for aggregation pipelines
  • Card Management: Execute, create, and manage Metabase questions/cards (SQL and MongoDB)
  • Collection Organization: Create and manage collections for better organization
  • Natural Language Queries: Let AI assistants translate questions into SQL or MongoDB queries

Authentication & Security

  • API Key Support: Secure authentication via Metabase API keys (recommended)
  • Session-based Auth: Alternative email/password authentication
  • Environment Variables: Secure credential management via .env files

AI Assistant Integration

  • Claude Desktop: Native integration with Anthropic's Claude AI
  • Cursor IDE: Seamless integration for AI-assisted development
  • Any MCP Client: Compatible with all Model Context Protocol clients

Enhanced Performance & Reliability

  • Context-aware Logging: Real-time logging with debug, info, warning, and error levels visible to AI clients
  • Proper Error Handling: FastMCP ToolError exceptions for better error messages and debugging
  • Middleware Stack: Built-in error handling and logging middleware for production reliability
  • Best Practices: Follows latest FastMCP patterns with duplicate prevention and clean configuration
  • Modern Python: Uses Python 3.12+ type hints (| syntax) for better type safety

Quick Start

Prerequisites

  • Python 3.12+
  • Metabase instance with API access
  • uvx or uv package manager

Installation

Option 1: Using uvx (Easiest - No Installation Required)

# Run directly without installing (like npx for Python)
uvx metabase-mcp

# With environment variables
METABASE_URL=https://your-instance.com METABASE_API_KEY=your-key uvx metabase-mcp

Option 2: Install from PyPI

# Install globally
uv tool install metabase-mcp

# Or with pip
pip install metabase-mcp

# Then run
metabase-mcp

Option 3: Development Setup (From Source)

# Clone the repository
git clone https://github.com/cheukyin175/metabase-mcp.git
cd metabase-mcp

# Install dependencies
uv sync

# Run the server
uv run python server.py

Configuration

Create a .env file with your Metabase credentials:

cp .env.example .env

Configuration Options

Option 1: API Key Authentication (Recommended)

METABASE_URL=https://your-metabase-instance.com
METABASE_API_KEY=your-api-key-here

Option 2: Email/Password Authentication

METABASE_URL=https://your-metabase-instance.com
METABASE_USER_EMAIL=your-email@example.com
METABASE_PASSWORD=your-password

Optional: Metabase API HTTP Timeout

METABASE_HTTP_TIMEOUT=30.0  # Default: 30.0 seconds

Optional: Custom Host/Port for SSE/HTTP

HOST=localhost  # Default: 0.0.0.0
PORT=9000      # Default: 8000

Usage

Run the Server

Quick Start (No Setup Required)

# Run directly with uvx
uvx metabase-mcp

# With custom Metabase instance
METABASE_URL=https://your-instance.com METABASE_API_KEY=your-key uvx metabase-mcp

From Source (Development)

# STDIO transport (default)
uv run python server.py

# SSE transport (uses HOST=0.0.0.0, PORT=8000 by default)
uv run python server.py --sse

# HTTP transport (uses HOST=0.0.0.0, PORT=8000 by default)
uv run python server.py --http

# Custom host and port via environment variables
HOST=localhost PORT=9000 uv run python server.py --sse
HOST=192.168.1.100 PORT=8080 uv run python server.py --http

Cursor Integration

You can manually configure Cursor by editing your Cursor settings.

For SSE transport: You must start the server before using Cursor:

uv run python server.py --sse

Claude Desktop Integration

Option 1: Using uvx (Recommended)

Add this to ~/Library/Application Support/Claude/claude_desktop_config.json:

{
    "mcpServers": {
        "metabase-mcp": {
            "command": "uvx",
            "args": ["metabase-mcp"],
            "env": {
                "METABASE_URL": "https://your-metabase-instance.com",
                "METABASE_API_KEY": "your-api-key-here"
            }
        }
    }
}

Option 2: Using Local Installation

If you've cloned the repository:

{
    "mcpServers": {
        "metabase-mcp": {
            "command": "uv",
            "args": [
                "run",
                "--directory",
                "/absolute/path/to/metabase-mcp",
                "python",
                "server.py"
            ],
            "env": {
                "METABASE_URL": "https://your-metabase-instance.com",
                "METABASE_API_KEY": "your-api-key-here"
            }
        }
    }
}

Option 3: Using FastMCP CLI

fastmcp install server.py -n "Metabase MCP"

Available Tools

Database Operations

Tool Description
list_databases List all configured databases in Metabase
list_tables Get all tables in a specific database with metadata
get_table_fields Retrieve field/column information for a table

Query Operations

Tool Description
execute_query Execute native SQL queries with parameter support
execute_mongodb_query Execute native MongoDB queries with automatic JSON conversion for aggregation pipelines
execute_card Run saved Metabase questions/cards

Card Management

Tool Description
list_cards List all saved questions/cards
create_card Create new questions/cards with SQL queries
create_mongodb_card Create new MongoDB questions/cards with native query support

Collection Management

Tool Description
list_collections Browse all collections
create_collection Create new collections for organization

Transport Methods

The server supports multiple transport methods:

  • STDIO (default): For IDE integration (Cursor, Claude Desktop)
  • SSE: Server-Sent Events for web applications
  • HTTP: Standard HTTP for API access
uv run python server.py                        # STDIO (default)
uv run python server.py --sse                  # SSE (HOST=0.0.0.0, PORT=8000)
uv run python server.py --http                 # HTTP (HOST=0.0.0.0, PORT=8000)
HOST=localhost PORT=9000 uv run python server.py --sse   # Custom host/port

Development

Setup Development Environment

# Install with dev dependencies
uv sync --group dev

# Or with pip
pip install -r requirements-dev.txt

Code Quality

# Run linting
uv run ruff check .

# Format code
uv run ruff format .

# Type checking
uv run mypy server.py

Usage Examples

Query Examples

# List all databases
databases = await list_databases()

# Execute a SQL query
result = await execute_query(
    database_id=1,
    query="SELECT * FROM users LIMIT 10"
)

# Create and run a card
card = await create_card(
    name="Active Users Report",
    database_id=1,
    query="SELECT COUNT(*) FROM users WHERE active = true",
    collection_id=2
)

Project Structure

metabase-mcp/
├── server.py                 # Main MCP server implementation
├── pyproject.toml           # Project configuration and dependencies
└── .env.example             # Environment variables template

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE file for details

Resources

Keywords & Topics

metabase mcp model-context-protocol claude cursor ai-assistant fastmcp sql database analytics business-intelligence bi data-analysis anthropic llm python automation api data-science query-builder natural-language-sql

Star History

If you find this project useful, please consider giving it a star! It helps others discover this tool.

Use Cases

  • Natural Language Database Queries: Ask Claude to query your Metabase databases using plain English
  • Automated Report Generation: Use AI to create and manage Metabase cards and collections
  • Data Exploration: Let AI assistants help you discover insights from your data
  • SQL Query Assistance: Get help writing and optimizing SQL queries through AI
  • Dashboard Management: Automate the creation and organization of Metabase dashboards
  • Data Analysis Workflows: Integrate AI-powered analytics into your development workflow

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选