Skip to main content

MCP (Model Context Protocol) server support for trackio experiment tracking

Project description

trackio-mcp

MCP (Model Context Protocol) server support for trackio experiment tracking

This package enables AI agents to observe and interact with trackio experiments through the Model Context Protocol (MCP). Simply import trackio_mcp before trackio to automatically enable MCP server functionality.

Features

  • Zero-code integration: Just import trackio_mcp before trackio
  • Automatic MCP server: Enables MCP server on all trackio deployments (local & Spaces)
  • Rich tool set: Exposes trackio functionality as MCP tools for AI agents
  • Spaces compatible: Works seamlessly with Hugging Face Spaces deployments
  • Drop-in replacement: No changes needed to existing trackio code

Installation

pip install trackio-mcp

Or with development dependencies:

pip install trackio-mcp[dev]

Quick Start

Basic Usage

Simply import trackio_mcp before importing trackio:

import trackio_mcp  # This enables MCP server functionality
import trackio as wandb

# Your existing trackio code works unchanged
wandb.init(project="my-experiment")
wandb.log({"loss": 0.1, "accuracy": 0.95})
wandb.finish()

The MCP server will be automatically available at:

  • Local: http://localhost:7860/gradio_api/mcp/sse
  • Spaces: https://your-space.hf.space/gradio_api/mcp/sse

Deploy to Hugging Face Spaces with MCP

import trackio_mcp
import trackio as wandb

# Deploy to Spaces with MCP enabled automatically
wandb.init(
    project="my-experiment", 
    space_id="username/my-trackio-space"
)

wandb.log({"loss": 0.1})
wandb.finish()

Standalone MCP Server

Launch a dedicated MCP server for trackio tools:

from trackio_mcp.tools import launch_trackio_mcp_server

# Launch standalone MCP server on port 7861
launch_trackio_mcp_server(port=7861, share=False)

MCP Client Configuration

Claude Desktop & Gemini CLI & Claude Code

These clients use similar JSON configuration structures with mcpServers:

Claude Desktop

Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or equivalent:

{
  "mcpServers": {
    "trackio": {
      "url": "http://localhost:7860/gradio_api/mcp/sse"
    }
  }
}

Gemini CLI

Add to mcp.json in your project directory:

{
  "mcpServers": {
    "trackio": {
      "command": "npx",
      "args": ["mcp-remote", "http://localhost:7860/gradio_api/mcp/sse"]
    }
  }
}

Claude Code

Add to ~/.claude.json:

{
  "mcpServers": {
    "trackio": {
      "type": "sse",
      "url": "http://localhost:7860/gradio_api/mcp/sse"
    }
  }
}

For Hugging Face Spaces, replace the URL:

{
  "mcpServers": {
    "trackio": {
      "url": "https://your-space.hf.space/gradio_api/mcp/sse"
    }
  }
}

For private Spaces, add authentication:

{
  "mcpServers": {
    "trackio": {
      "url": "https://your-space.hf.space/gradio_api/mcp/sse",
      "headers": {
        "Authorization": "Bearer YOUR_HF_TOKEN"
      }
    }
  }
}

Cursor/Windsurf/Cline

Create .cursor/mcp.json (or equivalent for your IDE):

{
  "mcpServers": {
    "trackio": {
      "command": "npx",
      "args": [
        "mcp-remote", 
        "http://localhost:7860/gradio_api/mcp/sse"
      ]
    }
  }
}

For SSE direct support:

{
  "mcpServers": {
    "trackio": {
      "url": "http://localhost:7860/gradio_api/mcp/sse"
    }
  }
}

VS Code

For VS Code with Copilot, add to .vscode/mcp.json:

{
  "mcpServers": {
    "trackio": {
      "command": "npx",
      "args": ["mcp-remote", "http://localhost:7860/gradio_api/mcp/sse"]
    }
  }
}

Available MCP Tools

Once connected, AI agents can use these trackio tools:

Core Tools (via Gradio API)

  • log: Log metrics to a trackio run
  • upload_db_to_space: Upload local database to a Space

Extended Tools (via trackio-mcp)

  • get_projects: List all trackio projects
  • get_runs: Get runs for a specific project
  • filter_runs: Filter runs by name pattern
  • get_run_metrics: Get metrics data for a specific run
  • get_available_metrics: Get all available metric names for a project
  • load_run_data: Load and process run data with optional smoothing
  • get_project_summary: Get comprehensive project statistics

Example Agent Interaction

Human: "Show me the latest results from my 'image-classification' project"

Agent: I'll check your trackio projects and get the latest results.

