MCP (Model Context Protocol) server support for SwanLab
Project description
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, andtotal - 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": "uv",
"args": ["run", "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 uv run 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 workspacesswanlab_get_workspace- Get workspace detailsswanlab_list_projects_in_workspace- List projects in one workspaceswanlab_list_projects- List projectsswanlab_get_project- Get project detailsswanlab_list_runs_in_project- List runs in one projectswanlab_list_runs- List runs with optional filters (state,config.*)swanlab_get_run- Get run detailsswanlab_get_run_config- Get run configswanlab_get_run_metadata- Get run metadataswanlab_get_run_requirements- Get run requirementsswanlab_get_run_metrics- Get run metric table
Resource Definitions:
- workspace: collection of projects (
PERSONorTEAM) identified byusername. - 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
- SwanLab
- Model Context Protocol
- FastMCP v2
- modelscope-mcp-server
- TrackIO-mcp-server
- Simple-Wandb-mcp-server
📄 License
MIT License
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 swanlab_mcp-0.0.2.tar.gz.
File metadata
- Download URL: swanlab_mcp-0.0.2.tar.gz
- Upload date:
- Size: 29.0 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35d1102fb4fc38d68ece1508698716d4adac529779449c3688b3acf4fae97ca7
|
|
| MD5 |
4595b6328339e5d7b8e593df0818c1b8
|
|
| BLAKE2b-256 |
f23e6306827d764fc094c41767d64b15e38b0363b69178a2e226de0b94b1bfff
|
File details
Details for the file swanlab_mcp-0.0.2-py3-none-any.whl.
File metadata
- Download URL: swanlab_mcp-0.0.2-py3-none-any.whl
- Upload date:
- Size: 19.2 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c015d818a6980aed2b707014ae8d513943d6e4c416e6771fc2aa38f1dd6ec6b4
|
|
| MD5 |
0ba2d6d20d2ae26d19930e83adb781c0
|
|
| BLAKE2b-256 |
eeed6fc720cb37b89ad3b9bb5040525b2e9b2391d1b9ad5ac60192e39b949b5d
|