Skip to main content

A Model Context Protocol (MCP) server that provides MetricFlow CLI tools

Project description

mcp-metricflow

Python License Coverage Code style: ruff Package manager: uv

A Model Context Protocol (MCP) server that provides MetricFlow CLI tools through both SSE (with optional API key authentication) and STDIO interfaces.

[!WARNING] This repository is a learning project focused on MetricFlow integration with MCP. For production use cases, please refer to the official dbt-mcp implementation by dbt Labs.

Table of Contents

Overview

This project provides a Model Context Protocol (MCP) server that wraps MetricFlow CLI commands, making them accessible through both Server-Sent Events (SSE) and Standard Input/Output (STDIO) interfaces. It enables seamless integration with Claude Desktop and other MCP-compatible clients.

Installation

# Clone the repository
git clone https://github.com/datnguye/mcp-metricflow.git
cd mcp-metricflow

# Install dependencies
uv sync

# Copy environment template
cp .env.template .env

Configuration

Edit the .env file with your specific configuration:

# Required: Path to your dbt project
DBT_PROJECT_DIR=/path/to/your/dbt/project

# Optional: Other configurations
DBT_PROFILES_DIR=~/.dbt
MF_PATH=mf
MF_TMP_DIR=/tmp

# SSE server configuration (optional)
MCP_HOST=localhost
MCP_PORT=8000

# API key authentication for SSE mode (optional)
MCP_API_KEY=your-secret-api-key
MCP_REQUIRE_AUTH=false

Running the MCP Server

STDIO Mode (Claude Desktop)

For integration with Claude Desktop, use STDIO mode:

uv run python src/main_stdio.py

Claude Desktop Configuration

Add this to your Claude Desktop MCP configuration:

{
  "mcpServers": {
    "metricflow": {
      "command": "uv",
      "args": ["run", "python", "/path/to/mcp-metricflow/src/main_stdio.py"],
      "cwd": "/path/to/mcp-metricflow",
      "env": {
        "DBT_PROJECT_DIR": "/path/to/your/dbt/project",
        "DBT_PROFILES_DIR": "~/.dbt",
        "MF_PATH": "mf"
      }
    }
  }
}

SSE Mode

For web-based integration or direct HTTP access:

# export DBT_PROFILES_DIR=~/.dbt
uv run python src/main_sse.py

The server will start on http://localhost:8000 (or the host/port specified in your environment variables).

API Key Authentication

The SSE server supports optional API key authentication. To enable authentication:

  1. Set the required environment variables:

    export MCP_API_KEY="your-secret-api-key"
    export MCP_REQUIRE_AUTH="true"
    
  2. Access authenticated endpoints by including the API key in the Authorization header:

    # Health check (no authentication required)
    curl http://localhost:8000/health
    
    # SSE endpoint (requires authentication when enabled)
    curl -H "Authorization: Bearer your-secret-api-key" http://localhost:8000/sse
    

Authentication Configuration:

  • MCP_API_KEY: The secret API key for authentication (required when MCP_REQUIRE_AUTH=true)
  • MCP_REQUIRE_AUTH: Enable/disable authentication (true, 1, yes, on to enable; default: false)

Security Notes:

  • The /health endpoint is always accessible without authentication for monitoring purposes
  • The /sse endpoint requires authentication when MCP_REQUIRE_AUTH=true
  • API keys are case-sensitive and support special characters
  • Store API keys securely and avoid committing them to version control

Available Tools

The MCP server exposes the following MetricFlow CLI tools:

Tool Description Required Parameters Optional Parameters
query Execute MetricFlow queries session_id, metrics group_by, start_time, end_time, where, order, limit, saved_query, explain, show_dataflow_plan, show_sql_descriptions
list_metrics List available metrics None search, show_all_dimensions
list_dimensions List available dimensions None metrics
list_entities List available entities None metrics
list_dimension_values List values for a dimension dimension, metrics start_time, end_time
validate_configs Validate model configurations None dw_timeout, skip_dw, show_all, verbose_issues, semantic_validation_workers
health_checks Perform system health checks None None

Each tool includes comprehensive documentation accessible through the MCP interface.

Project Structure

src/
├── config/
│   └── config.py              # Configuration management
├── server/
│   ├── auth.py                # API key authentication
│   ├── sse_server.py          # SSE server implementation
│   └── stdio_server.py        # STDIO server implementation
├── tools/
│   ├── prompts/mf_cli/        # Tool documentation (*.md files)
│   ├── metricflow/            # MetricFlow CLI wrappers
│   │   ├── base.py            # Shared command execution
│   │   ├── query.py           # Query functionality
│   │   ├── list_metrics.py    # List metrics
│   │   ├── list_dimensions.py # List dimensions
│   │   ├── list_entities.py   # List entities
│   │   ├── list_dimension_values.py # List dimension values
│   │   ├── validate_configs.py # Configuration validation
│   │   └── health_checks.py   # Health checks
│   └── cli_tools.py           # MCP tool registration
├── utils/
│   ├── logger.py              # Logging configuration
│   └── prompts.py             # Prompt loading utilities
├── main_sse.py                # SSE server entry point
└── main_stdio.py              # STDIO server entry point

Development

Code Quality

The project uses ruff for code formatting and linting:

# Format code
uv run ruff format

# Check code quality
uv run ruff check .

TODO

  • Test STDIO mode

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_metricflow-1.0.0b3.tar.gz (35.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_metricflow-1.0.0b3-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file mcp_metricflow-1.0.0b3.tar.gz.

File metadata

  • Download URL: mcp_metricflow-1.0.0b3.tar.gz
  • Upload date:
  • Size: 35.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mcp_metricflow-1.0.0b3.tar.gz
Algorithm Hash digest
SHA256 233f8473c2750cd5a510ab5f40b5a9f35dc9a2a0669bcdc720d8ac59230b1187
MD5 77d0458fce70bf037e6d01253eb3a055
BLAKE2b-256 63e537fce6a1d9ac362b067ceb8c142aef971108352ecead486201cd6424c6a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_metricflow-1.0.0b3.tar.gz:

Publisher: pypi-publish.yml on datnguye/mcp-metricflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mcp_metricflow-1.0.0b3-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_metricflow-1.0.0b3-py3-none-any.whl
Algorithm Hash digest
SHA256 449999084d1a25ff7a0edaca86a13c95c6e91fb8d1cef30fe83b64d00d3e94b7
MD5 a6eb882dae0bff50054520d4e5c5ee5d
BLAKE2b-256 cfffaf513e59c377a8f4ce4a8db509dee83164d596b908b084a4adbab683fa64

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_metricflow-1.0.0b3-py3-none-any.whl:

Publisher: pypi-publish.yml on datnguye/mcp-metricflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page