A Model Context Protocol (MCP) server that provides MetricFlow CLI tools
Project description
mcp-metricflow
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.
Setup
# Install uv at https://docs.astral.sh/uv/getting-started/installation/
# Copy environment template
cp .env.template .env
# ...and then jump to # Configuration section to fulfill it
Configuration
Edit the .env file with your specific configuration:
# Required: Path to your dbt project
DBT_PROJECT_DIR=/path/to/your/dbt/project e.g. /Users/dat/repos/il/jaffle-shop
# Optional: Other configurations
DBT_PROFILES_DIR=/path/to/.dbt
MF_PATH=mf
MF_TMP_DIR=/path/to/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 โ
For integration with Claude Desktop (or any other MCP Client tool), use STDIO mode with the following uvx command:
uvx --env-file /path/to/.env --with "mcp-metricflow[snowflake]" mcp-metricflow
Sample .env file:
DBT_PROJECT_DIR=/Users/xxx/sources/jaffle-shop
DBT_PROFILES_DIR=/Users/xxx/.dbt
MF_TMP_DIR=/Users/xxx/.dbt/tmp
Add this configuration to the respective client's config file:
{
"mcpServers": {
"mcp-metricflow": {
"command": "uvx",
"args": [
"--env-file", "<path-to-.env-file>",
"--with", "mcp-metricflow[snowflake]",
"mcp-metricflow"
]
},
}
}
NOTE: Currently only support Snowflake with this extra dependency specified:
"--with", "mcp-metricflow[snowflake]"
NOTE: We might have to use absolute path for example:
/Users/xxx/.local/bin/uvxinstead ofuvxalone. Usewhich uvxto get the full path
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:
-
Set the required environment variables:
export MCP_API_KEY="your-secret-api-key" export MCP_REQUIRE_AUTH="true"
-
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 whenMCP_REQUIRE_AUTH=true)MCP_REQUIRE_AUTH: Enable/disable authentication (true,1,yes,onto enable; default:false)
Security Notes:
- The
/healthendpoint is always accessible without authentication for monitoring purposes - The
/sseendpoint requires authentication whenMCP_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
Contributing โจ
If you've ever wanted to contribute to this tool, and a great cause, now is your chance!
See the contributing docs CONTRIBUTING for more information.
If you've found this tool to be very helpful, please consider giving the repository a star, sharing it on social media, or even writing a blog post about it ๐
Finally, super thanks to our Contributors:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_metricflow-1.0.0.tar.gz.
File metadata
- Download URL: mcp_metricflow-1.0.0.tar.gz
- Upload date:
- Size: 39.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8b7687c40a60cd331a177359a30889683e24cab410bbbfcfb5654e2bedf17ee
|
|
| MD5 |
5b7504098833ff4ebad7a68599812fcb
|
|
| BLAKE2b-256 |
a36f4db63b0a348227e1eb6e2ff23e83a90efd912799e4b3c7684858159ef61a
|
Provenance
The following attestation bundles were made for mcp_metricflow-1.0.0.tar.gz:
Publisher:
pypi-publish.yml on datnguye/mcp-metricflow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_metricflow-1.0.0.tar.gz -
Subject digest:
c8b7687c40a60cd331a177359a30889683e24cab410bbbfcfb5654e2bedf17ee - Sigstore transparency entry: 322696612
- Sigstore integration time:
-
Permalink:
datnguye/mcp-metricflow@2f618fea983239a9bb1b94844cf911b7995fd7c4 -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/datnguye
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@2f618fea983239a9bb1b94844cf911b7995fd7c4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mcp_metricflow-1.0.0-py3-none-any.whl.
File metadata
- Download URL: mcp_metricflow-1.0.0-py3-none-any.whl
- Upload date:
- Size: 28.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f9a544b813a37893aff8ec82ac1f67f642e55df57073022bc9716aee8b031e0
|
|
| MD5 |
b425ac490e1bd85df5908b7ade990622
|
|
| BLAKE2b-256 |
615d2e69076a977abe4ae64227c44e178335a68162a7f9a4a5f53441f54a1486
|
Provenance
The following attestation bundles were made for mcp_metricflow-1.0.0-py3-none-any.whl:
Publisher:
pypi-publish.yml on datnguye/mcp-metricflow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_metricflow-1.0.0-py3-none-any.whl -
Subject digest:
7f9a544b813a37893aff8ec82ac1f67f642e55df57073022bc9716aee8b031e0 - Sigstore transparency entry: 322696624
- Sigstore integration time:
-
Permalink:
datnguye/mcp-metricflow@2f618fea983239a9bb1b94844cf911b7995fd7c4 -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/datnguye
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@2f618fea983239a9bb1b94844cf911b7995fd7c4 -
Trigger Event:
push
-
Statement type: