Skip to main content

SwanLab MCP Server

       

A Model Context Protocol (MCP) server implementation for SwanLab, combining SwanLab-OpenAPI & FastMCP.

✨ Features

Core Features

  • Workspace Queries - List accessible workspaces and enumerate workspace projects
  • Project Queries - List projects and inspect a specific project with run summaries
  • Run Queries - Inspect runs with normalized fields (id, state, profile, user)
  • Metric Queries - Fetch metric tables with consistent columns, rows, and total
  • API Integration - Provide read-only access through SwanLab OpenAPI (swanlab.Api)

Tech Stack

  • Language: Python 3.12+
  • Core Framework: FastMCP (v2.14.4+)
  • API Client: SwanLab SDK
  • Config Management: Pydantic Settings

🚀 Quick Start

❗️Configuration

Add the following configuration to your relative mcp config list

{
  "mcpServers": 
    ...
    {
    "swanlab-mcp": {
      "command": "uvx",
      "args": ["--from", "swanlab-mcp", "swanlab_mcp", "--transport", "stdio"],
      "env": {
        "SWANLAB_API_KEY": "your_api_key_here"
      }
    }
  }
}

For Claude Code Users, you can config like this:

claude mcp add --env SWANLAB_API_KEY=<your_api_key> -- swanlab_mcp uvx --from swanlab-mcp swanlab_mcp --transport stdio

Prerequisites

  • Python >= 3.12
  • SwanLab API Key (get it from SwanLab)

Installation

# Using uv (recommended)
uv sync

# Or using pip
pip install -e .

Configuration

Environment Variables

Create a .env file and configure your API key:

cp .env.template .env

Edit the .env file:

SWANLAB_API_KEY=your_api_key_here

Running

# Using stdio transport (default)
python -m swanlab_mcp

# Or using CLI
python -m swanlab_mcp --transport stdio

# Check version
python -m swanlab_mcp --version

Usage

After configuration, restart Claude Desktop to interact with SwanLab via the MCP protocol.

Available Tools:

  • swanlab_list_workspaces - List workspaces
  • swanlab_get_workspace - Get workspace details
  • swanlab_list_projects_in_workspace - List projects in one workspace
  • swanlab_list_projects - List projects
  • swanlab_get_project - Get project details
  • swanlab_list_runs_in_project - List runs in one project
  • swanlab_list_runs - List runs with optional filters (state, config.*)
  • swanlab_get_run - Get run details
  • swanlab_get_run_config - Get run config
  • swanlab_get_run_metadata - Get run metadata
  • swanlab_get_run_requirements - Get run requirements
  • swanlab_list_run_metric_keys - List available metric keys for a run
  • swanlab_get_run_metrics - Get run metric table

Resource Definitions:

  • workspace: collection of projects (PERSON or TEAM) identified by username.
  • project: collection of runs identified by path = username/project_name.
  • run: single experiment identified by path = username/project_name/experiment_id.
  • metric: tabular run history returned as {path, keys, x_axis, sample, columns, rows, total}.

🛠️ Development

Code Formatting

# Using Makefile
make format

# Or manually
uvx isort . --skip-gitignore
uvx ruff format . --quiet

Lint Check

uvx ruff check .

Pre-commit Hooks

bash scripts/install-hooks.sh

📚 References & Acknowledgements

📄 License

MIT License

Metadata

Release files for swanlab-mcp 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for swanlab-mcp 0.0.3
File Size Uploaded
swanlab_mcp-0.0.3.tar.gz 30.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for swanlab-mcp 0.0.3
File Interpreter ABI Platform
swanlab_mcp-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 50.2 kB

Release files / swanlab_mcp-0.0.3.tar.gz

Download URL swanlab_mcp-0.0.3.tar.gz
Size 30.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a790c84be80cc3bbcad6629c36144561d7d4af902c7cc5a5daf3eca7ec7d4d9e
BLAKE2b-256 checksum
How to use checksums
e35b052f795f50adec8c837e07b6178eb28fccbe9b6fdfbd7e9086bc76bc3480
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / swanlab_mcp-0.0.3-py3-none-any.whl

Download URL swanlab_mcp-0.0.3-py3-none-any.whl
Size 20.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
75257f26ee164adf17386c92fc36b28437ca820558e634476de43023d56fb4a8
BLAKE2b-256 checksum
How to use checksums
57fce043166539fd3e3db06fc9174037702786769ec0a500a10c127b233afed7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page