HTTP + SSE bridge for YADE MCP server - runs inside YADE Python environment
Project description
yade-mcp-bridge
HTTP + SSE bridge that runs inside a YADE process and enables execution tools for yade-mcp.
Features
- Async tasks with progress polling. Submit a long simulation script
(
execute_task) and poll its status and paginated log while it runs (check_task_status). - Live code during a run. Send
execute_codeat any time to inspect state or tune parameters mid-cycle — no need to bake probes into the script up front. It shares the simulation's__main__namespace. - Graceful interrupt. Stop a long cycling task on request
(
interrupt_task) without killing the YADE process. - Unified output capture. Python
printand YADE console output are interleaved in execution order in the task log. - Zero third-party dependencies. Pure stdlib HTTP + SSE.
Architecture
YADE's Qt GUI objects are main-thread-only, so the bridge keeps
execute_code on the main thread while running each task on its own
thread — a long O.run() then never blocks the server or live code.
flowchart TD
C[MCP client] -->|POST /command| S[HTTP + SSE server<br/>background thread]
C -.->|GET /events| S
S -->|execute_code → queue| Q[CodeExecutor<br/>one at a time]
Q -->|Qt timer GUI / daemon console| P[pump thread]
S -->|execute_task| T[ScriptRunner<br/>one thread per task]
T -->|O.run| Y[YADE C++ sim loop]
Y -.->|PyRunner callback| I[interrupt check]
S -.->|doorbells| C
- HTTP + SSE server (background thread). A threaded HTTP server takes
POST /<command>request/response calls and serves one long-livedGET /eventsSSE stream. It hands work off rather than touching YADE directly, so lightweight calls (status, interrupt) stay responsive even while a long task runs. - execute_code pump.
execute_codesubmissions are serialized through a queue drained by a single pump — so concurrent submissions run one at a time instead of racing on YADE state. The pump is a Qt timer on the main thread in GUI mode (mandatory foryade.qtobjects), or a background daemon thread in console mode. - Per-task threads.
ScriptRunnerruns eachexecute_taskscript on its own background thread, so a cyclingO.run()holds that thread, not the server or the main thread. - Cycle-gap interrupt. A
PyRunnercallback fires periodically duringO.run()to honor a pendinginterrupt_taskwithin ~one step. - SSE doorbells. Two no-payload server→client events
(
task_status_changed,console_entry) tell the client when to re-poll; all data travels over the plainPOST/GETcalls.
HTTP protocol
The bridge is the source of truth for the wire contract — yade-mcp is a
client of it. A request is POST /<command> with a JSON body carrying a
request_id; the response echoes the request_id.
| Command | Purpose | Key fields |
|---|---|---|
execute_task |
Submit a file-backed script as a tracked async task; the response returns the assigned task_id |
script_path, description |
check_task_status |
Poll a task's status and paginated log | task_id, skip_newest, limit, filter_text |
list_tasks |
List known tasks | offset, limit |
interrupt_task |
Request a graceful interrupt of a running task | task_id |
execute_code |
Run a snippet in the shared __main__ namespace |
code, timeout_ms |
console_history |
Read captured console output | limit |
Server→client SSE events on GET /events: task_status_changed,
console_entry. GET /health reports liveness and runtime mode.
Quick Start
In a YADE Python console, install the bridge using YADE's own interpreter:
import sys, subprocess
subprocess.check_call([sys.executable, "-m", "pip", "install", "--user", "yade-mcp-bridge"])
On PEP 668 externally-managed environments (pip refuses --user), see the bootstrap guide for a portable form.
Restart YADE, then in the Python console:
import yade_mcp_bridge
yade_mcp_bridge.start()
The bridge auto-detects the runtime: Qt timer in GUI mode, blocking poll in console mode.
Expected output (one line):
YADE MCP Bridge on http://localhost:9002, log: /your-working-dir/.yade-mcp/bridge.log
Detailed initialization logs go to bridge.log only (stdout shows warnings and errors).
Options
yade_mcp_bridge.start(
host="localhost", # Server host
port=9002, # Server port
mode="auto", # "auto", "gui", or "console"
)
Requirements
- Python >= 3.8
- YADE with Python bindings
- No third-party dependencies (stdlib HTTP + SSE)
Troubleshooting
| Symptom | Fix |
|---|---|
| Port in use | yade_mcp_bridge.start(port=9003), then set YADE_MCP_BRIDGE_URL=http://localhost:9003 |
| Connection failed | Check bridge is running, see .yade-mcp/bridge.log |
| PyRunner not available | YADE installation may lack PyRunner; interrupt checking during O.run() will be disabled |
Development
Run the bridge from source inside YADE:
import sys
sys.path.insert(0, '/path/to/yade-mcp/yade-mcp-bridge/src')
import yade_mcp_bridge
yade_mcp_bridge.start()
Code changes take effect on the next restart + start().
Relationship to MCP servers
This package is the in-process runtime only. Pair it with an MCP server that speaks its HTTP + SSE protocol — yade-mcp — for full client setup.
License: MIT (LICENSE).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yade_mcp_bridge-0.9.0.tar.gz.
File metadata
- Download URL: yade_mcp_bridge-0.9.0.tar.gz
- Upload date:
- Size: 34.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd2564ced9ec30539dd83eb472bfa8dd2b5041d6b93bba7d48d443381c0d3495
|
|
| MD5 |
28a0e29a1cd88bbe3be7df7c21862be6
|
|
| BLAKE2b-256 |
643b7418183234886602c8daa1e0789c6edcfc88ddab9126904eabcf321084f5
|
Provenance
The following attestation bundles were made for yade_mcp_bridge-0.9.0.tar.gz:
Publisher:
release-bridge.yml on yusong652/yade-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yade_mcp_bridge-0.9.0.tar.gz -
Subject digest:
fd2564ced9ec30539dd83eb472bfa8dd2b5041d6b93bba7d48d443381c0d3495 - Sigstore transparency entry: 2047589643
- Sigstore integration time:
-
Permalink:
yusong652/yade-mcp@9a521f270b3331cb875b76c79f9c84ea8d512b38 -
Branch / Tag:
refs/tags/bridge-v0.9.0 - Owner: https://github.com/yusong652
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-bridge.yml@9a521f270b3331cb875b76c79f9c84ea8d512b38 -
Trigger Event:
push
-
Statement type:
File details
Details for the file yade_mcp_bridge-0.9.0-py3-none-any.whl.
File metadata
- Download URL: yade_mcp_bridge-0.9.0-py3-none-any.whl
- Upload date:
- Size: 50.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10e36b40ccf2db01d91e8c339ad1789555e57e14763accc9e9206f21a8b1c058
|
|
| MD5 |
fb54e27d3d9cc88034f9ec6a14b3b7cc
|
|
| BLAKE2b-256 |
058b407b425c8f9adfc8849d7cf460e00e5f66e2be4099731081fa42fbe6a686
|
Provenance
The following attestation bundles were made for yade_mcp_bridge-0.9.0-py3-none-any.whl:
Publisher:
release-bridge.yml on yusong652/yade-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yade_mcp_bridge-0.9.0-py3-none-any.whl -
Subject digest:
10e36b40ccf2db01d91e8c339ad1789555e57e14763accc9e9206f21a8b1c058 - Sigstore transparency entry: 2047589728
- Sigstore integration time:
-
Permalink:
yusong652/yade-mcp@9a521f270b3331cb875b76c79f9c84ea8d512b38 -
Branch / Tag:
refs/tags/bridge-v0.9.0 - Owner: https://github.com/yusong652
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-bridge.yml@9a521f270b3331cb875b76c79f9c84ea8d512b38 -
Trigger Event:
push
-
Statement type: