docs/docs/genai/mcp/index.mdx
import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem";
:::info
:::
The MLflow Model Context Protocol (MCP) server enables AI applications and coding assistants to interact with MLflow traces programmatically. MCP is an open protocol that provides a standardized way for AI tools like Claude, VS Code extensions, and other language models to access external data sources and tools.
The MLflow MCP server exposes all MLflow trace management operations through the MCP protocol, allowing AI assistants to:
This integration makes it easy to incorporate MLflow tracing capabilities into AI-powered development workflows, enabling more intelligent analysis and management of your LLM applications and AI agents.
To use the MLflow MCP server, install MLflow with the mcp extra:
pip install 'mlflow[mcp]>=3.5.1'
Configure the MLflow MCP server in your MCP client by adding the server configuration to your client's settings file:
<Tabs> <TabItem label="VS Code" value="vscode">Add to your VS Code configuration file (.vscode/mcp.json):
{
"servers": {
"mlflow-mcp": {
"command": "uv",
"args": ["run", "--with", "mlflow[mcp]>=3.5.1", "mlflow", "mcp", "run"],
"env": {
"MLFLOW_TRACKING_URI": "<MLFLOW_TRACKING_URI>"
}
}
}
}
Add to your Cursor configuration file (.cursor/mcp.json):
{
"mcpServers": {
"mlflow-mcp": {
"command": "uv",
"args": ["run", "--with", "mlflow[mcp]>=3.5.1", "mlflow", "mcp", "run"],
"env": {
"MLFLOW_TRACKING_URI": "<MLFLOW_TRACKING_URI>"
}
}
}
}
Option 1 - claude mcp add CLI (recommended):
claude mcp add mlflow-mcp -e MLFLOW_TRACKING_URI=<MLFLOW_TRACKING_URI> \
-- uv run --with "mlflow[mcp]>=3.5.1" mlflow mcp run
Option 2 - .mcp.json at the project root (shareable via version control):
{
"mcpServers": {
"mlflow-mcp": {
"command": "uv",
"args": ["run", "--with", "mlflow[mcp]>=3.5.1", "mlflow", "mcp", "run"],
"env": {
"MLFLOW_TRACKING_URI": "<MLFLOW_TRACKING_URI>"
}
}
}
}
Replace <MLFLOW_TRACKING_URI> with your MLflow tracking server URL:
http://localhost:5000https://your-mlflow-server.comdatabricks and configure authentication using environment variables such as DATABRICKS_HOST and DATABRICKS_TOKEN. For detailed setup instructions, refer to the Databricks authentication guide.The MLflow MCP server provides comprehensive trace management capabilities:
| Tool | Description | Key Parameters |
|---|---|---|
search_traces | Search and filter traces in experiments | experiment_id, filter_string, max_results, extract_fields |
get_trace | Get detailed trace information | trace_id, extract_fields |
delete_traces | Delete traces by ID or timestamp | experiment_id, trace_ids, max_timestamp_millis |
set_trace_tag | Add custom tags to traces | trace_id, key, value |
delete_trace_tag | Remove tags from traces | trace_id, key |
log_feedback | Log evaluation scores or judgments | trace_id, name, value, source_type, rationale |
log_expectation | Log ground truth labels | trace_id, name, value, source_type |
get_assessment | Retrieve assessment details | trace_id, assessment_id |
update_assessment | Modify existing assessments | trace_id, assessment_id, value, rationale |
delete_assessment | Remove assessments | trace_id, assessment_id |
The MCP server supports sophisticated field selection through the extract_fields parameter, available in both search_traces and get_trace tools. This parameter accepts comma-separated field paths using dot notation, allowing you to retrieve only the data you need, reducing response size and improving performance. The extract_fields parameter lets you:
*) to select all items in arrays or objectsExample usage with tools:
# With search_traces
search_traces(
experiment_id="1",
extract_fields="info.trace_id,info.state,data.spans.*.name",
)
# With get_trace
get_trace(
trace_id="tr-abc123",
extract_fields="info.assessments.*,info.tags.*",
)
Trace Information:
info.trace_id: Unique trace identifierinfo.state: Trace statusinfo.execution_duration: Total execution timeinfo.request_preview: Truncated request previewinfo.response_preview: Truncated response previewTags and Metadata:
info.tags.*: All trace tagsinfo.tags.mlflow.traceName: Trace nameinfo.trace_metadata.*: Custom metadata fieldsAssessments:
info.assessments.*: All assessment datainfo.assessments.*.feedback.value: Feedback scoresinfo.assessments.*.source.source_type: Assessment sourcesSpan Data:
data.spans.*: All span informationdata.spans.*.name: Span operation namesdata.spans.*.attributes.mlflow.spanType: Span types (AGENT, TOOL, LLM)# Get basic trace info
info.trace_id,info.state,info.execution_duration
# Get all assessments
info.assessments.*
# Get feedback values only
info.assessments.*.feedback.value
# Get span names
data.spans.*.name
# Get trace name (use backticks for dots in field names)
info.tags.`mlflow.traceName`
Use the MCP server to quickly identify problematic traces:
User: Find all failed traces in experiment 1 from the last hour
Agent: Uses `search_traces` with `filter_string="status='ERROR' AND timestamp_ms > [recent_timestamp]"`
Analyze execution patterns and bottlenecks:
User: Show me the slowest traces in experiment 2 with execution times over 5 seconds
Agent: Uses `search_traces` with `filter_string="execution_time_ms > 5000"` and `order_by="execution_time_ms DESC"`
Log and manage trace evaluations:
User: Log a relevance score of 0.85 for trace tr-abc123 with rationale about accuracy
Agent: Uses `log_feedback` with appropriate parameters
Remove old or test traces:
User: Delete traces older than 30 days from experiment 1
Agent: Uses `delete_traces` with timestamp-based filtering
The MCP server respects standard MLflow environment variables:
MLFLOW_TRACKING_URI: MLflow tracking server URLMLFLOW_EXPERIMENT_ID: Default experiment IDMLFLOW_MCP_TOOLS: Controls which tool categories are enabled (see below)For Databricks environments, ensure you have appropriate authentication configured (personal access tokens, service principals, etc.).
The MLFLOW_MCP_TOOLS environment variable controls which tools are exposed by the MCP server. This is useful for limiting the number of tools available to your AI assistant, which can improve performance and reduce token usage.
Supported values:
| Value | Description | Tools Included |
|---|---|---|
genai (default) | GenAI-focused tools for tracing and evaluation | traces, scorers, experiments, runs |
ml | Traditional ML workflow tools | experiments, runs, models, deployments |
all | All available tools | All of the above |
You can also specify a comma-separated list of individual tool categories:
# Enable only specific categories
export MLFLOW_MCP_TOOLS="traces,scorers,experiments"
Example configuration with tool categories:
{
"mcpServers": {
"mlflow-mcp": {
"command": "uv",
"args": ["run", "--with", "mlflow[mcp]>=3.5.1", "mlflow", "mcp", "run"],
"env": {
"MLFLOW_TRACKING_URI": "<MLFLOW_TRACKING_URI>",
"MLFLOW_MCP_TOOLS": "all"
}
}
}
}