Metadata-Version: 2.5
Name: swanlab-mcp
Version: 0.3.2
Summary: MCP (Model Context Protocol) server support for SwanLab
Author-email: CaddiesNew <nexisato0810@gmail.com>
License: MIT
License-File: LICENSE
Requires-Python: >=3.12
Requires-Dist: fastmcp>=4.2.0
Description-Content-Type: text/markdown

<div align="center">

<a href="https://swanlab.cn/">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="public/SWANLAB_LOGO_DARK.svg" />
    <source media="(prefers-color-scheme: light)" srcset="public/SWANLAB_LOGO.svg" />
    <img src="public/SWANLAB_LOGO.svg" alt="SwanLab" width="360" />
  </picture>
</a>

<h1><a href="https://github.com/Nexisato/SwanLab-MCP">SwanLab MCP Server</a></h1>

> Let your AI coding assistant write SwanLab tracking code and look up experiment data.

[![SwanLab Website](https://img.shields.io/badge/SwanLab-Website-C21E31?labelColor=black&style=flat-square)](https://swanlab.cn/)
[![SwanLab Docs](https://img.shields.io/badge/SwanLab-Docs-c4f042?labelColor=black&style=flat-square)](https://docs.swanlab.cn)
[![PyPI](https://img.shields.io/pypi/v/swanlab-mcp?color=4b8bbe&labelColor=black&style=flat-square)](https://pypi.org/project/swanlab-mcp/)
[![Skill Version](https://img.shields.io/badge/Skill-v0.3.2-7c3aed?labelColor=black&style=flat-square)](https://github.com/SwanHubX/SwanLab-Skill)
[![License](https://img.shields.io/badge/License-MIT-d4a017?labelColor=black&style=flat-square)](LICENSE)

[中文](README_zh.md) · [Quick Start](#quick-start) · [What It Does](#what-it-does) · [What's Inside](#whats-inside) · [Development](#development)

</div>

---

SwanLab MCP Server hands the official [`swanlab-skill`](https://github.com/SwanHubX/SwanLab-Skill) to AI coding assistants like Claude Code and Codex. The assistant reads that guide, then writes tracking code for you or runs `swanlab api` in your terminal to look up experiments.

Queries go through the `swanlab` command on your own machine with your own login, so the assistant sees exactly what you would see doing it by hand. The server itself needs no API key — install it and it works.

## Quick Start

If you're using a coding agent like Claude Code or Codex, just send it the following prompt and it will install everything for you:

```text
Fetch the installation guide and follow it: https://raw.githubusercontent.com/Nexisato/SwanLab-MCP/main/README.md
```

Doing it by hand is just as easy.

### 1. Install and log in

```bash
pip install swanlab
swanlab login          # paste your API key from https://swanlab.cn
```

Once is enough — both the server and your assistant reuse it.

### 2. Add the MCP server

Claude Code:

```bash
claude mcp add -- swanlab-mcp uvx --from swanlab-mcp swanlab_mcp --transport stdio
```

Codex:

```bash
codex mcp add swanlab-mcp -- uvx --from swanlab-mcp swanlab_mcp --transport stdio
```

Codex writes it to `~/.codex/config.toml`, which is the same as adding this entry by hand:

```toml
[mcp_servers.swanlab-mcp]
command = "uvx"
args = ["--from", "swanlab-mcp", "swanlab_mcp", "--transport", "stdio"]
```

Any other client:

```json
{
  "mcpServers": {
    "swanlab-mcp": {
      "command": "uvx",
      "args": ["--from", "swanlab-mcp", "swanlab_mcp", "--transport", "stdio"]
    }
  }
}
```

> `uvx` pulls `swanlab-mcp` from PyPI on first run, so no prior installation is needed. To install it into your current environment instead, run `pip install swanlab-mcp` and replace `uvx --from swanlab-mcp` above with `swanlab_mcp`; `swanlab_mcp --version` confirms the installation.

### 3. Just ask

```text
Plot the loss curve of username/project/run1 and compare it with run2 and run3.
```

## What It Does

| You want                     | The assistant will                                                    |
| ---------------------------- | --------------------------------------------------------------------- |
| Add experiment tracking      | Write `swanlab.init` / `log` / `finish` code, with image, audio, text |
| Inspect one run              | Run `swanlab api` for metrics, logs, summaries and media              |
| Find matching experiments    | Filter runs by config or summary conditions                           |
| Chart and compare runs       | Run the bundled plotting scripts for line charts and run rankings     |

## What's Inside

`swanlab-skill` ships with the server and is readable as soon as you connect — nothing extra to install:

- **`SKILL.md`** — the entry point, telling the assistant which reference to read for the task at hand
- **`references/`** — how to use the SDK, how to use the CLI, data model and terminology, comparison and report writing
- **`scripts/`** — a single-run line chart and a multi-run ranking comparison

Both plotting scripts expect an existing `swanlab login`, plus `matplotlib` and `numpy` in the environment.

## Development

```bash
uv sync --all-groups
uv run pytest
uv run ruff check .
uv run swanlab_mcp --version
```

Skill content is copied from the upstream repository and committed, so every update shows up in the diff:

```bash
git clone https://github.com/SwanHubX/SwanLab-Skill ../SwanLab-Skill
make sync-skills
```

## License

[MIT License](LICENSE) © 2026 Emotion Machine (Beijing) Technology Co., Ltd.
