Skip to main content
Glama

champollion-sulcal-mcp

A FastMCP server wrapping the Champollion sulcal embedding pipeline — exposes each pipeline stage as an MCP tool so an agent can run, monitor, and debug the pipeline without shelling out manually.

Overview

This is a stdio MCP server (not a web service). It doesn't run the pipeline in-process — each start_* tool launches one of the pipeline's CLI scripts as a subprocess and tracks it as a background job (status + log file on disk), which callers poll until it reaches a terminal state.

Any MCP client can drive it. The repository also ships its own Claude Code subagent definition and skills, so it can be driven directly from Claude Code.

Related MCP server: dat-ai-mcp

How it works

  1. A caller (an MCP client) invokes a tool such as start_cortical_tiles.

  2. The tool validates its arguments (paths must be absolute), resolves the pipeline's script location via preflight.detect(), and builds an argv matching that script's real CLI.

  3. runner.launch() spawns the script as a subprocess with an environment built by _build_env() (selectively passes HF_TOKEN, injects BRAINVISA_SHARE, prepends BrainVISA/pixi bins to PATH), and returns immediately with a job_id.

  4. The subprocess's combined stdout/stderr is streamed line-by-line into a log file; progress lines matching fold N/M update the job's progress.

  5. The caller polls get_job_status(output_dir, job_id) (and can tail get_job_log) until the job is succeeded, failed, or cancelled.

Pipeline stages

Stage

Tool

Purpose

1

start_morphologist

Generate sulcal graphs from T1 MRI using Morphologist

2

start_cortical_tiles

Extract 28 standardized sulcal region crops

3

start_config

Generate Champollion dataset YAML configuration

4

start_embeddings

Compute 56-fold sulcal embeddings (28 regions × 2 hemispheres)

5

start_combine

Collect per-region embedding CSVs into a single output directory

6

start_snapshots

Render sulcal graph meshes, cortical tile masks, and UMAP plots

—

start_pipeline

Run stages 1–6 sequentially as one umbrella job (stages skippable)

—

start_training

Train a self-supervised champollion_V1 encoder for one region

Project layout

src/champollion_sulcal_mcp/
├── server.py            # FastMCP instance, tool registration, entry point (main())
├── preflight.py          # locates the champollion_pipeline repo + its scripts/submodules
├── job_store.py           # JobState/JobProgress models, JSON job file persistence
├── runner.py               # subprocess launch, log capture, progress parsing, cancel
└── tools/
    ├── stages.py           # one start_<stage> tool per pipeline stage + maintenance tools
    ├── pipeline.py          # start_pipeline composite/umbrella job orchestration
    ├── jobs.py               # get_job_status, list_jobs, cancel_job, get_job_log
    └── utils.py               # get_pipeline_info, preflight_check
agents/
└── champollion-pipeline.md  # Claude Code subagent definition for this MCP server
skills/
├── run-pipeline/             # SKILL.md guiding pipeline runs and their parameters
├── monitor/                   # SKILL.md for the job-polling loop
└── debug/                      # SKILL.md + known error patterns for failure diagnosis
tests/                           # pytest suite with fake_pipeline_dir / recording_runner fixtures

MCP tools reference

Registered in server.py:

Stage launchers — start_morphologist, start_cortical_tiles, start_config, start_training, start_embeddings, start_combine, start_snapshots

Composite pipeline — start_pipeline

Maintenance — purge_subject (remove a subject's cortical_tiles derivatives), prune_failed_subjects (remove outputs for subjects that failed QC)

Job lifecycle — get_job_status, list_jobs, cancel_job, get_job_log

Utilities — get_pipeline_info (server/stage metadata), preflight_check (verify the pipeline is correctly configured and accessible)

Requirements

  • Python 3.11 or 3.12

  • pixi

  • A checkout of the champollion_pipeline repository (not included here) — must contain the stage scripts under src/ (generate_morphologist_graphs.py, run_cortical_tiles.py, generate_champollion_config.py, generate_embeddings.py, put_together_embeddings.py, generate_snapshots.py, train_champollion.py) and the external/champollion_V1 and external/cortical_tiles submodules.

Installation

pixi install

Configuration

Variable

Purpose

Default

CHAMPOLLION_PIPELINE_DIR

Absolute path to the champollion_pipeline repo

Required

HF_TOKEN

HuggingFace token

Passed through only to the embeddings stage; stripped from every other stage's subprocess environment

BRAINVISA / BRAINVISA_SHARE

BrainVISA install location / share dir

Auto-injected from the pipeline's pixi environment if not already set in the environment

Running

This is a stdio server meant to be launched by an MCP client or coding agent (see Coding agents integration for ready-to-paste configurations), not run interactively on its own:

pixi run run                  # python -m champollion_sulcal_mcp.server
# or, once installed:
champollion-sulcal-mcp

Coding agents integration

Any coding agent or MCP client that can launch a local stdio server can use this server. Every configuration below starts it with pixi run --manifest-path /path/to/champollion_sulcal_mcp/pixi.toml run, so it works from any working directory. Replace the /path/to/... placeholders with absolute paths.

  • CHAMPOLLION_PIPELINE_DIR is required: the absolute path of your champollion_pipeline checkout.

  • HF_TOKEN is optional: set it only to download models from Hugging Face. Prefer an environment reference over writing the token in a configuration file, and never commit a token.

  • The first start can take a few seconds while pixi resolves the environment, so the snippets raise the client's start-up timeout.

Claude Code

Register it with the CLI (user scope shown; --scope project writes a shared .mcp.json instead):

claude mcp add --transport stdio --scope user \
  --env CHAMPOLLION_PIPELINE_DIR=/path/to/champollion_pipeline \
  champollion-sulcal \
  -- pixi run --manifest-path /path/to/champollion_sulcal_mcp/pixi.toml run

or add it to .mcp.json at the root of your project:

{
  "mcpServers": {
    "champollion-sulcal": {
      "command": "pixi",
      "args": ["run", "--manifest-path", "/path/to/champollion_sulcal_mcp/pixi.toml", "run"],
      "env": {
        "CHAMPOLLION_PIPELINE_DIR": "/path/to/champollion_pipeline",
        "HF_TOKEN": "${HF_TOKEN:-}"
      }
    }
  }
}

This repository also ships Claude Code assets:

  • agents/champollion-pipeline.md — a subagent scoped to exactly the MCP tools it needs, with an operational playbook: always preflight first, never guess paths, default output layout, per-stage required parameters, a known-error-pattern table, and the exact CLI invocation each tool wraps.

  • skills/run-pipeline — guides choosing between the full pipeline and individual stages, and gathering the right parameters.

  • skills/monitor — a poll-every-30-seconds monitoring loop with per-job-type progress reporting.

  • skills/debug — systematic failure diagnosis: read the full log, match against known error patterns, report root cause and fix.

They are Markdown files: other coding agents can read them as plain instructions, for example by pointing their own agent or rules file at them.

OpenCode

In opencode.json (project) or ~/.config/opencode/opencode.json (global):

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "champollion-sulcal": {
      "type": "local",
      "command": ["pixi", "run", "--manifest-path", "/path/to/champollion_sulcal_mcp/pixi.toml", "run"],
      "enabled": true,
      "timeout": 30000,
      "environment": {
        "CHAMPOLLION_PIPELINE_DIR": "/path/to/champollion_pipeline",
        "HF_TOKEN": "{env:HF_TOKEN}"
      }
    }
  }
}

Mistral Vibe

In ./.vibe/config.toml (project) or ~/.vibe/config.toml (global). Vibe does not expand environment variables in this file; add "HF_TOKEN" = "<your token>" to env only in a private, uncommitted config.

[[mcp_servers]]
name = "champollion-sulcal"
transport = "stdio"
command = "pixi"
args = ["run", "--manifest-path", "/path/to/champollion_sulcal_mcp/pixi.toml", "run"]
startup_timeout_sec = 60
env = { "CHAMPOLLION_PIPELINE_DIR" = "/path/to/champollion_pipeline" }

Codex

In ~/.codex/config.toml (global) or .codex/config.toml (trusted project); env_vars forwards HF_TOKEN from your shell without storing it in the file:

[mcp_servers.champollion-sulcal]
command = "pixi"
args = ["run", "--manifest-path", "/path/to/champollion_sulcal_mcp/pixi.toml", "run"]
startup_timeout_sec = 60
env_vars = ["HF_TOKEN"]

[mcp_servers.champollion-sulcal.env]
CHAMPOLLION_PIPELINE_DIR = "/path/to/champollion_pipeline"

or from the command line:

codex mcp add champollion-sulcal \
  --env CHAMPOLLION_PIPELINE_DIR=/path/to/champollion_pipeline \
  -- pixi run --manifest-path /path/to/champollion_sulcal_mcp/pixi.toml run

Other MCP clients

Most other clients (Claude Desktop, Cursor, and others) read the common mcpServers format, for example Claude Desktop's claude_desktop_config.json or Cursor's .cursor/mcp.json:

{
  "mcpServers": {
    "champollion-sulcal": {
      "command": "pixi",
      "args": ["run", "--manifest-path", "/path/to/champollion_sulcal_mcp/pixi.toml", "run"],
      "env": {
        "CHAMPOLLION_PIPELINE_DIR": "/path/to/champollion_pipeline"
      }
    }
  }
}

If your client has no env setting, export CHAMPOLLION_PIPELINE_DIR (and optionally HF_TOKEN) in the environment the client is started from.

Job tracking

Each job is persisted as <output_dir>/.mcp_jobs/<job_id>.json (atomic write) with its combined stdout/stderr log at <output_dir>/.mcp_jobs/<job_id>.log. Status lifecycle: pending → running → one of succeeded / failed / cancelled. start_pipeline additionally writes an "umbrella" job whose progress tracks current_stage / stages_done / stages_total and the currently active child job_id.

Testing

pixi run test           # full suite
pixi run test-unit        # unit-marked tests only
pixi run test-fast         # stop on first failure
pixi run test-cov           # with coverage report

tests/conftest.py provides fake_pipeline_dir (a temp dir with stub stage scripts and submodule folders) and recording_runner (stubs runner.launch to record calls instead of spawning real subprocesses), so most tool behavior can be tested without a real champollion_pipeline checkout.

Linting

pixi run lint        # ruff check
pixi run lint-fix      # ruff check --fix
pixi run format         # ruff format

Contributing

See CONTRIBUTING.md for the development setup, checks, branch model and how to report issues.

License

Released under the CeCILL-B free software licence, the same as champollion_pipeline. See LICENSE.

Available Tools

16 tools
cancel_jobCancel JobB

Cancel a running job by sending SIGTERM to its process.

Inputs: job_id (required), output_dir (required). Returns: object

get_job_logGet Job LogC

Retrieve the last N lines of a job's log output.

Inputs: job_id (required), output_dir (required), tail_lines. Returns: object

get_job_statusGet Job StatusC

Get the current status and progress of a running or completed job.

Inputs: job_id (required), output_dir (required). Returns: object

get_pipeline_infoGet Pipeline InfoB

Get metadata about the Champollion pipeline and available MCP tools.

Inputs: no named parameters. Returns: object

list_jobsList JobsC

List all jobs for a given output directory, optionally filtered by status.

Inputs: output_dir (required), limit, status. Returns: result

preflight_checkPreflight CheckB

Check whether the Champollion pipeline is correctly configured and accessible.

Inputs: no named parameters. Returns: object

prune_failed_subjectsPrune Failed SubjectsA

Remove cortical_tiles outputs for all subjects that failed QC.

Reads a QC TSV/CSV file with 'participant_id' and 'qc' columns and deletes all files belonging to subjects with qc==0 or absent from the QC file. Equivalent to having run cortical_tiles with --sk_qc_path from the start.

Use dry_run=True to preview what would be deleted without modifying anything.

Inputs: qc (required), output (required), dry_run. Returns: object

purge_subjectPurge SubjectA

Remove all cortical_tiles derivatives for a single subject.

Deletes per-subject NIfTI files (crops, labels, extremities, distbottom), per-subject subdirectories (skeletons/, foldlabels/, transforms/, distmaps/), and filters the subject's row from aggregated .npy arrays and their subject CSVs.

Use dry_run=True to preview what would be deleted without modifying anything.

Inputs: subject (required), derivatives (required), dry_run. Returns: object

start_combineStart CombineC

Launch Stage 5: collect all per-region embedding CSVs into a single output directory.

Inputs: output_path (required), embeddings_source (required). Returns: object

start_configStart ConfigB

Launch Stage 3: generate Champollion dataset YAML configuration files.

The configs root defaults to //derivatives/champollion_V1/configs, where is the parent of the directory in crop_path; region YAMLs land at {configs root}/dataset//. output overrides the configs root; external_config overrides where the dataset_localization YAML is written (default {configs root}/dataset_localization/). Each is forwarded only when supplied, so the pipeline defaults apply otherwise. When supplied, output and external_config must be absolute paths and, when the MCP client declares roots, inside a declared root. masks is the mask version tag forwarded as --masks; it must match the stage-2 masks (script default canonical_25).

Inputs: dataset (required), crop_path (required), masks, output, +3 more. Returns: object

start_cortical_tilesStart Cortical TilesC

Launch Stage 2: extract 28 sulcal region crops with cortical_tiles.

Inputs: input_dir (required), output_dir (required), path_to_graph (required), path_sk_with_hull (required), +6 more. Returns: object

start_embeddingsStart EmbeddingsC

Launch Stage 4: compute sulcal embeddings across all 56 model folds (28 regions × 2 hemispheres).

profiling: run the embeddings script under cProfile. no_cache: re-extract a models archive, ignoring the cache. legacy: read crops from derivatives/deep_folding-2025 (overrides cortical_version). use_last_checkpoint: evaluate with the native Lightning checkpoint in version_0/checkpoints/ instead of best_model_weights.pt, for regions that have one.

Inputs: models_path (required), datasets_root (required), cpu, masks, +11 more. Returns: object

start_morphologistStart MorphologistC

Launch Stage 1: generate sulcal graphs with Morphologist from raw T1 MRI data.

Inputs: input_dir (required), output_dir (required), parallel, enable_sulcal_recognition. Returns: object

start_pipelineStart PipelineB

Launch the full Champollion pipeline (all 6 stages sequentially). Returns a pipeline job_id immediately.

reference_data_dir is optional and forwarded to stage 6 (snapshots) for UMAP plots.

A non-empty masks is forwarded to stages 2, 3 and 4, and names the <datasets_root>/derivatives/champollion_V1/<masks or canonical_25>/ directory that stages 5 and 6 read and write (region_embeddings, embeddings, snapshots). overwrite, run_cka, regions, masks_version and cortical_version apply to stage 4 (embeddings) only. regions are model names (e.g. SCsylv_left); cortical_version must name where the stage-2 crops actually are.

Inputs: dataset (required), crop_path (required), input_dir (required), output_dir (required), +17 more. Returns: object

start_snapshotsStart SnapshotsC

Launch Stage 6: render sulcal graph meshes, cortical tile masks, and UMAP scatter plots.

UMAP plots need both embeddings_dir and reference_data_dir; there is no default for reference_data_dir (not shipped with champollion_pipeline).

Inputs: output_dir (required), subject, umap_only, tiles_only, +8 more. Returns: object

start_trainingStart TrainingB

Launch encoder training: train a champollion_V1 self-supervised encoder for one sulcal region.

Dataset configs must exist before calling this tool: run start_config first. When the MCP client declares roots, config_dir defaults to <roots[0]>/data//derivatives/champollion_V1/configs (roots[0] = the first declared root; same base as the output_dir default). Otherwise config_dir defaults to /data//derivatives/champollion_V1/configs ( = the champollion_pipeline root). Pass config_dir when the configs live elsewhere (use //derivatives/champollion_V1/configs) or when start_config was given an explicit output (use that configs root).

Inputs: region (required), dataset (required), cpu, swf, +5 more. Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.2/5.0

    Scored across 16 tools

    Disambiguation4/5

    Most tools have clearly distinct roles: stage launches are separated by stage number and resource, and job controls are status/list/cancel/log. Minor overlap exists between start_pipeline and the individual stage launchers, and between purge_subject and prune_failed_subjects, but descriptions make the distinctions clear.

    Naming Consistency4/5

    Tool names are mostly consistent snake_case action-object patterns, especially the start_* stage launchers and job management verbs. preflight_check is a minor deviation from the verb_noun pattern but remains readable.

    Tool Count4/5

    At 16 tools it is slightly heavy, but the count is justified by six pipeline stages, a full-pipeline launcher, configuration/training helpers, job management, cleanup, and informational tools. Each tool has a plausible role in the orchestration workflow.

    Completeness4/5

    The surface covers the main pipeline lifecycle well: preflight, all six stages, full pipeline execution, job status/list/cancel/log, cleanup, and pipeline info. Minor gaps remain, such as resume/retry operations and cleanup coverage outside cortical_tiles outputs.

    Maintenance

    ActivityNo data
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers