YADE MCP Server

io.github.yusong652由 GitHub 账号 yusong652 发布v0.11.2更新于 Oct 30, 2026

MCP server for YADE — open-source DEM engine. Browse API docs, run simulations, manage tasks.

概览

AI 生成的概览

把 AI 助手连接到开源离散元引擎 YADE:浏览其 Python API 文档,并在运行中的 YADE 会话里执行模拟。

可以做什么
  • 浏览并按关键词搜索 YADE Python API 的类树与文档,离线可用、无需桥接服务
  • 在运行中的 YADE 进程里同步执行 Python 代码,调用之间状态会保留
  • 把模拟脚本作为后台任务提交,查看状态与输出、列出任务历史、中断或取消任务
  • 读取 YADE 进程的运行时上下文,包括控制台历史和模拟状态
适用场景
适合在搭建或调试 YADE 离散元模型时使用:让助手查阅 API 类、运行建模代码、在后台启动长时间模拟,并在不中断模拟的情况下查看结果。
运行要求
通过 uvx 在本地运行(需安装 uv),并需要已安装 YADE。执行类工具还要求把 yade-mcp-bridge 安装到 YADE 自带的 Python 解释器中,并在 YADE 控制台里启动桥接服务,默认监听 localhost 的 9002 端口;换端口时用 --bridge-url 指定。文档类工具无需桥接服务。
安装前请注意
执行类工具会在你正在运行的 YADE 进程里运行任意 Python 代码,且副作用会持续保留,可能改动或删除模拟状态与文件。桥接服务是 HTTP 服务,为容器场景绑定到所有网卡会使其暴露在 localhost 之外。任务脚本、输出和控制台历史会被留存并传给助手。

安装

在 SourceWeft 中

  1. 打开 控制台中的 YADE MCP Server,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

yade-mcp

[yade-mcp header]

English | 简体中文

[PyPI] [Downloads] [GitHub stars] [Glama] [License: MIT] [Python 3.10+]

O.engines += [LLM()] # yet another engine.

yade-mcp connects AI agents to YADE, the open-source discrete element method engine, through the Model Context Protocol. The agent browses the YADE API, runs code in a live YADE session, launches long simulations as background tasks, and reads what you type at the YADE console.

[yade-mcp demo]

Tools (7)

Two documentation tools (no bridge needed) and five execution tools (bridge required):

ToolPurposeBridge
yade_browse_apiWalk the YADE Python class treeNo
yade_query_apiBM25 keyword search across the APINo
yade_execute_codeRun Python in the live YADE process; returns synchronouslyYes
yade_execute_taskSubmit a script as a long-running background taskYes
yade_check_task_statusInspect a running or finished task (output, status)Yes
yade_interrupt_taskStop a running task at an iteration boundary, or cancel a queued oneYes
yade_list_tasksList submitted tasks with metadataYes

Example Prompts

  • "Set up a triaxial compression test on a dense packing and plot deviatoric stress against axial strain"
  • "Build an irregular particle as a level set body and drop it onto a plane"
  • "The simulation is still running, check the unbalanced force without stopping it"
  • "Look up how GlobalStiffnessTimeStepper picks the timestep, then add it to this model"
  • "The command I just typed in the console raised an error, what went wrong?"
  • "List what was run yesterday and summarize what each task produced"

First-time Setup

Prerequisites

  • YADE installed
  • uv installed. It provides the uvx launcher that agent clients use to run yade-mcp; without it the client reports No such file or directory when starting the server.
  • An AI agent: Claude Code, Codex CLI, Gemini CLI, or any MCP-capable client

Agentic Setup (Recommended)

Copy this to your AI agent and let it self-configure:

text
Fetch and follow this bootstrap guide end-to-end:https://raw.githubusercontent.com/yusong652/yade-mcp/master/docs/agentic/yade-mcp-bootstrap.md

Manual Setup

1. Register the MCP server with your agent (use the line for yours):

bash
# Claude Codeclaude mcp add yade-mcp -- uvx yade-mcp
# Codex CLIcodex mcp add yade-mcp -- uvx yade-mcp
# Gemini CLIgemini mcp add yade-mcp uvx yade-mcp

Or fill in the MCP config file by hand:

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

2. Install the bridge into YADE's Python.

YADE embeds one specific interpreter (the system python3 for the Debian and Ubuntu packages, or the one it was built against). A conda or venv Python is a different interpreter, and a package installed there is invisible to YADE. The reliable way to hit the right one is to install from inside YADE, where sys.executable is that interpreter. In the YADE console:

python
import sys, subprocesssubprocess.check_call([sys.executable, "-m", "pip", "install", "--user", "yade-mcp-bridge"])

Two things can go wrong here:

  • No module named pip: the interpreter has no pip. Install it with the system package manager, for example sudo apt install python3-pip.
  • externally-managed-environment (Debian 12, Ubuntu 23.04 and later): pip refuses --user by default. Add "--break-system-packages" after "--user" in the command above.

Then exit and restart YADE so the new package directory is picked up.

The bridge is proposed for inclusion in YADE itself (yade-dev/trunk !1187). Once it ships with YADE, this step goes away and the bridge starts with from yade import mcpbridge.

3. Start the bridge in the YADE console:

python
import yade_mcp_bridgeyade_mcp_bridge.start()

It prints one line: YADE MCP Bridge on http://localhost:9002, log: <cwd>/.yade-mcp/bridge.log.

Verify

Restart your AI agent and ask it to check that it is connected to YADE. It calls yade_execute_code; ok: true in the response means the whole chain works.

Daily Startup

Once first-time setup is done, each new YADE session only needs the bridge started again. In the YADE console:

python
import yade_mcp_bridgeyade_mcp_bridge.start()

The MCP client config persists.

Configuration

Port

The bridge listens on 9002 by default. To use another port, pass it to start():

python
yade_mcp_bridge.start(port=9008)

The MCP server connects to 9002 unless told otherwise, so register it with the matching URL:

json
{  "mcpServers": {    "yade-mcp": {      "command": "uvx",      "args": ["yade-mcp", "--bridge-url", "http://localhost:9008"]    }  }}

Container

When YADE runs inside a container, bind the bridge to all interfaces so it is reachable from outside:

python
yade_mcp_bridge.start(host="0.0.0.0")

Publish the port when starting the container (for Docker, -p 9002:9002).

Features

  • Live REPL in the running YADE process: yade_execute_code runs Python in the session's own namespace, so state persists between calls. It keeps working while a task runs, for reading intermediate results without stopping the simulation.
  • Task lifecycle: submit a script as a background task, tail its output, stop it at an iteration boundary, fix and resubmit. Tasks queue up and run one at a time, so a multi-stage pipeline can be submitted in one go.
  • Task history across sessions: every task's script, output, and final state stay on record. A new agent session lists what was run and picks up without being told.
  • Console input reaches the agent: lines you type at the YADE console arrive in the agent's context on its next call, so you can work at the console and with the agent at the same time.
  • API documentation without a bridge: the class tree and a BM25 search over the YADE Python API work offline, from a corpus refreshed against current YADE releases.
  • Multi-client: works with Claude Code, Codex CLI, Gemini CLI, GitHub Copilot CLI, OpenCode, toyoura-nagisa, and other MCP clients.

Troubleshooting

See Troubleshooting in the bootstrap guide.

Contributing

See CONTRIBUTING.md for development setup and guidelines.

License

MIT, see LICENSE.

来源:README.md,提交 613a243

工具

7

yade_browse_api

Yade Browse Api

Browse YADE's Python API as a YADE-native class tree. The tree is rooted in YADE's real inheritance hierarchy: paths mirror the class's __mro__ up to its category root. No shortcuts — always drill through parents.

输入参数path

yade_query_api

Yade Query Api

Search YADE API documentation by keywords (like grep). Returns matching class/function names with descriptions ranked by relevance. Use yade_browse_api for full documentation of a specific class. When to use: - You have keywords but don't know the exact class name - Examples: "friction material", "gravity engine", "contact force", "triaxial stress", "sphere create", "hertz mindlin" Related tools: - yade_browse_api: Get full documentation for a known class path

输入参数limitquery必填

yade_execute_task

Yade Execute Task

Submit a Python script for asynchronous execution in YADE. Returns a task_id immediately; the script is queued and runs in the background. Tasks run one at a time in submit order (they share the YADE process and its single simulation state), so a multi-stage pipeline can be submitted in one go — each stage starts when the previous one finishes. Use the companion tools to manage the task lifecycle: - yade_check_task_status: poll output, progress, and final status - yade_interrupt_task: stop a running task or cancel a queued one - yade_list_tasks: browse task history (also shows queue order) Use this for production simulation runs, long O.run() cycles, and any operation that may take minutes or longer. For quick queries and REPL-style testing, use yade_execute_code. O.engines[0] holds a PyRunner that belongs to yade-mcp-bridge (its command mentions "mcp bridge"). The script does not need to keep it: assign O.engines as usual, the bridge re-adds the PyRunner before every O.run().

输入参数description必填script_path必填

yade_check_task_status

Yade Check Task Status

Check status and output for a submitted YADE task.

输入参数limitfiltertask_id必填skip_newestwait_seconds

yade_list_tasks

Yade List Tasks

List tracked YADE tasks with pagination. Tasks are listed newest first. Queued (pending) tasks run one at a time in submit order, so among the pending entries the one furthest down the list runs next.

输入参数limitskip_newest

yade_interrupt_task

Yade Interrupt Task

Stop a running YADE task, or cancel one still waiting in the queue. A task that has not started yet is simply removed from the queue and ends in status ``canceled`` (``method`` reports ``canceled_while_queued``). For a running task, two cancellation paths are applied together by the bridge: - ``flag_only`` — sets an interrupt flag that YADE's PyRunner tick observes between simulation iterations (graceful path for ``O.run`` tasks). - ``flag_and_async_exc`` — in addition, injects a ``TaskInterrupt`` exception into the script thread, so pure-Python deadloops with no ``O.run`` on the stack are terminated too. The response ``method`` field reports which path ran. When async-exc is refused (e.g. target thread is a Dummy-N boost::python frame), ``async_exc_skipped_reason`` explains why. Namespace after interrupt: the YADE ``__main__`` namespace is shared between tasks and ``yade_execute_code`` calls. Any variables the interrupted script had already defined — including ``O`` state — are preserved. There's no need to re-run the whole script to continue work: inspect state with ``yade_execute_code`` or resume via a fresh ``yade_execute_task`` that only runs the remaining logic.

输入参数task_id必填

yade_execute_code

Yade Execute Code

Execute Python code synchronously in the running YADE process. Returns stdout immediately. Code runs in the YADE Python environment where yade modules are already imported; side effects persist. This tool remains responsive EVEN WHILE a simulation task is running (submitted via yade_execute_task). Use it as a live REPL to inspect simulation state in real time — no need to pre-script print statements. Typical uses: - Query simulation state: O.bodies count, current iteration - Create/modify bodies, engines, interactions - Read or set material properties - Live inspection during a running simulation (e.g. check stress tensor, coordination number, energy balance, or capture viewport screenshots when GUI is available) - Development and REPL-style testing O.engines[0] holds a PyRunner that belongs to yade-mcp-bridge (its command mentions "mcp bridge"). Ignore it: assign O.engines as usual, the bridge re-adds the PyRunner before every O.run(). Unlike yade_execute_task, this tool is fire-and-return: the response contains the full output. It is NOT tracked by yade_list_tasks and cannot be interrupted or polled. Timeout behaviour: on timeout the bridge attempts to abort the running code. The response is an error envelope (``ok=false``) whose ``error.code`` is one of: - ``interrupted`` — the code was running a simulation cycle (``O.run``) and was paused cleanly at an iteration boundary. For long simulations or solving to equilibrium, switch to yade_execute_task — it tracks progress and stops cleanly via yade_interrupt_task. - ``terminated`` — a non-cycle abort succeeded (async exception injection); the pump thread is free, but YADE state may be partially modified by the code that ran before the abort fired. Inspect state before retrying. - ``timeout`` — abort failed (code stuck in a C extension, or nested inside a running task's PyRunner tick); the bridge may still be blocked. Restart if unresponsive. WARNING: For anything expected to take more th

输入参数code必填timeout

版本历史

2
  1. v0.11.2最新Oct 22, 2026
  2. v0.1.5Sep 16, 2026

评分

已满足适用检查项的 90%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分
  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具必需15 分
  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分