Skip to main content

yade-mcp-bridge

PyPI

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_code at 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 print and 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-lived GET /events SSE 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_code submissions 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 for yade.qt objects), or a background daemon thread in console mode.
  • Per-task threads. ScriptRunner runs each execute_task script on its own background thread, so a cycling O.run() holds that thread, not the server or the main thread.
  • Cycle-gap interrupt. A PyRunner callback fires periodically during O.run() to honor a pending interrupt_task within ~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 plain POST/GET calls.

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).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yade_mcp_bridge-0.10.0.tar.gz (35.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yade_mcp_bridge-0.10.0-py3-none-any.whl (51.7 kB view details)

Uploaded Python 3

File details

Details for the file yade_mcp_bridge-0.10.0.tar.gz.

File metadata

  • Download URL: yade_mcp_bridge-0.10.0.tar.gz
  • Upload date:
  • Size: 35.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for yade_mcp_bridge-0.10.0.tar.gz
Algorithm Hash digest
SHA256 9c08d445fe5a070c14a440d0b3ca0ed8a4a38f7839a3bacd2377d0b37306d98e
MD5 a5982e51bdc17310322d0042e95f5c91
BLAKE2b-256 548a9ba42f549633de7f3407f56484a75f159ba7c48abeaec7ece409ded2eae7

See more details on using hashes here.

Provenance

The following attestation bundles were made for yade_mcp_bridge-0.10.0.tar.gz:

Publisher: release-bridge.yml on yusong652/yade-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file yade_mcp_bridge-0.10.0-py3-none-any.whl.

File metadata

File hashes

Hashes for yade_mcp_bridge-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8abff8c7814aa6268b4a715e572affc7aa0ff179f06bf12996012d63e8f6298a
MD5 415e86037837247325dbcacb1c95033e
BLAKE2b-256 97ce1d23bad2a0214a29dabd99cf08d4139443c861d579e2104017501410c4a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for yade_mcp_bridge-0.10.0-py3-none-any.whl:

Publisher: release-bridge.yml on yusong652/yade-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.10.0 This release

2 files

0.9.0

2 files

0.8.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.4

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page