Skip to main content
Glama

MS-MCP

面向 Windows 与 BIOVIA Materials Studio 的外部 Model Context Protocol(MCP)服务器。它让 Codex 或其他 MCP 客户端通过官方 MaterialsScript 运行时执行建模、Forcite、DMol3、CASTEP、GUI 队列和结果读取,并提供本地 Dashboard。

当前版本:0.2.0-hardened.1。项目不是 BIOVIA/Dassault Systèmes 官方产品;使用者必须自行取得并遵守合法的 Materials Studio 许可证,仓库不包含软件本体、许可证或专有数据。

本仓库是可复现部署的源码发行版,固定基于 DrYe1109/MS-MCP 提交 991a1b3ab2ad985529fb645dc82f47528a2a1297。所有机器路径、凭据和运行数据均通过 本机配置生成,不进入版本控制。硬化差异见 HARDENING.md。

调用链与安全模型

Codex / MCP client → stdio → MS-MCP policy gates → MaterialsScript
                                              ├→ licensed Materials Studio
                                              ├→ isolated workspace
                                              └→ optional local Dashboard / SSH monitor

默认插件配置只启用七个检查与读取工具。结构编辑、GUI 队列和真实计算必须由操作者 显式扩展工具列表;真实计算还必须先完成 dry-run 审阅,再取得与操作和目标绑定的 短期一次性授权。完整组件与信任边界见 架构说明。

Related MCP server: materials-studio-mcp-moc

主要能力

  • 检查 Materials Studio、RunMatScript.bat、工作区和会话状态。

  • 创建/导入结构,维护当前 GUI 文档,并执行常用结构编辑。

  • 执行 Forcite、DMol3、CASTEP 任务与预设工作流。

  • 通过可选的 Materials Studio GUI 循环把脚本送入当前打开的项目。

  • 从受限 HTTPS 白名单下载 CIF,并限制响应大小。

  • 准备远程 CASTEP 任务,Dashboard 可通过 SSH 只读监控 Gateway 作业目录。

  • 所有生成文件默认限制在独立工作区;任意 MaterialsScript 和外部输入默认关闭。

系统要求

  • Windows 10/11(64 位)。

  • BIOVIA Materials Studio,且已安装 MaterialsScript;必须能找到: MS_INSTALL_ROOT\etc\Scripting\bin\RunMatScript.bat。

  • Node.js 20 或更高版本,包含 npm.cmd。

  • Codex 或其他支持 stdio MCP 的客户端。

  • 可选:Windows OpenSSH Client(只在远程 Dashboard 监控时使用)。

最快安装

下载 Release 压缩包或克隆仓库后,不要把项目放入随后会删除或改名的临时目录。安装路径可以自定,后续由配置脚本生成该机器专用配置。

  1. 双击 Configure-MS-MCP.bat,逐项确认 Node、Materials Studio、工作区等路径。

  2. 双击 Install-MS-MCP.bat,以 npm ci 安装锁定依赖并检查发布文件。

  3. 双击 Test-MS-MCP.bat,验证路径、安全默认值和 MCP stdio 通信。

  4. 打开生成的 config\codex-ms-mcp.local.toml,把完整内容合并到 %USERPROFILE%\.codex\config.toml。

  5. 完全退出并重启 Codex,在 MCP 列表中确认 MS-MCP 可用。

完整逐步说明、路径示例和安装后修改方法见 安装与配置指南。

配置 BAT 会生成什么

Configure-MS-MCP.bat 是唯一推荐的本机配置入口,内部调用 PowerShell 完成验证和安全写入:

  • config\ms-mcp.local.bat:供启动、测试、Dashboard、GUI 循环和 SSH 脚本统一读取。

  • config\codex-ms-mcp.local.toml:供复制到 Codex 的 MCP 配置块。

这两个文件包含本机绝对路径,已由 .gitignore 排除,不能上传 GitHub。仓库只保留不含真实机器信息的 .mcp.json、.env.example 与 config\ms-mcp.example.bat。

必须根据机器修改的路径

变量/配置

含义

何时必须修改

NODE_EXE / command

node.exe 的绝对路径

Node 安装位置变化或换电脑

NPM_CMD

与 Node 配套的 npm.cmd

Node 安装位置变化

MS_INSTALL_ROOT

Materials Studio 安装根目录

版本、盘符或安装目录变化

MS_MCP_WORK_ROOT

可写的独立任务工作区

换电脑、迁移数据或调整存储盘

MCP args

本仓库 src\index.js

仓库移动、改名或重新解压

MCP cwd

本仓库根目录

仓库移动、改名或重新解压

MS_MCP_MODEL_ROOT

已有 Materials Studio 模型目录

仅使用 Chapter 3 同步时设置

MS_MCP_REMOTE_SSH_TARGET

user@host

仅使用远程监控时设置

MS_MCP_REMOTE_SSH_KEY

SSH 私钥绝对路径

使用非默认密钥或用户目录变化

MS_MCP_REMOTE_JOBS_ROOT

Linux Gateway 作业根目录

远端版本、用户或 Gateway 根目录变化

仓库移动后不要逐个修改启动脚本;重新运行 Configure-MS-MCP.bat,再用新生成的 TOML 更新 Codex 即可。

启动方式

MCP 服务器

正常情况下由 Codex 按 TOML 自动启动。调试时可运行:

Run-MS-MCP.bat

该进程使用 stdio 协议,命令窗口看似等待输入是正常现象;不要向 stdout 添加日志。

Dashboard

双击 Start-MS-MCP-Dashboard.bat,浏览器打开 http://127.0.0.1:4877/。端口可在重新配置时修改。MCP 也可在后台启动 Dashboard,但默认不会强制打开浏览器。

需要登录 Windows 后自动启动时,先完成配置与测试,再运行 Install-Dashboard-Autostart.bat。快捷方式使用相对仓库定位;若移动仓库,重新安装自启快捷方式。

Materials Studio GUI 循环

要把任务写入当前由用户打开的 Materials Studio 项目时:

  1. 先运行 Configure-MS-MCP.bat。

  2. 在 Materials Studio 中打开目标项目。

  3. 从 Materials Studio 的脚本界面运行 materialscript\mcp_loop_gui.pl;或在正确的 Materials Studio 会话条件下使用 materialscript\start_mcp_loop.bat。

  4. 队列位于 %MS_MCP_WORK_ROOT%\.mcp-queue,停止标记为 .mcp-queue\stop。

GUI 循环必须在 Materials Studio GUI 环境中运行,不能把普通 RunMatScript.bat 进程误当成已打开项目的 GUI 上下文。

远程 CASTEP Dashboard 监控(可选)

重新运行 Configure-MS-MCP.bat,填写 user@host 和远程 Gateway jobs 路径,然后运行 Setup-Dashboard-SSH.bat。脚本创建独立 Ed25519 密钥、把公钥加入远端 authorized_keys,并验证非交互登录。Dashboard 不保存服务器密码。

这只配置作业目录监控;Materials Studio Gateway、队列、许可证和计算核数仍需在 Materials Studio Job Control 中按实际服务器配置。

安全默认值

  • MS_MCP_ALLOW_ARBITRARY_SCRIPT=0:禁用任意 MaterialsScript。

  • MS_MCP_EXPOSE_RAW_TOOLS=0:不暴露原始任意脚本工具。

  • MS_MCP_ALLOW_GUI_QUEUE=0:默认不允许结构化 GUI 队列工具。

  • MS_MCP_ALLOW_COMPUTE=0:默认不提交任何消耗许可证或计算资源的任务。

  • MS_MCP_ALLOW_EXTERNAL_INPUTS=0:禁止读取工作区外输入。

  • CIF 仅允许配置的 HTTPS 主机,默认最大 10 MiB。

  • Dashboard 默认只监听 127.0.0.1;写操作默认关闭。启用写操作时必须配置至少 24 字符令牌。

  • 工作区路径经边界与 junction/symlink 检查,防止任务越界写入。

更详细的部署原则见 LOCAL-HARDENING.md,漏洞报告见 SECURITY.md。

开发与验证

在已经加载正确环境变量的终端中:

npm ci
npm run check
npm run smoke
npm run security-smoke
npm run mcp-smoke

Windows 用户直接运行 Test-MS-MCP.bat 更简单,它会加载生成的本机配置。涉及真实 Forcite/DMol3/CASTEP 的计算仍应在授权的测试模型和服务器上单独验证。

仓库结构

MS-MCP/
├─ .codex-plugin/               Codex 插件清单
├─ .mcp.json                    相对路径、默认只读的 MCP 配置
├─ skills/                      Materials Studio 操作与授权边界
├─ src/                         MCP 服务器与 MaterialsScript 生成逻辑
├─ materialscript/              Materials Studio GUI 循环
├─ GUI-Dashboard/               本地 Dashboard
├─ scripts/                     验证、解析、同步与远程准备脚本
├─ config/                      示例配置;本机生成配置不会上传
├─ docs/                        安装与配置文档
├─ .github/workflows/           安装、清单、隐私与安全 CI
├─ examples/                    示例输入
├─ Configure-MS-MCP.bat         分步配置入口
├─ Install-MS-MCP.bat           锁定依赖安装
├─ Test-MS-MCP.bat              完整本机验证
└─ Run-MS-MCP.bat               手动 stdio 启动入口

GitHub 上传清单与排除项见 RELEASE-FILES.md。

常见问题

找不到 RunMatScript.bat:MS_INSTALL_ROOT 填得太上层或太下层。应直接指向包含 etc\Scripting 的 Materials Studio 版本目录,然后重新配置。

移动仓库后 Codex 启动失败:重新运行配置 BAT,并替换 Codex TOML 中旧的 command、args、cwd 与环境路径。

Node 可用但 npm.cmd 不存在:安装完整的 Node.js Windows 发行版,而不是只复制 node.exe。

Dashboard 可打开但没有结构/作业:先检查工作区与当前 session;远程作业还需要 SSH target、key 和 jobs root 三项同时有效。

MCP 修改不到当前 GUI 项目:确认 GUI 循环是在目标 Materials Studio 会话中运行,而不是只启动了独立 MaterialsScript 进程。

贡献与许可

提交 Issue/PR 前请阅读 CONTRIBUTING.md,不要提交许可证文件、真实结构数据、服务器地址、私钥、本机配置或计算输出。项目采用 MIT License。公开发行版不包含 BIOVIA 软件、许可证文件、专有结构/力场、私钥、服务器信息或任何用户计算结果。

致谢与视频教程

  • 本项目初始代码基于 shenghhe-svg/shengh_he,感谢原作者的工作与分享。

  • 安装、配置及使用视频教程可在抖音搜索:抖音号 Au.Tom,昵称 Dr.小叶。

独立的上游来源与教程声明见 NOTICE.md。

Available Tools

32 tools
ms_castepC

Run a CASTEP task or preset calculation on an input document located under the MS-MCP work root. Presets include Energy, GeometryOptimization, Frequency/phonons, DOS, band structure, charge density, and density difference.

Inputs: inputDocument (required), task, cores, dryRun, +3 more.

ms_codex_configA

Return an MCP server config snippet that can be pasted into Codex settings.

Inputs: no named parameters.

ms_create_moleculeA

Create a standalone molecule/crystal document from explicit atoms and bonds using MaterialsScript. For the already-open GUI project, prefer ms_gui_create_current to avoid duplicate GUI documents.

Inputs: atoms (required), documentName (required), bonds, project.

ms_forciteC

Run a Forcite task on an input document located under the MS-MCP work root.

Inputs: inputDocument (required), task, cores, dryRun, +3 more.

ms_gui_add_vacuum_currentB

Add vacuum to the current GUI periodic document in place only when the user explicitly asks for vacuum. For an already-built 3D cell, extend_lattice increases the chosen lattice length while preserving Cartesian atom positions; for 2D surfaces, vacuum_slab uses CrystalBuilder VacuumSlab.

Inputs: thickness (required), axis, mode, exportFile, +5 more.

ms_gui_apply_currentC

Queue a MaterialsScript body that modifies the current GUI document in place. Use this for 'on this molecule...' edits.

Inputs: body (required), save, label, exportFile, +2 more.

ms_gui_castep_currentB

Queue a CASTEP calculation on the current GUI document. Supports Energy, GeometryOptimization, phonon/frequency, DOS, band structure, charge density, and density difference presets.

Inputs: cores, dryRun, quality, exportFile, +7 more.

ms_gui_cleave_surface_vacuum_currentB

Cleave a surface from the current GUI crystal and build a vacuum slab through Materials Studio SurfaceBuilder + CrystalBuilder. Use only when the user explicitly asks to cleave/build a surface or create a vacuum slab by the manual surface workflow.

Inputs: slabThickness (required), vacuumThickness (required), h, k, +10 more.

ms_gui_create_crystal_currentA

Create or replace the current GUI document as a periodic crystal/unit cell from lattice parameters and atom coordinates. Before using this for a new crystal, first try ms_gui_find_cif_import_current against open CIF sources; use manual construction only when no reliable open CIF is found or the user provides credentials/API access for a restricted source. Do not add vacuum here unless the user explicitly requested vacuum in the initial cell parameters.

Inputs: a (required), b (required), c (required), atoms (required), +13 more.

ms_gui_create_currentA

Create or replace the current GUI document from a MaterialsScript body. Before using this for a new structure, first try ms_gui_find_cif_import_current against open CIF sources; use manual construction only when no reliable open CIF is found or the user provides credentials/API access for a restricted source. By default it reuses the existing current/same-name document and rebuilds it in place to avoid duplicate .xsd files.

Inputs: body (required), documentName (required), forceNew, exportFile, +1 more.

ms_gui_dmol3_optimize_currentB

Queue a DMol3 GeometryOptimization on the current GUI document and organize calculation outputs under a dedicated calculation name/folder.

Inputs: cores, charge, dryRun, quality, +7 more.

ms_gui_download_cif_import_currentA

Download a CIF from an open supported source or direct CIF URL, store it once in the active task session, optionally import it into the open GUI project, and make it current. Use this before modeling when a reliable database CIF is available. Do not use this to bypass login/license walls; credentialed databases require user-provided existing credentials/API configuration.

Inputs: url, codId, source, fileName, +3 more.

ms_gui_edit_currentB

Queue a basic molecule-building edit on the current GUI document, such as adding/deleting bonds, changing an atom element, adding/deleting atoms, recalculating bonds, Clean, or AdjustHydrogen.

Inputs: x, y, z, atom, +13 more.

ms_gui_find_cif_import_currentA

Search open crystallographic databases for a reliable CIF, download it once, import it into the current GUI project, and make it current. Use this before manually building a new crystal or molecular crystal. It only uses open sources; if the requested structure appears to require credentialed databases such as ICSD/CSD/Materials Project API, return candidates/reason so the user can provide access instead of bypassing login walls.

Inputs: query (required), formula, fileName, maxResults, +4 more.

ms_gui_forcite_optimize_currentC

Queue a Forcite GeometryOptimization on the current GUI document using a manual-like calculation folder layout.

Inputs: cores, dryRun, quality, exportFile, +9 more.

ms_gui_import_currentB

Queue an import into the open Materials Studio GUI project and make the imported document the current document. Import external source files only; do not import XSD files that MS-MCP just exported from the current GUI document.

Inputs: file (required), exportFile, ballAndStick, documentName.

ms_gui_make_supercell_currentC

Build a supercell from the current GUI periodic document in place, using Materials Studio BuildSuperCell.

Inputs: a, b, c, surface2D, +4 more.

ms_gui_model_currentB

Queue a basic Materials Studio modeling-toolbar operation on the current GUI document, such as Clean or AdjustHydrogen, without creating a new document.

Inputs: operation, exportFile, ballAndStick, documentName, +1 more.

ms_gui_new_structure_currentA

Unified entry point for creating a new GUI structure. Decision order: if an open and reliable CIF can be found, download it and import it as the initial XSD/current GUI document; if a likely source exists but requires an account/API such as ICSD/CSD/Materials Project/OQMD, return candidates and ask the user for access instead of bypassing authentication; if no usable CIF source is available, fall back to controlled MCP GUI manual creation when manual atoms/cell data are provided. Build the primitive/base document first; do not name the initial document after a planned supercell size. Prefer this tool over direct create/import tools for first-time structure creation.

Inputs: query (required), a, b, c, +22 more.

ms_gui_prepare_remote_castep_batchB

Prepare independent native CASTEP geometry-optimization jobs or compatibility Script Job drivers. The default native_castep mode stages one XSD plus one CASTEP settings document per structure/spin task for separate submission from the CASTEP Calculation dialog, giving each calculation its own CASTEP Job Control entry and native convergence graphs.

Inputs: tasks (required), batchName, commonSettings, submissionMode, +1 more.

ms_gui_project_dirB

Ensure and return the current MS-MCP task/session output directory under the workspace.

Inputs: no named parameters.

ms_gui_set_current_documentC

Set the current Materials Studio GUI document for subsequent stateful operations. This does not create a file.

Inputs: documentName (required), exportFile.

ms_gui_set_lattice_currentC

Set lattice parameters on the current GUI crystal document in place.

Inputs: a, b, c, beta, +5 more.

ms_gui_start_project_sessionA

Start a new MS-MCP task/session folder under the workspace, such as YYYY-MM-DD-1, for subsequent GUI modeling and calculation outputs. Use only when the user explicitly asks for a new task/session; normal modeling should reuse the Dashboard/current session.

Inputs: folderName, allowExistingSessionSwitch.

ms_gui_stateA

Get the stateful GUI session target: current document, current exported file, last job, and history.

Inputs: no named parameters.

ms_list_workspaceC

List files under the MS-MCP work root.

Inputs: subdir, maxFiles.

ms_prepare_compute_authorizationC

Issue a short-lived one-time token for one reviewed licensed calculation. Configure this tool to require explicit approval in Codex.

Inputs: target (required), operation (required), ttlSeconds.

ms_queue_statusB

Inspect the optional MS-MCP GUI queue folders.

Inputs: no named parameters.

ms_read_textC

Read a text output file under the MS-MCP work root.

Inputs: file (required), maxBytes.

ms_remote_castep_batch_statusB

Read the local preparation markers, submission receipt, and downloaded result summary available for a remote CASTEP batch.

Inputs: batchName (required).

ms_remote_castep_record_submissionB

Record one Materials Studio Job Control receipt. For native_castep preparation, call this once per calculationName after submitting its XSD from the CASTEP Calculation dialog.

Inputs: jobId (required), gateway (required), batchName (required), status, +6 more.

ms_statusA

Check Materials Studio paths, RunMatScript availability, and MS-MCP workspace.

Inputs: no named parameters.

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    C2.8/5.0

    Scored across 32 tools

    Disambiguation2/5

    Multiple tools overlap significantly: ms_gui_apply_current, ms_gui_model_current, and ms_gui_edit_current all cover in-place editing actions like Clean/AdjustHydrogen, while structure creation is split across ms_gui_new_structure_current, ms_gui_find_cif_import_current, ms_gui_download_cif_import_current, ms_gui_import_current, ms_gui_create_current, and ms_gui_create_crystal_current. An agent would need deep knowledge of the intended decision hierarchy to reliably choose between them.

    Naming Consistency4/5

    The ms_ prefix and snake_case are used consistently, and the ms_gui_*_current convention for stateful GUI operations is a strong pattern. Some names are awkward or less uniform, such as ms_gui_download_cif_import_current and ms_gui_cleave_surface_vacuum_current, and standalone tools like ms_forcite, ms_castep, and ms_codex_config do not follow the same verb-first style, but the overall pattern is still readable.

    Tool Count2/5

    With 32 tools, this server exceeds the practical MCP surface size and falls into the too-many category. Many of the structure-import and GUI-edit variants could be consolidated into fewer parameterized tools without losing scope.

    Completeness3/5

    The server covers a broad workflow: structure creation/import, editing, simulation engines, GUI queue inspection, file management, and remote CASTEP batch handling. However, result/property retrieval is largely limited to reading text files and batch status, there is no cleanup/delete tool, and DMol3 support is restricted to geometry optimization, leaving notable gaps for some workflows.

    Maintenance

    ActivityNo data
    ResponsivenessSyncing

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      C
      quality
      C
      maintenance
      Enables MCP clients to execute Materials Studio modeling and computation tasks via MaterialsScript runtime, with a local Dashboard for monitoring.
      33
      32
      MIT
    • F
      license
      C
      quality
      D
      maintenance
      MCP server for BIOVIA Materials Studio 2023 on Windows, providing controlled preparation of Forcite and CASTEP inputs, model building, and LAMMPS/VMD pre-processing with reproducible, auditable workflows and strict scientific boundaries.
      53
      1
      -
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables MCP clients like Codex to control Ansys Workbench and ICEM CFD locally, executing scripts, managing projects, and running simulations.
      1
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      Enables MCP clients to control the local Open Science research application, including creating projects, starting or continuing research sessions, inspecting progress and plans, canceling runs, and reading generated artifacts.
      12
      Apache 2.0