Skip to content

Feature: Attach to running openMSX instances #18

Description

@pvmm

Problem

Currently mcp-openmsx can only control emulator instances it spawns itself via emu_control.launch. There's no way to connect to an openMSX instance the user started independently (e.g. from the command line). This limits integration in workflows where the user already has an openMSX session open doing some inspection and wants the AI agent help in a more tight collaboration.

Use case

This feature is particularly valuable for interactive bug hunting and reverse engineering workflows. A user often has openMSX already running a ROM or disk program they're debugging — stepping through code in an IDE, setting breakpoints, inspecting memory. Being able to attach the agent to that live session lets the agent help diagnose issues in real time: reading registers, scanning memory, analyzing VDP state, or suggesting breakpoints, all without disrupting the user's existing setup or forcing them to restart the emulator from scratch.

Proposed solution

Add attach and detach commands to emu_control that connect to an already-running openMSX instance via its control socket, without taking ownership of the process lifecycle.

Design

Instance discovery — on Linux/macOS, openMSX writes Unix domain sockets at /tmp/openmsx-<username>/socket.<PID>. On Windows, the situation is more involved and since I don't actually use Windows, a solution will be proposed later.

Proposed interface:

emu_control.attach

  • Without socketPath: auto-scans, connects if exactly one instance found, returns a list for agent elicitation if multiple found.
  • With socketPath: connects directly to the specified instance.
  • Skips auto-configuration (renderer, save_settings_on_exit, reverse replay) — the instance keeps its own settings.

emu_control.detach — disconnects without killing the openMSX process.

Lifecycle changesemu_close, destroy, forceClose, and the command queue guard are updated so attached instances are cleanly disconnected rather than killed.

Scope

Area Changes
openmsx.ts scanRunningInstances, emu_connect, querySocketIdentity, queryTcpIdentity, connectUnix, connectTcp. Updated guards in emu_close, forceClose, destroy, writeData.
server_tools.ts attach/detach commands, socketPath parameter, instances output schema.
Tests 7 new tests: direct connect, auto-connect, no-instances, multi-instance, detach success/failure.
Docs Skills, launch reference, tool reference, README updated.

Questions to resolve

  • Should attached instances be allowed to call powerOff/reset, or should those be blocked for non-owned processes?
  • On Windows, should the attach scan also support direct-sspi mode (TCP without the socket file), or only stdio-proxy?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions