# MNE-MCP [Health: Active]

**Category:** 💻 Developer Tools  
**Repository:** https://github.com/Exekiel179/MNE-MCP  
**GitHub Stars:** 14  
**Views:** 2  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/mne-mcp

## Description
MNE-Python neurophysiology analysis (EEG, MEG, sEEG, ECoG, fNIRS) via the Model Context Protocol

## Tools
Capabilities this server exposes over MCP:

- **mne_check_status** — Check MNE MCP capabilities: MNE-Python version, scikit-learn (needed for ICA), numpy/scipy/matplotlib versions, and runtime directories. Call this first.
- **mne_install_backend** — Provision the analysis backend (MNE-Python + numpy/scipy/matplotlib/pandas, plus scikit-learn for ICA) into this server's own Python environment, on demand. Call this once when mne_check_status reports the backend is not installed; afterwards every mne_* tool works with NO client restart. profile: 'ica' (default), 'analysis' (no scikit-learn), or 'full' (adds source localization, connectivity, decoding, BIDS, extra file readers). The first run downloads a large scientific stack and may take a few minutes.
- **mne_get_config** — Show the configured default analysis parameters (line frequency, default montage, filter band, rejection threshold, ICA method/components, epoch window, dirs, timeout) that the structured tools fall back to when a parameter is omitted. Users change these by running `mne-mcp configure` in a terminal.
- **mne_session_info** — List every object currently held in the persistent analysis session (raw recordings, epochs, evoked, ICA, events, arrays) with a one-line summary. Use this to see what is loaded before operating on it.
- **mne_describe** — Show a detailed summary of one named session object (channels, sfreq, montage, bads, etc.).
- **mne_get_info** — Show the full channel list and measurement info for a named session object.
- **mne_reset_session** — Clear all loaded objects and figures from the session, starting fresh. Irreversible.
- **mne_run_code** — Execute arbitrary Python/MNE code in the persistent session namespace. Pre-bound names: `mne`, `np`, `pd`, `plt`, plus every object you have loaded (e.g. `raw`, `epochs`, `evoked`, `ica`). Like a notebook cell: the value of a final expression is returned, stdout is captured, and any matplotlib figures are saved as PNG (paths returned). Use this for anything the structured tools do not cover.
- **mne_list_files** — List neurophysiology data files (.fif, .edf, .bdf, .vhdr, .set, .cnt, .egi/.mff, .ds, .snirf, …) under a directory. Defaults to MNE_MCP_DATA_DIR / current dir. Optionally pass a glob pattern.
- **mne_load_raw** — Load a raw recording from disk into the session. Auto-detects the format by extension (FIF/EDF/BDF/BrainVision/EEGLAB/CNT/EGI/…). Stores it under `name` (default `raw`). Set preload=False for very large files.
- **mne_filter** — Band-pass / high-pass / low-pass and/or notch filter a Raw/Epochs/Evoked object in place. l_freq=high-pass edge, h_freq=low-pass edge (either may be null), notch=line-noise frequency (e.g. 50 or 60). picks optional ('eeg', 'meg', or null).
- **mne_resample** — Resample a Raw/Epochs object to a new sampling frequency (Hz), in place.
- **mne_crop** — Crop a Raw/Epochs/Evoked object to the time window [tmin, tmax] seconds, in place.
- **mne_set_montage** — Apply a standard electrode montage (e.g. 'standard_1020', 'standard_1005', 'biosemi64', 'GSN-HydroCel-128') to set channel positions. Needed before topographic plots and interpolation. If montage is omitted, uses the configured default (set via `mne-mcp configure`).
- **mne_set_reference** — Set the EEG reference. Use 'average' for average reference, 'REST', or a comma-separated list of channel names (e.g. 'TP9,TP10').
- **mne_mark_bad_channels** — Mark channels as bad (comma-separated names, e.g. 'Fp1,T7'). By default appends to existing bads; set replace=true to overwrite.
- **mne_interpolate_bads** — Interpolate currently-marked bad channels using spherical splines (requires a montage).
- **mne_plot_psd** — Plot the power spectral density of a Raw/Epochs/Evoked object. Returns a PNG path.
- **mne_plot_raw** — Plot raw signal traces (a window of channels over time). Returns a PNG path.
- **mne_plot_sensors** — Plot the sensor/electrode layout (kind='topomap' 2D or '3d'). Returns a PNG path.
- **mne_fit_ica** — Fit Independent Component Analysis on a (preferably 1 Hz high-pass filtered) Raw/Epochs object for artifact removal. n_components can be an int, a float (variance fraction), or null. method: 'fastica' (default), 'infomax', 'picard'. Stored under ica_name (default 'ica'). Requires scikit-learn.
- **mne_plot_ica_components** — Plot ICA component scalp topographies (to identify eye/heart/muscle artifacts). Returns PNG path(s).
- **mne_plot_ica_sources** — Plot ICA component time courses for an instrument (raw/epochs). Returns a PNG path.
- **mne_apply_ica** — Remove ICA components from an instrument in place. exclude = comma-separated component indices to drop (e.g. '0,3'); if omitted, uses the ICA object's current exclude list.
- **mne_find_events** — Find stimulus/trigger events on a stim channel of a Raw object. Stores them under events_name.
- **mne_events_from_annotations** — Convert a Raw object's annotations into an events array + event_id map (for EDF/BrainVision/EEGLAB data).
- **mne_make_epochs** — Segment a Raw object into Epochs around events. tmin/tmax in seconds relative to the event; baseline 'default' = (None, 0); event_id like 'target:1,standard:2' to name/select conditions; reject_eeg = peak-to-peak EEG rejection threshold in volts (e.g. 100e-6). Stored under epochs_name.
- **mne_plot_epochs_image** — Plot an ERP image (epochs × time heatmap) for an Epochs object. Returns PNG path(s).
- **mne_average_evoked** — Average Epochs into an Evoked (ERP/ERF) response. condition = an event_id name to average just that condition (else averages all). Stored under evoked_name.
- **mne_plot_evoked** — Plot an Evoked response. style: 'joint' (butterfly + topomaps, default), 'topo', or 'butterfly'. Returns PNG path.
- **mne_plot_topomap** — Plot scalp topographies of an Evoked at given times. times='auto', 'peaks', or comma-separated seconds (e.g. '0.1,0.2,0.3'). Returns PNG path.
- **mne_tfr_morlet** — Compute Morlet-wavelet time-frequency power on Epochs and plot it. fmin/fmax = frequency range (Hz), n_freqs = number of frequencies. Stored under tfr_name. Returns PNG path.
- **mne_save** — Save a session object to disk. MNE naming rules: Raw → '*_raw.fif', Epochs → '*-epo.fif', Evoked → '*-ave.fif'. Other formats follow the object's .save() support.
- **mne_decode** — Time-resolved decoding (MVPA): train a classifier at each time point to discriminate two conditions, with cross-validation. cond_a/cond_b are event_id names (e.g. 'target','standard'). Returns mean/peak score over time + a scores-vs-time plot. Requires scikit-learn.
- **mne_connectivity** — Spectral connectivity between channels over Epochs in a frequency band. method: 'coh', 'plv', 'wpli', 'pli', 'imcoh', etc. Returns a channel×channel connectivity heatmap + strongest pairs. Requires mne-connectivity.
- **mne_compute_noise_cov** — Compute a noise covariance matrix from the Epochs baseline (data up to tmax seconds, default 0). Needed before building an inverse operator for source localization.
- **mne_make_forward** — Build a template-head (fsaverage) EEG forward model for the named object's montage. Downloads the fsaverage template once (~ tens of MB). Use for EEG source localization without an individual MRI. Stored under fwd_name.
- **mne_apply_inverse** — Estimate cortical sources from an Evoked using a forward model and noise covariance. method: 'dSPM' (default), 'MNE', 'sLORETA', 'eLORETA'. Stores the source estimate (stc) and reports the peak activation time. Pair with mne_make_forward + mne_compute_noise_cov.
- **mne_plot_source_estimate** — Render a source estimate (stc) as a cortical activation map (PNG) at its peak time or a given time. hemi: 'both' / 'lh' / 'rh'. Requires PyVista with off-screen rendering; if 3D rendering is unavailable the estimate is still computed and can be inspected via mne_run_code.

