Skip to main content

WebSocket bridge for ITASCA codes (PFC, FLAC3D, ...) - runs inside the product GUI to enable remote simulation control

Project description

itasca-mcp-bridge

English | 简体中文

PyPI

Runtime bridge that runs inside an ITASCA product process (PFC, FLAC, ...) and exposes the product's Python SDK as a WebSocket API, enabling execution tools for MCP servers such as pfc-mcp.

The bridge is product-neutral: it drives the host through the shared ITASCA command language / Python SDK rather than any product-specific API.

Features

  • Async tasks with progress polling. Submit a long simulation script (execute_task message) and poll its status and paginated output while it runs (check_task_status).
  • Live REPL during a run. Send execute_code against the running task's namespace at any time to inspect state or tune parameters mid-cycle — no need to bake probes into the script up front.
  • Graceful interrupt. Stop a long cycling task on request (interrupt_task) without killing the product.
  • Unified output capture. Python print and product console output (itasca.command() tables, list dumps, summaries) are interleaved in execution order in the task log.

Architecture

ITASCA's Python SDK is main-thread-only, so the bridge keeps the simulation on the main thread and serves remote requests around it with three parts:

flowchart TD
    C[MCP client] -->|WebSocket| S[asyncio server<br/>background thread]
    S -->|submit → Future| Q[MainThreadExecutor<br/>queue]
    Q -->|Qt timer / blocking poll| M[PFC main thread<br/>itasca SDK + solver]
    M -.->|callback at cycle| CB[interrupt check<br/>+ snippet executor]
    CB -.-> M
  • WebSocket server (background thread). An asyncio server receives messages, hands the work to the main thread, and awaits a Future. It never touches the SDK directly, so lightweight calls (status, interrupt) stay responsive even while a long task runs.
  • Main-thread queue. MainThreadExecutor holds a thread-safe queue that the main thread drains — via a Qt timer in GUI mode, or a blocking poll in console mode. Submitted task scripts (execute_task) run here.
  • Cycle-gap callbacks. A cycling task holds the main thread, so two itasca.set_callback hooks keep it reachable: an interrupt check that stops the run (interrupt_task), and a snippet executor that runs execute_code REPL calls in the gaps between cycles — sharing the task's __main__ namespace for live inspection and tuning.

WebSocket protocol

The bridge is the source of truth for the wire contract — MCP servers such as pfc-mcp and flac-mcp are clients of it. A request is a JSON object with a type and a request_id; the response echoes the request_id. The message types are product-neutral:

type (request) Purpose Key fields
execute_task Submit a file-backed script as a tracked async task 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 running task's __main__ (sync REPL) code, timeout_ms
get_working_directory Report the product process working directory
ping Liveness check

pfc_task is still accepted as a deprecated alias for execute_task, so older clients keep working during the transition.

Quick Start

Run inside the product's Python (GUI IPython console or console CLI):

Install from PyPI

In the product's IPython console:

from pip._internal.cli.main import main as pip_main
pip_main(["install", "--user", "itasca-mcp-bridge"])

import itasca_mcp_bridge
itasca_mcp_bridge.start()

websockets is pulled in automatically with a version matched to the embedded Python (9.1 for Python 3.6, 16.0 for Python 3.10). If it is missing or mismatched, install it the same way (pip_main(["install", "--user", "websockets==9.1"]) on Python 3.6, websockets==16.0 on 3.10).

Run from a source checkout

%run C:/path/to/itasca-mcp-bridge/start_bridge.py

Use forward slashes in the path. Do not wrap it in quotes.

Code changes take effect on the next %run, so this is the preferred workflow during development.

The bridge auto-detects the runtime: a Qt timer in GUI mode, a blocking loop in console mode.

Expected output:

============================================================
Itasca MCP Bridge Server
============================================================
  URL:  ws://localhost:9001
  Log:  /your-working-dir/.itasca-mcp-bridge/bridge.log
============================================================

Requirements

  • An ITASCA product with an embedded Python interpreter.
    • Verified: PFC 6.0 / 7.0 / 9.0.
    • FLAC3D: the bridge's core SDK/command mechanisms are verified compatible; full end-to-end validation is in progress.
  • Python >= 3.6 (PFC 6/7 use Python 3.6; PFC 9 uses Python 3.10).
  • websockets (==9.1 on Python 3.6, ==16.0 on Python 3.10), installed automatically as a dependency.

Troubleshooting

Symptom Fix
Server won't start Re-run the install/start steps in the product's IPython console; check .itasca-mcp-bridge/bridge.log
websockets version mismatch In the product IPython console: from pip._internal.cli.main import main as pip_main; pip_main(["install", "--user", "websockets==16.0"]) (use 9.1 on Python 3.6)
Port in use itasca_mcp_bridge.start(port=9002), then point your MCP client's bridge URL at ws://localhost:9002
Connection failed Confirm the bridge is running and the port is reachable; see .itasca-mcp-bridge/bridge.log
No task execution / MCP cannot connect If execution tools return ok=false, error.code=bridge_unavailable, error.details.reason=cannot connect to bridge service, confirm itasca_mcp_bridge.start() is running and your MCP client's bridge URL matches

Relationship to MCP servers

This package is the in-process runtime only. Pair it with an MCP server that speaks its WebSocket protocol — for example pfc-mcp — for full client setup.

License: MIT.

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

itasca_mcp_bridge-0.1.6.tar.gz (67.1 kB view details)

Uploaded Source

Built Distribution

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

itasca_mcp_bridge-0.1.6-py3-none-any.whl (61.3 kB view details)

Uploaded Python 3

File details

Details for the file itasca_mcp_bridge-0.1.6.tar.gz.

File metadata

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

File hashes

Hashes for itasca_mcp_bridge-0.1.6.tar.gz
Algorithm Hash digest
SHA256 e4c288ff632bcbef35c7f30e2e78ced2b0474b528113f5714e722cad7d677384
MD5 e158f83394c56ffd73f8f847e46717d5
BLAKE2b-256 b25dc12fdd51511b4914924e3218ef326b89c43c92a67deecc3f03c8bff285e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for itasca_mcp_bridge-0.1.6.tar.gz:

Publisher: publish.yml on yusong652/itasca-mcp-bridge

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

File details

Details for the file itasca_mcp_bridge-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for itasca_mcp_bridge-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 1b0de7c33c57dc50769780276e4a824449cf385089216eb77418acdde5633cde
MD5 2bf7280b5cf8b487dc951d75be71cd65
BLAKE2b-256 a18815fb40d54c16babe66155ab745faae50a06e6d641a4bdf41548c73d2b08a

See more details on using hashes here.

Provenance

The following attestation bundles were made for itasca_mcp_bridge-0.1.6-py3-none-any.whl:

Publisher: publish.yml on yusong652/itasca-mcp-bridge

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