Marea.Mcp.Runner (marea v0.0.1-rc.1)

Copy Markdown View Source

Executes a single Marea command inside an isolated task and returns its captured output.

Designed for use from the MCP server: each tools/call is realised by:

  1. Stopping any currently running Marea.Service.
  2. Spawning a Task whose group leader is swapped for a StringIO so all command output is captured.
  3. Setting the per-process stop mode to :raise, so Marea.Lib.stop/1 raises Marea.Stop instead of halting the VM.
  4. Invoking Marea.main_inline/1 with the synthesized argv.
  5. If the command returned a deferred {:exec, cmd}, running the shell command inline (still inside the capture).
  6. Returning {captured_output, status} to the caller.

Argv synthesis

The MCP arguments map is translated to argv using the leaf's option/flag spec (see Marea.Mcp.Tools.specs_for/2):

  • each option present in the map becomes [long, to_string(v)],
  • each flag that is true becomes [long],
  • unknown keys are rejected up-front to keep behaviour predictable across clients.

Subcommand path is prepended verbatim, dasherised via Marea.Lib.to_dashes/1 to match how Optimus matches subcommand names.

Summary

Types

Outcome of a single tool invocation.

Functions

Builds argv for the given tool path + arguments and executes it.

Runs an already-built argv list and returns {output, status}.

Types

status()

@type status() :: :ok | {:error, String.t()}

Outcome of a single tool invocation.

Functions

run(path, arguments)

@spec run([atom()], map()) :: {String.t(), status()}

Builds argv for the given tool path + arguments and executes it.

Returns {captured_output, status}.

run_argv(argv)

@spec run_argv([String.t()]) :: {String.t(), status()}

Runs an already-built argv list and returns {output, status}.

Public so the marea mcp call debugging subcommand can reuse the same execution path without going through argv synthesis.