EEGLAB-MCP:面向AI智能体的 MATLAB/EEGLAB脑电分析自动化系统
EEGLAB-MCP: An Automated MATLAB/EEGLAB Analysis System for MCP-Compatible AI Agents
摘要
本文提出 EEGLAB-MCP,一个基于模型上下文协议(Model Context Protocol, MCP)的服务器,将支持 MCP 的 AI 智能体与 MATLAB/EEGLAB 脑电分析生态连接,使研究者能够以自然语言驱动数据检查、预处理、分段、独立成分分析(ICA)、事件相关电位(ERP)、频谱分析与质量控制等环节。与让大语言模型直接生成并执行 MATLAB 代码的做法不同,本系统把可执行的操作固定在20 个带参数模式与前置条件检查的结构化工具之内:Python 侧完成路径白名单、数值范围与奈奎斯特校验,MATLAB 侧由固定的动作分派再次校验,全程不拼接脚本、不向客户端暴露接受任意 MATLAB 代码字符串的执行接口;常驻 MATLAB 工作进程承担首次启动开销(约 5.6 s),此后单次调用的排队开销约 0.2 s。系统内置一套方法学知识层:47 条带编号与依据定位的方法学声明、39 个具名方法配置与 39 个前置检查,覆盖滤波、重参考、ICA、ASR、分段、基线与统计等环节。方法学检查在 Python 侧执行,依据 MATLAB 以只读方式读回的数据集事实与轻量质量指标判定;判定本身不启动目标分析任务,被阻断的调用不产生任何分析结果文件,放行阻断项必须给出不少于 20 个字符的理由,理由与受阻条目一并留档。系统以统一的 JSON 信封返回结果,把“程序是否跑通”与“科学结论是否成立”显式分离,主动列出未执行的检查项与解释边界;原始数据只读,全部产物附带 SHA-256 与完整参数记录。在 EEGLAB 官方示例数据上,端到端流程 7/7 通过,关键数值经独立核验一致(采样率 128 Hz、32 通道、30504 采样点、154 个事件、80 个有效分段),29 项 MATLAB 原生测试与 43 项 Python 测试全部通过。原生测试同时暴露出一个真实缺陷:EEGLAB 13 的 pop_runica 在 R2023a 上因图形句柄类型变化而无法运行,系统改由直接调用 runica 完成分解。本文还与 MNE-MCP 作了对照,讨论方法学知识组织与测试策略的可移植之处。本文介绍系统的架构、设计取舍与验证结果,并讨论其局限、风险与使用建议,旨在为 MATLAB 生态下的脑电分析提供一条可控、可追溯、可复现的智能化路径。
Abstract
I present EEGLAB-MCP, a Model Context Protocol (MCP) server that connects MCP-compatible AI agents to the MATLAB/EEGLAB ecosystem, allowing researchers to drive data inspection, preprocessing, epoching, independent component analysis (ICA), event-related potentials (ERP), spectral analysis and quality control through natural-language dialogue. Unlike approaches in which a large language model writes and executes MATLAB code, the system fixes the executable surface at 20 schema-validated tools with explicit preconditions: path allow-listing, numeric-range and Nyquist checks run in Python, and a second validation runs inside MATLAB against a fixed action dispatcher, so that no script is ever assembled from user input and no channel accepting arbitrary MATLAB code strings is exposed. A persistent MATLAB worker absorbs the start-up cost (about 5.6 s for the first call) and brings subsequent calls to about 0.2 s. The server carries a methodology layer of 47 versioned, source-located claims, 39 named method profiles and 39 preflight checks covering filtering, re-referencing, ICA, ASR, epoching, baseline correction and statistics. Checks run in Python against facts that MATLAB reads back from the dataset header, plus lightweight quality metrics; a blocked call starts no analysis job and writes no analysis output; proceeding past a blocked condition requires a written reason of at least 20 characters, recorded together with the obstructed items. Every result is returned in a unified JSON envelope that separates execution success from scientific validity, lists the checks that were not performed, and carries SHA-256 digests and full parameter records, while raw data remain read-only. On the official EEGLAB sample dataset the end-to-end chain passed 7/7 steps, key quantities were independently verified (128 Hz, 32 channels, 30,504 samples, 154 events, 80 valid epochs), and all 29 MATLAB-native checks and 43 Python tests passed. The native suite also exposed a real defect: EEGLAB 13's pop_runica cannot run under R2023a because figure handles are objects rather than numbers, so decomposition now calls runica directly. We further compare the design and interoperability of the system with MNE-MCP. Architecture, design trade-offs, validation results, limitations and usage recommendations are discussed.关键词
模型上下文协议/EEGLAB/MATLAB/脑电/大语言模型/可复现性Key words
Model Context Protocol/EEGLAB/MATLAB/EEG/Large Language Model/Reproducibility引用本文复制引用
魏楚光.EEGLAB-MCP:面向AI智能体的 MATLAB/EEGLAB脑电分析自动化系统[EB/OL].(2026-10-30)[2026-11-04].https://chinaxiv.org/abs/202611.00012.学科分类
生物科学理论、生物科学方法