{
  "markdown": "<!-- mcp-name: io.github.AImplifier/eeg-mcp -->\n\n<div align=\"center\">\n\n# ⚡🧠 eeg-mcp\n\n### Real-time EEG for AI agents — stream, replay, visualize, record, stimulate\n\n[![PyPI](https://img.shields.io/pypi/v/eeg-mcp?color=14b8a6&logo=pypi&logoColor=white&cacheSeconds=1800)](https://pypi.org/project/eeg-mcp/)\n[![Python](https://img.shields.io/badge/python-3.10%2B-14b8a6?logo=python&logoColor=white)](https://pypi.org/project/eeg-mcp/)\n[![Docs](https://img.shields.io/badge/docs-aimplifier.github.io-14b8a6)](https://aimplifier.github.io/eeg-mcp/)\n[![License](https://img.shields.io/badge/license-BSD--3--Clause-14b8a6)](LICENSE)\n\n**[Documentation](https://aimplifier.github.io/eeg-mcp/)** ·\n**[Tutorial](https://aimplifier.github.io/eeg-mcp/examples/tutorial-first-realtime-session/)** ·\n**[Hardware](https://aimplifier.github.io/eeg-mcp/hardware/)** ·\n**[Safety](https://aimplifier.github.io/eeg-mcp/safety/)** ·\n**[Tool Reference](https://aimplifier.github.io/eeg-mcp/tools/)**\n\n</div>\n\nA Model Context Protocol server that gives an AI agent one interface over the\n**live** EEG workflow: acquisition from ~66 [BrainFlow](https://brainflow.readthedocs.io)\nboards, wall-clock replay of existing recordings, stateful online DSP, a live\nbrowser monitor, crash-safe recording, and gated stimulation output.\n\nThe offline counterpart is **[neuro-mcp](https://github.com/AImplifier/neuro-mcp)**\n(MNE processing, source imaging, BIDS/EHR storage). This is the real-time half —\neverything that has to happen while the signal is still arriving.\n\n## Concept\n\n```mermaid\nflowchart LR\n    Researcher([\"🔬 BCI Researcher\"])\n    Clinician([\"🩺 Clinician\"])\n    Agent[[\"🤖 AI Agent\"]]\n    Server((\"eeg-mcp<br/>FastMCP · 47 tools\"))\n\n    Clinician -- talks to --> Agent\n    Researcher -- talks to --> Agent\n    Agent -- MCP --> Server\n\n    Server --> Acquire[\"Acquire<br/>66 boards · replay<br/>at true rate\"]\n    Server --> Process[\"Process<br/>stateful online DSP<br/>custom plugins\"]\n    Server --> Watch[\"Watch &amp; Record<br/>live monitor · HTML<br/>crash-safe .fif\"]\n    Server --> Stim[\"Stimulate<br/>LSL · TTL · TMS/tES<br/>3 safety gates\"]\n\n    classDef acq fill:#14b8a6,stroke:#0d9488,color:#fff\n    classDef proc fill:#4f8cff,stroke:#2f5fbf,color:#fff\n    classDef viz fill:#b06fe0,stroke:#7c3fae,color:#fff\n    classDef stim fill:#eb5757,stroke:#b93b3b,color:#fff\n    class Acquire acq\n    class Process proc\n    class Watch viz\n    class Stim stim\n```\n\nNobody calls a tool by hand — you talk to an agent in plain English and it\ndrives the 47 tools underneath. The\n**[tutorial](https://aimplifier.github.io/eeg-mcp/examples/tutorial-first-realtime-session/)**\nshows what that looks like end to end, with no hardware required.\n\n## What it does\n\n<table>\n<tr>\n<td width=\"50%\" valign=\"top\">\n\n**📡 Stream**\n\n66 BrainFlow board identifiers — OpenBCI, Muse, ANT Neuro, g.tec, Mentalab and\nmore — plus a synthetic board that needs no hardware. Samples land in a ring\nbuffer filled by a background thread, so tool calls read a live view instead of\nblocking on a device.\n\n</td>\n<td width=\"50%\" valign=\"top\">\n\n**⏪ Replay**\n\nPlay an EDF/BDF/GDF/SET/FIF or BrainFlow CSV *at the rate it was recorded*,\nre-emitting annotations as events at their original timings. Adds speed, seek,\npause and looping. A pipeline developed against a file runs **unchanged**\nagainst hardware.\n\n</td>\n</tr>\n<tr>\n<td width=\"50%\" valign=\"top\">\n\n**👁 Visualize**\n\nA loopback-bound, token-gated live browser view: rolling traces, event markers,\nband power, per-electrode quality, and transport controls. Plus self-contained\nHTML reports — no CDN, no external assets, opens on an air-gapped machine.\n\n</td>\n<td width=\"50%\" valign=\"top\">\n\n**💾 Record**\n\nWrite continuously to MNE-native `.fif` with the event log attached as\nannotations, plus a metadata row in a store **schema-compatible with\nneuro-mcp**. Crash-safe: an interrupted session is recoverable.\n\n</td>\n</tr>\n<tr>\n<td width=\"50%\" valign=\"top\">\n\n**🧩 Extend**\n\nPlug in your own real-time processor — feature extractor, classifier, artifact\ngate, or **EEG tokenizer for sequence models** — and it runs on the same footing\nas the built-ins, inside the acquisition loop.\n→ [Extending](https://aimplifier.github.io/eeg-mcp/extending/)\n\n</td>\n<td width=\"50%\" valign=\"top\">\n\n**⚡ Stimulate**\n\nOne `send_stim_event` contract over pluggable backends: LSL for software,\nBrainFlow's marker channel for sample-aligned embedding, serial/TTL and\ntemplated ASCII for hardware including TMS and tES — behind three safety gates.\n\n</td>\n</tr>\n</table>\n\n> [!NOTE]\n> **One event log.** Board markers, replayed annotations, dispatched\n> stimulations and manual notes all land in the same table on the same clock, with\n> absolute sample indices. A closed-loop run reconstructs afterwards with no clock join.\n\n## Install\n\n```bash\nconda create -n eeg-mcp python=3.11 -y && conda activate eeg-mcp\npip install eeg-mcp\n```\n\n<details>\n<summary><b>Optional extras and MCP client registration</b></summary>\n\n<br>\n\n```bash\npip install \"eeg-mcp[lsl]\"      # LSL marker outlets (PsychoPy, OpenViBE, ...)\npip install \"eeg-mcp[serial]\"   # serial/TTL trigger delivery to hardware\n```\n\nRegister with an MCP client using an **absolute path** to the env's interpreter:\n\n```json\n{\n  \"mcpServers\": {\n    \"eeg-realtime\": {\n      \"command\": \"/path/to/envs/eeg-mcp/bin/python\",\n      \"args\": [\"-m\", \"eeg_mcp\"]\n    }\n  }\n}\n```\n\nOr with the Claude Code CLI:\n\n```bash\nclaude mcp add eeg-realtime -- /path/to/envs/eeg-mcp/bin/python -m eeg_mcp\n```\n\n→ Full guide: **[Installation](https://aimplifier.github.io/eeg-mcp/installation/)**\n\n</details>\n\n## Quick start\n\nAsk your agent for the outcome; it picks the calls. No hardware required:\n\n```python\nstart_stream(session_id=\"s1\", board=\"synthetic\")\ncheck_signal_quality(session_id=\"s1\")          # before trusting anything\nset_filters(session_id=\"s1\", bandpass_low=1, bandpass_high=40, notch_freq=50)\nget_band_power(session_id=\"s1\", seconds=2)\nstart_monitor(session_id=\"s1\")                 # → open the returned URL\n```\n\nReplay a real recording as if it were live, then keep the record:\n\n```python\ninspect_recording(path=\"sub-04_rest.edf\")\nstart_replay(session_id=\"r1\", path=\"sub-04_rest.edf\", speed=1.0)\nget_events(session_id=\"r1\", origin=\"annotation\")\nexport_report(session_id=\"r1\", notes=\"Routine review.\")\n```\n\n<div align=\"center\">\n\n```mermaid\nflowchart LR\n    A[\"start_stream<br/><i>or</i> start_replay\"] --> B[check_signal_quality]\n    B --> C[set_filters]\n    C --> D[\"get_band_power<br/>get_psd\"]\n    C --> E[start_monitor]\n    C --> P[attach_processor]\n    A --> R[start_recording]\n    D --> S[send_stim_event]\n    P --> S\n    R --> X[stop_recording]\n    S --> X\n    E --> X\n    X --> Z[stop_stream]\n\n    classDef hot fill:#14b8a6,stroke:#0d9488,color:#fff\n    class A,X hot\n```\n\n</div>\n\n## Documentation\n\n| Guide | |\n|---|---|\n| 🚀 **[Installation](https://aimplifier.github.io/eeg-mcp/installation/)** | Environment, client registration, troubleshooting |\n| 📘 **[Tutorial](https://aimplifier.github.io/eeg-mcp/examples/tutorial-first-realtime-session/)** | End to end, no hardware needed |\n| ⏪ [Replay-Driven Development](https://aimplifier.github.io/eeg-mcp/examples/replay-driven-development/) | Build against a recording, deploy live |\n| 🔁 [Closed-Loop Neurofeedback](https://aimplifier.github.io/eeg-mcp/examples/closed-loop-neurofeedback/) | Feature → trigger, with a measured latency budget |\n| 🩺 [Live Clinical Review](https://aimplifier.github.io/eeg-mcp/examples/clinical-live-review/) | Visual review, annotation, reporting |\n| ⚡ [Stimulation Protocols](https://aimplifier.github.io/eeg-mcp/examples/stimulation-protocols/) | TMS and tES through the safety gates |\n| 🧩 [Extending](https://aimplifier.github.io/eeg-mcp/extending/) | Write a custom processor or EEG tokenizer |\n| 🔌 [Supported Hardware](https://aimplifier.github.io/eeg-mcp/hardware/) | All 66 boards, formats, stimulation transports |\n| ⚠️ [Safety](https://aimplifier.github.io/eeg-mcp/safety/) | **Read before connecting a stimulator** |\n| 🛠 [Tool Reference](https://aimplifier.github.io/eeg-mcp/tools/) | All 47 tools |\n\n## The one design decision worth knowing\n\n> [!IMPORTANT]\n> **Filtering happens in the producer thread, not at query time.**\n\nA stateful IIR filter must see every sample exactly once, in order. The common\nshortcut — filtering each query window independently — restarts the filter at\nevery window boundary and injects a transient each time. It is invisible in a\nband-power plot and **fatal for anything phase-sensitive**.\n\nSo the producer filters each chunk once as it arrives, carrying `sosfilt`\ndelay-line state forward, and writes to a second ring buffer. Queries just read.\n\n```mermaid\nflowchart LR\n    BF[Board / Recording] -->|poll| PR{{Producer thread}}\n    PR -->|raw chunk| RB[(Raw ring buffer)]\n    PR -->|stateful sosfilt| FB[(Filtered ring buffer)]\n    PR -->|markers &amp; annotations| EL[(Event log)]\n    PR -->|append| DISK[(.fif on disk)]\n    PR -->|streaming| PL[Your processors]\n    RB & FB & EL --> Q[MCP tools]\n\n    classDef hot fill:#14b8a6,stroke:#0d9488,color:#fff\n    class PR hot\n```\n\nThe test suite asserts chunked filtering matches whole-signal filtering to\n**1e-9**, *and* asserts as a control that the naive approach does not.\n\n| Consequence | |\n|---|---|\n| Filters are **causal** | No zero-phase option — that needs future samples. `stream_status` reports `group_delay_sec` |\n| Both buffers are kept | `read_window(filtered=false)` always gets raw signal, to check whether a feature is real or an artifact |\n| Indices are shared | An event's `sample_index` means the same thing in either buffer |\n\n> [!TIP]\n> Budget a closed loop as **group delay + poll interval + dispatch latency** —\n> measured at **~71 ms** in the reference configuration. Good for neurofeedback;\n> not adequate for phase-locked stimulation.\n\n## Stimulation safety\n\n> [!CAUTION]\n> **This software is not a medical device and has not been validated for\n> clinical use.** TMS and tES can cause harm, **including seizure**. Use only\n> under a protocol approved by your ethics board, on a rig whose device-level\n> interlocks are intact, with a trained operator present.\n\nThree gates apply to every hardware backend:\n\n| # | Gate | Effect |\n|---|---|---|\n| 1 | **Config** | Hardware backends refuse to open unless the server was started with `EEG_MCP_ALLOW_HARDWARE_STIM=1`. **An agent cannot set this.** |\n| 2 | **Arming** | `arm_stim` permits dispatch for a window that *expires*, so a stalled agent cannot resume and fire later |\n| 3 | **Limits** | Intensity, duration and interval are clamped; violations **raise** rather than silently saturate |\n\nNone of this replaces the interlocks on the device itself.\n\n> [!WARNING]\n> **The hardware backends are generic transports driven by command templates you\n> supply from your device's manual — not vendor drivers, and none has been tested\n> against a physical stimulator.** A plausible-looking untested driver would be\n> worse than none: it would fail silently while connected to something pointed at\n> a person's head.\n>\n> Start every protocol on `backend=\"log\"`, which accepts everything and emits nothing.\n\n## Verify\n\n```bash\npython testing/verify.py                    # core correctness\npython testing/verify_recording.py          # recording + metadata store\npython testing/verify_processing.py         # plugin processors\npython testing/persona_bci_researcher.py    # engineer workflow\npython testing/persona_clinician.py         # clinician workflow\n```\n\nAll five drive the real server through FastMCP's in-memory client and assert\nagainst **planted ground truth**:\n\n- a spike planted at an annotation onset lands at **t = 0 ± 0 ms** in the\n  extracted epoch — proving annotation timing, replay clock, ring-buffer\n  indexing and epoch extraction all agree;\n- a deliberately **broken plugin cannot stop acquisition** — throughput holds at 1.0;\n- hardware stimulation is **refused** while the config gate is unset.\n\n→ **[What is and is not covered](https://aimplifier.github.io/eeg-mcp/testing/)** —\nincluding an honest list of what has never been tested against real hardware.\n\n## License\n\nBSD-3-Clause. See **[LICENSE](LICENSE)** and **[NOTICE](NOTICE)**.\n\n<div align=\"center\">\n<br>\n\n**[⬆ back to top](#-eeg-mcp)** · Part of the\n**[AImplifier](https://github.com/AImplifier)** neuro toolchain ·\nsibling project **[neuro-mcp](https://github.com/AImplifier/neuro-mcp)**\n\n</div>\n",
  "bytes": 12459,
  "sha": "85094ee2297dd44ff8d10d85f11b1dcffc79a5656212264c4cdf9e4a8d14c44d",
  "repo_slug": "aimplifier/eeg-mcp",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/mcp_io_github_aimplifier_eeg_mcp_d11cebb1/readme"
}