[Tool: get_projects] → finds "image-classification" project
[Tool: get_runs] → gets runs for "image-classification" 
[Tool: get_run_metrics] → gets metrics for latest run
[Tool: get_available_metrics] → gets metric names

Agent: Your latest image-classification run achieved 94.2% accuracy with a final loss of 0.18. The model trained for 50 epochs with best validation accuracy of 94.7% at epoch 45.

Configuration

Environment Variables

  • TRACKIO_ENABLE_MCP: Set to "false" to disable MCP functionality (default: "true")
  • GRADIO_MCP_SERVER: Alternative way to enable MCP server
  • TRACKIO_MCP_ENABLED: Set automatically when MCP is enabled

Programmatic Control

import os
os.environ["TRACKIO_ENABLE_MCP"] = "false"  # Disable MCP
import trackio_mcp  # MCP won't be enabled
import trackio

How It Works

trackio-mcp uses monkey-patching to automatically:

  1. Enable MCP server: Sets mcp_server=True on all Gradio launches
  2. Enable API: Sets show_api=True to expose Gradio API endpoints
  3. Add tools: Registers additional trackio-specific MCP tools
  4. Preserve compatibility: No changes needed to existing trackio code

The package patches:

  • gradio.Blocks.launch() - Core Gradio launch method
  • trackio.ui.demo.launch() - Trackio dashboard launches
  • Adds new MCP endpoints at /gradio_api/mcp/sse

Deployment Examples

Local Development

import trackio_mcp
import trackio

# Start local tracking with MCP enabled
trackio.show()  # Dashboard + MCP server at http://localhost:7860

Production Spaces Deployment

import trackio_mcp
import trackio as wandb

# Deploy to production with MCP support
wandb.init(
    project="production-model",
    space_id="company/model-tracking",
    dataset_id="company/model-metrics"  # Persistent storage
)

# Your training loop
for epoch in range(100):
    wandb.log({"epoch": epoch, "loss": loss, "accuracy": acc})

wandb.finish()

CLI Interface

# Launch standalone MCP server
trackio-mcp server --port 7861

# Check status and configuration
trackio-mcp status

# Test MCP server functionality
trackio-mcp test --url http://localhost:7860

Security Considerations

  • Private Spaces: Use HF tokens for authentication
  • Access Control: MCP server inherits trackio's access controls
  • Network Security: Consider firewall rules for production deployments
  • Token Management: Store HF tokens securely, use environment variables

Troubleshooting

MCP Server Not Available

import trackio_mcp
import trackio

# Check if MCP was enabled
import os
print("MCP Enabled:", os.getenv("TRACKIO_MCP_ENABLED"))

# Manual verification
trackio.show()  # Look for MCP server URL in output

Connection Issues

  1. Check URL: Ensure correct /gradio_api/mcp/sse endpoint
  2. Authentication: Add Bearer token for private Spaces
  3. Network: Verify firewall/proxy settings
  4. Dependencies: Ensure gradio[mcp] is installed

Tool Discovery Issues

# Test tools manually
from trackio_mcp.tools import register_trackio_tools

tools = register_trackio_tools()
tools.launch(mcp_server=True)  # Test tools interface

Contributing

  1. Fork the repository
  2. Install development dependencies: pip install -e .[dev]
  3. Make your changes
  4. Run tests: pytest
  5. Submit a pull request

License

MIT License - see LICENSE file.

Acknowledgments


Made with care for the AI research community

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

trackio_mcp-0.1.0.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

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

trackio_mcp-0.1.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file trackio_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: trackio_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for trackio_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 50d88d9e8782a10046b27ba2a406e17ef1ab0b17a231a4b39b841ca2fd6bf0a5
MD5 fe26fc1bc0dce3e2309ac587ab1746a2
BLAKE2b-256 5b7f093deb877d2d4ced7dbc31093c8426cf58f3fdd0738c343aae71ff5b298e

See more details on using hashes here.

Provenance

The following attestation bundles were made for trackio_mcp-0.1.0.tar.gz:

Publisher: publish_pypi.yml on fcakyon/trackio-mcp

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

File details

Details for the file trackio_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: trackio_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for trackio_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d0a6e3133e9d0575202c9fce392ed1c6445788e1566b6f23136cfe947898f1a5
MD5 c2615cd1608bd8837eabb9bdb1b8cb6a
BLAKE2b-256 bd442ff27e93d2d32fcf6f089546a8ae8b5f08309430232df262747c29cb4aa0

See more details on using hashes here.

Provenance

The following attestation bundles were made for trackio_mcp-0.1.0-py3-none-any.whl:

Publisher: publish_pypi.yml on fcakyon/trackio-mcp

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