datnguye/mcp-metricflow
If you are the rightful owner of mcp-metricflow and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The mcp-metricflow project is a Model Context Protocol (MCP) server that integrates MetricFlow CLI tools, providing access through SSE and STDIO interfaces.
query
Execute MetricFlow queries with various parameters.
list_metrics
List available metrics in the system.
list_dimensions
List available dimensions for metrics.
list_entities
List available entities related to metrics.
list_dimension_values
List values for a specific dimension.
validate_configs
Validate model configurations for correctness.
health_checks
Perform system health checks to ensure stability.
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=~/.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
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 mcp-metricflow
Add this configuration to the respective client's config file:
{
"mcpServers": {
"mcp-metricflow": {
"command": "uvx",
"args": [
"--env-file",
"<path-to-.env-file>",
"mcp-metricflow"
]
},
}
}
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
,on
to enable; default:false
)
Security Notes:
- The
/health
endpoint is always accessible without authentication for monitoring purposes - The
/sse
endpoint 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 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:
TODO
- Test STDIO mode