## Claude Desktop Quick Installation
Install path detected from listing signals. Uses `uvx` (confidence: high):

```json
"mcpServers": {
  "mne-mcp": {
    "command": "uvx",
    "args": ["mne-mcp"]
  }
}
```

## Documentation & README

<!-- mcp-name: io.github.Exekiel179/mne-mcp -->

# MNE-MCP

[![CI](https://github.com/Exekiel179/MNE-MCP/actions/workflows/ci.yml/badge.svg)](https://github.com/Exekiel179/MNE-MCP/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![Python 3.12+](https://img.shields.io/badge/python-3.12%2B-blue.svg)](https://www.python.org/downloads/)
[![MCP](https://img.shields.io/badge/protocol-MCP-green.svg)](https://modelcontextprotocol.io)

**English** | [简体中文](https://github.com/Exekiel179/MNE-MCP/blob/HEAD/README.zh-CN.md)

A [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server that gives AI assistants
direct, conversational access to **[MNE-Python](https://mne.tools/)** for analyzing human
neurophysiology data — **EEG, MEG, sEEG, ECoG, and fNIRS**.

Describe your analysis in plain language — MNE-MCP loads your recording, runs the MNE pipeline
(filtering, ICA, epoching, ERP/ERF averaging, time-frequency, source-level work via code),
saves the figures, and explains the results.

> Works in **Claude Code**, **Codex**, **PsyClaw** and **opencode**. Pairs with bundled
> Agent **Skills** — `mne-analyst`, `mne-mcp-guard`, plus a skeptical **analysis suite**
> (`mne-methodology-critic` + per-category skills) for reliable, archived workflows.

---

## Why an MCP for MNE-Python?

MNE analysis is **stateful and visual** — unlike a one-shot statistics batch job:

- You load a `Raw` recording once, then filter → re-reference → fit ICA → epoch → average →
  time-frequency, each step mutating large in-memory objects. MNE-MCP keeps **one persistent
  session** so recordings never get re-loaded between steps.
- Every decision is driven by **looking** (PSD, sensor maps, ICA components, ERPs). Every plotting
  tool saves a **PNG** the assistant can read and interpret.
- MNE has a large Python API. MNE-MCP gives you **41 structured tools** spanning the common
  pipeline *and* advanced analysis (source localization, connectivity, decoding), plus an
  **`mne_run_code`** escape hatch that reaches the entire MNE API in the same live session.
- Defaults (line frequency, montage, filter band, rejection threshold, ICA settings, epoch window,
  dirs, timeout) are **user-configurable** via an interactive `mne-mcp configure` wizard.

---

## Requirements

- Python **3.12+** (no package upper-version gate; full-test baseline: 3.12)
- Git
- Claude Code, Codex, PsyClaw, opencode, or another MCP client

> Cross-platform: unlike a closed engine, MNE-Python is pure Python, so analysis tools work on
> Windows, macOS, and Linux.

---

## Installation

Looking for the separate native C++ preview? See
[MNE-CPP MCP installation and capabilities](https://github.com/Exekiel179/MNE-MCP/blob/HEAD/packages/mne-cpp-mcp/README.md).
It now includes explicit native-runtime setup and companion-skill registration;
it is not a replacement for the MNE-Python analysis backend described here.

### Install with your agent

Send this to a coding agent with terminal access:

> Follow https://github.com/Exekiel179/MNE-MCP/blob/v0.4.4/INSTALL_AGENT.md to install MNE-MCP and all companion skills in my existing MNE environment, configure my current client, and verify the result.

The agent checks the environment, installs missing MNE/core libraries when needed, installs the lightweight interface and all 14 skills, and
registers the selected client. A client restart is required. See the
[installation guide](https://github.com/Exekiel179/MNE-MCP/blob/HEAD/INSTALL_AGENT.md) for environment checks and verification.

### Manual installation

Activate your existing Python 3.12+ MNE environment, then install the lightweight interface:

```bash
python -m pip install mne-mcp
mne-mcp setup
```

The installation creates the `mne-mcp` command (`mne-mcp.exe` on Windows).
`python -m mne_mcp setup` remains an equivalent diagnostic invocation.

Release downloads: [latest release](https://github.com/Exekiel179/MNE-MCP/releases/latest).
For a downloaded source archive, extract it and use `python -m pip install .` in that directory.
Setup defaults to all four clients, including their skills. To configure only PsyClaw,
use `mne-mcp setup --clients psyclaw`; `claude`, `codex` and `opencode`
are also supported (comma-separated). Restart clients after setup; PsyClaw supports `/reload`.
MNE and scientific libraries are user-managed; installing this package does not install them.
See [installation instructions](https://github.com/Exekiel179/MNE-MCP/blob/HEAD/docs/INSTALL.md) for dependencies and troubleshooting.

## Configuration

### Repair or reconfigure

To update an existing installation, run `python -m pip install --upgrade mne-mcp`.
Run `mne-mcp setup --clients codex` in the same MNE environment.
Setup registers that exact interpreter and installs the bundled skills for the selected clients.
Existing configuration and skill files are backed up before updates.

### PsyClaw verification

PsyClaw registration writes `~/.psyclaw/mcp/mne.json`; all 14 skills and references
go to `~/.psyclaw/skills`. Setup checks a real MCP handshake, tool discovery and
`mne_check_status`, including a second check of the saved PsyClaw command.

```bash
mne-mcp verify --client psyclaw
```

This checks the saved command without modifying registration. `connected` and
`mne_available` are separate: the lightweight server can connect without MNE installed.
After `/reload`, ask PsyClaw to list tools for server `mne` and call `mne_check_status`.
Project `.psyclaw/mcp/*.json` entries with the same id override user configuration.
The setup check does not claim your already-running chat has reloaded.

### Environment variables (optional `.env`)

```ini
MNE_MCP_TIMEOUT=300          # per-operation timeout (s); raise for ICA / TFR / large files
MNE_MCP_RESULTS_DIR=...      # where figures + exported objects are saved
MNE_MCP_DATA_DIR=...         # default directory mne_list_files scans
```

### Configure analysis defaults (interactive wizard)

Set the defaults the structured tools fall back to — mains line frequency (50/60 Hz), default
montage, filter band, EEG rejection threshold, ICA method/components, epoch window, directories,
and timeout:

```bash
mne-mcp configure            # interactive prompts (Enter keeps current value)
mne-mcp configure --show     # print current defaults
mne-mcp configure --reset    # back to built-in defaults
mne-mcp configure --set line_freq=60 default_montage=biosemi64 reject_eeg_uv=120   # non-interactive
```

Defaults are saved to `~/.mne-mcp/config.json` (override path with `MNE_MCP_CONFIG`). Precedence at
runtime: **environment variable > config file > built-in**. View the active config in-session with the
`mne_get_config` tool. Restart the MCP server for changes to take effect.

### Skills

Setup installs all 14 skills into the selected client's skill directory, including their references.
Claude also receives the methodology-review subagent. Other clients use the methodology-critic skill.
Rerun setup after updating the package.

---

## Usage

Just describe what you want:

```
加载 sub-01_raw.fif，看一下功率谱
```
```
对 raw 做 1–40 Hz 带通、50 Hz 陷波，然后跑 ICA 去眼电
```
```
Epoch around the 'target' trigger, -0.2 to 0.8 s, average it, and show the ERP topomaps at 100/200/300 ms
```

The assistant will:
1. Check capabilities (`mne_check_status`)
2. Load your recording into the persistent session
3. Run the pipeline step by step, showing figures as PNGs
4. Interpret each result in plain language
5. Archive figures + the equivalent MNE code to `mne_result/`

---

## Output

Every plotting tool saves a PNG to the results dir and returns its path:

```
> Figure: `C:\...\mne-mcp\results\psd_01.png`
```

With the `mne-analyst` skill installed, results and the exact MNE code that produced them are
archived to `mne_result/` in your working directory (sequence-numbered), so the analysis is
fully reproducible.

---

## Available Tools (41)

### Status & Session (7)
`mne_check_status` · `mne_session_info` · `mne_describe` · `mne_get_info` ·
`mne_reset_session` · `mne_run_code` · `mne_get_config`

### Data IO (2)
`mne_list_files` · `mne_load_raw`

### Preprocessing (7)
`mne_filter` · `mne_resample` · `mne_crop` · `mne_set_montage` ·
`mne_set_reference` · `mne_mark_bad_channels` · `mne_interpolate_bads`

### Visualization (3)
`mne_plot_psd` · `mne_plot_raw` · `mne_plot_sensors`

### ICA (4)
`mne_fit_ica` · `mne_plot_ica_components` · `mne_plot_ica_sources` · `mne_apply_ica`

### Events / Epochs / ERP (7)
`mne_find_events` · `mne_events_from_annotations` · `mne_make_epochs` ·
`mne_plot_epochs_image` · `mne_average_evoked` · `mne_plot_evoked` · `mne_plot_topomap`

### Time-frequency (2)
`mne_compute_tfr` (Morlet/multitaper, custom cycles, ITC, trial power, baseline) · `mne_tfr_morlet`

### Advanced analysis (8)
`mne_decode` (MVPA) · `mne_connectivity` · `mne_compute_connectivity` (bands, pairs, estimators) · `mne_compute_noise_cov` · `mne_make_forward` ·
`mne_apply_inverse` · `mne_plot_source_estimate`

`mne_decoding_group_test` provides participant-level max-T or cluster-corrected inference.
Decoding reports separate numerical evidence, methods, interpretation, limitations
and a results draft requiring scientific review. The code escape hatch is not
equivalent to validated structured coverage of every MNE API.

### Export (1)
`mne_save`

Anything still not covered — BIDS, custom statistics, beamformers, autoreject — is reachable through
**`mne_run_code`** in the same live session. See [TOOLS_REFERENCE.md](https://github.com/Exekiel179/MNE-MCP/blob/HEAD/TOOLS_REFERENCE.md) for full
parameter details. Advanced dependencies are checked per feature and are not bundled.

---

## Development

```bash
# Compile check
python -m compileall src/mne_mcp

# Run tests
pytest

# CLI commands
mne-mcp status            # Check environment
mne-mcp setup --clients codex # Register in Codex + install skills
```

---

## License

MIT — see [LICENSE](https://github.com/Exekiel179/MNE-MCP/blob/HEAD/LICENSE)

## Documentation

- **项目介绍 / Introduction**: [docs/INTRODUCTION.md](https://github.com/Exekiel179/MNE-MCP/blob/HEAD/docs/INTRODUCTION.md) · [.docx](https://github.com/Exekiel179/MNE-MCP/blob/HEAD/docs/INTRODUCTION.docx)
- **安装说明 / Install guide**: [docs/INSTALL.md](https://github.com/Exekiel179/MNE-MCP/blob/HEAD/docs/INSTALL.md) · [.docx](https://github.com/Exekiel179/MNE-MCP/blob/HEAD/docs/INSTALL.docx)
- **使用介绍 / Usage guide**: [docs/USAGE.md](https://github.com/Exekiel179/MNE-MCP/blob/HEAD/docs/USAGE.md) · [.docx](https://github.com/Exekiel179/MNE-MCP/blob/HEAD/docs/USAGE.docx)
- **Quick start**: [QUICK_START.md](https://github.com/Exekiel179/MNE-MCP/blob/HEAD/QUICK_START.md)
- **Tool reference**: [TOOLS_REFERENCE.md](https://github.com/Exekiel179/MNE-MCP/blob/HEAD/TOOLS_REFERENCE.md)

## Links

- **MNE-Python**: https://mne.tools/
- **MCP Protocol**: https://modelcontextprotocol.io

