Skip to main content

HTTP + SSE bridge for YADE MCP server - runs inside YADE Python environment

Project description

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

Project details


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.8.0.tar.gz (34.6 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.8.0-py3-none-any.whl (50.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: yade_mcp_bridge-0.8.0.tar.gz
  • Upload date:
  • Size: 34.6 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.8.0.tar.gz
Algorithm Hash digest
SHA256 921b2ea868024d27e68fc2559c608315532f01c7832f04d7efd459aa825e32f5
MD5 9caf2affaeb482a73320199632ad4c97
BLAKE2b-256 5bd5c8ce669bfb0fcfec33ff01c2c4c905f3cc900ceab98857f0fd4dd9d0b7fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for yade_mcp_bridge-0.8.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.8.0-py3-none-any.whl.

File metadata

File hashes

Hashes for yade_mcp_bridge-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 32238bdb8c820ec34465c96bcef3f5629096bffbc2e9aa6bbec2e430a723abcf
MD5 eb9f6f9b0eb45e7136531ccf5e0eb93f
BLAKE2b-256 b0a128e54c06e0881c0b2badfd4a83f2d30a0299fafff3a53018f2af3a59f5e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for yade_mcp_bridge-0.8.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.

Supported by

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