diff --git a/pkgs/mcpx/docs/compare/matrix-code-mode.md b/pkgs/mcpx/docs/compare/matrix-code-mode.md index e1a6d50a49..59b892b08c 100644 --- a/pkgs/mcpx/docs/compare/matrix-code-mode.md +++ b/pkgs/mcpx/docs/compare/matrix-code-mode.md @@ -94,7 +94,7 @@ https://developers.cloudflare.com/dynamic-workers/examples/codemode/, **blog** = | B7 | answer without `console.log` | — | stdout only for snippets (`internal/execsvc/execsvc.go:607-625`) | — | last expression is the result (`v2:packages/codemode/README.md:20`) | auto-returns the last expression (dwex "`createCodeTool`") | | B8 | discovery ergonomics | — | catalogue on request; search without paging (`internal/codegen/emit.go:1121`) | catalogue in the tool description automatically; paged search (`v1:packages/opencode/src/tool/registry.ts:283-289`; `v1:packages/codemode/README.md:206`) | catalogue in instructions, deltas, pinned tools (`v2:packages/core/src/codemode/catalog.ts:79-84`) | search also finds vetted snippets (how "Platform SDK") | | B9 | tool names | `mcp_` prefix keeps namespaces clear of reserved words (`.lootbox/src/lib/type_system/client_generator.ts:654`) | no reserved-word, prelude or collision checks (`internal/codegen/ts.go:397-418`; `internal/config/config.go:407-416`) | real names, bracket notation, no collisions (`v1:packages/opencode/src/mcp/catalog.ts:117`) | same (`v2:packages/codemode/README.md:77-78`) | reserved words suffixed, collisions throw, namespaces validated (mcp, step 2; api "DynamicWorkerExecutor") | -| B10 | harness integration | — | plugin `mcpx_exec`: no abort, session, cwd or live status; reads a missing field (`plugin/opencode/mcpx/daemon.ts:452-455`; `plugin/opencode/mcpx-session.ts:621-623`) | permission check and hooks per child call, live status, cancel (`v1:packages/opencode/src/tool/code-mode.ts:141-147`, `:216-217`, `:262-274`) | same, plus the session id on every child call (`v2:packages/core/src/tool/mcp.ts:51-69`) | approval per connector method (how "Approvals through abort and replay") | +| B10 | harness integration | — | plugin `mcpx_exec`: no abort, session, cwd or live status; reads a missing field (`plugin/core/daemon.ts:452-455`; `plugin/opencode/mcpx-session.ts:621-623`) | permission check and hooks per child call, live status, cancel (`v1:packages/opencode/src/tool/code-mode.ts:141-147`, `:216-217`, `:262-274`) | same, plus the session id on every child call (`v2:packages/core/src/tool/mcp.ts:51-69`) | approval per connector method (how "Approvals through abort and replay") | | B11 | long upstream calls | — | fixed 120 s, no progress token (`internal/defaults/defaults.json:6`; `internal/mcpclient/client.go:438`) | progress token resets the timeout (`v1:packages/opencode/src/tool/code-mode.ts:154-158`) | 12 h call timeout (`v2:packages/core/src/mcp/client.ts:34`) | — | | B12 | questions from upstream servers | — | broker and policy; no script hook (`internal/daemon/server.go:422-424`; `docs/protocol.md:379`) | — | UI form, form and URL modes (`v2:packages/core/src/mcp/client.ts:143`) | agent handlers on both paths (client "Elicitation") | | B13 | images for a vision model | — | artifacts by reference; model needs `resources/read` (`docs/exec.md:259-275`) | attached to the model as files (`v1:packages/opencode/src/tool/code-mode.ts:89-100`) | same (`v2:packages/core/src/codemode/tool.ts:139-147`) | — | diff --git a/pkgs/mcpx/docs/compare/register/content-types.md b/pkgs/mcpx/docs/compare/register/content-types.md index c4c0499ae1..0bc4636b71 100644 --- a/pkgs/mcpx/docs/compare/register/content-types.md +++ b/pkgs/mcpx/docs/compare/register/content-types.md @@ -343,7 +343,7 @@ Status column: **mcpx @ 05c78b2**. Legend and citation conventions: [../README.m a `resources/read`. - **Effort.** S. - **Risk.** Med: the plugin's `mcpx_exec` never declares `artifacts`, so its images are not intercepted and must be - printed as base64 to be seen (inferred from `plugin/opencode/mcpx/daemon.ts:452-455`). + printed as base64 to be seen (inferred from `plugin/core/daemon.ts:452-455`). - **Detail.** Artifacts are served by a random 128-bit id, not the content hash, because a hash is guessable (`docs/exec.md:200-207`). - **Sources.** `v1:packages/opencode/src/tool/code-mode.ts:89-100`; `v2:packages/core/src/codemode/tool.ts:139-147`; `docs/exec.md:259-275` diff --git a/pkgs/mcpx/docs/compare/register/plugin-apis.md b/pkgs/mcpx/docs/compare/register/plugin-apis.md index 38d5eaf4cf..dee633a577 100644 --- a/pkgs/mcpx/docs/compare/register/plugin-apis.md +++ b/pkgs/mcpx/docs/compare/register/plugin-apis.md @@ -158,7 +158,7 @@ Status column: **mcpx @ 05c78b2**. Legend and citation conventions: [../README.m process (v1 the server Worker, v2 the daemon). - **Where.** opencode v1 and v2. - **mcpx @ 05c78b2.** The plugin reaches the daemon socket with Bun's `fetch(url, {unix})`; its own comment notes that - Node's fetch ignores the option (`plugin/opencode/mcpx/daemon.ts:348-351`). + Node's fetch ignores the option (`plugin/core/daemon.ts:348-351`). - **Value to mcpx.** + low: holds for the nix build installed here. - **Effort.** S. - **Risk.** Low: a Node build of v2 would break unix-socket fetch. @@ -224,15 +224,15 @@ Status column: **mcpx @ 05c78b2**. Legend and citation conventions: [../README.m `create.before` hook). - **Where.** opencode v1 only. - **mcpx @ 05c78b2.** Already independent of `$`: it spawns with `node:child_process` `execFile` - (`plugin/opencode/mcpx/daemon.ts:41`) and talks to the daemon over the unix socket - (`plugin/opencode/mcpx/daemon.ts:352`). + (`plugin/core/daemon.ts:41`) and talks to the daemon over the unix socket + (`plugin/core/daemon.ts:352`). - **Value to mcpx.** + low: nothing to port. - **Effort.** S. - **Risk.** Low. - **Detail.** `docs/opencode-plugin.md:103` says mcpx's plugin "uses `$` for exactly two things"; the source at 05c78b2 uses `execFile` and the socket, and does not destructure `$`. `import("node:child_process")` still works in v2 because plugins are imported unsandboxed. -- **Sources.** `v1:packages/plugin/src/index.ts:65` "$: BunShell"; `v2:packages/plugin/src/promise/shell.ts:12` "readonly \"create.before\": ShellCreateBefore"; `plugin/opencode/mcpx/daemon.ts:41`; `docs/opencode-plugin.md:103` +- **Sources.** `v1:packages/plugin/src/index.ts:65` "$: BunShell"; `v2:packages/plugin/src/promise/shell.ts:12` "readonly \"create.before\": ShellCreateBefore"; `plugin/core/daemon.ts:41`; `docs/opencode-plugin.md:103` ## PLG-13 `shell.env` hook vs `shell.hook("create.before")` without session @@ -604,7 +604,7 @@ Status column: **mcpx @ 05c78b2**. Legend and citation conventions: [../README.m - **Where.** opencode v1 and v2. mcpx's daemon has an event stream and `/v1/exec` can stream frames, but the plugin does not use them; lootbox has nothing. - **mcpx @ 05c78b2.** The plugin's `mcpx_exec` makes one blocking POST and publishes nothing; its `execute(args)` does - not even take the tool context (`plugin/opencode/mcpx-session.ts:615-625`; `plugin/opencode/mcpx/daemon.ts:451-455`). + not even take the tool context (`plugin/opencode/mcpx-session.ts:615-625`; `plugin/core/daemon.ts:451-455`). - **Value to mcpx.** + med: a user watching a two-minute browser script sees nothing until it ends. - **Effort.** S — read `/v1/exec` with `output: "stream"` and map log and emit frames to metadata. - **Risk.** Low. @@ -619,13 +619,13 @@ Status column: **mcpx @ 05c78b2**. Legend and citation conventions: [../README.m - **Where.** opencode v1 and v2. mcpx CLI: a killed CLI process kills its local script's process group. lootbox: the CLI's WebSocket closes but the daemon's `deno` keeps running. Cloudflare: unverified. - **mcpx @ 05c78b2.** `postRaw` takes only an optional timeout, and `exec()` passes neither timeout nor signal - (`plugin/opencode/mcpx/daemon.ts:380-386`, `:452-455`). The daemon would cancel on client disconnect + (`plugin/core/daemon.ts:380-386`, `:452-455`). The daemon would cancel on client disconnect (`internal/daemon/routes_exec.go:252`), but the plugin never disconnects. - **Value to mcpx.** + med: Esc on a runaway browser script should stop it. - **Effort.** S — pass the tool context's abort signal to `fetch`. - **Risk.** Med: runaway scripts keep holding pooled browsers. - **Detail.** The progress-cancellation area records how an HTTP disconnect propagates to the upstream call. -- **Sources.** `v1:packages/opencode/src/tool/code-mode.ts:262-274`; `v1:packages/opencode/src/tool/code-mode.ts:155` "signal: input.ctx.abort,"; `plugin/opencode/mcpx/daemon.ts:380-386`; `internal/daemon/routes_exec.go:252` +- **Sources.** `v1:packages/opencode/src/tool/code-mode.ts:262-274`; `v1:packages/opencode/src/tool/code-mode.ts:155` "signal: input.ctx.abort,"; `plugin/core/daemon.ts:380-386`; `internal/daemon/routes_exec.go:252` ## PLG-39 Harness session and working directory reach the script @@ -635,15 +635,15 @@ Status column: **mcpx @ 05c78b2**. Legend and citation conventions: [../README.m directory. - **Where.** opencode v2; mcpx bash path yes, plugin tool path no. - **mcpx @ 05c78b2.** `exec()` sends only `{source, options: {output: "structured"}}` - (`plugin/opencode/mcpx/daemon.ts:452-455`); with `options.session` empty the service falls back to `"exec-"+runID` + (`plugin/core/daemon.ts:452-455`); with `options.session` empty the service falls back to `"exec-"+runID` (`internal/execsvc/execsvc.go:382`). - **Value to mcpx.** + high: with the session, a browser persists across `mcpx_exec` calls in one opencode session, which `AGENTS.md:87-89` promises; with `cwd`, `repo` and `cwd` scopes resolve to the right repository. - **Effort.** S — pass `ctx.sessionID` and `ctx.directory` as `options.session` and `options.cwd`. - **Risk.** High: repo-scoped servers resolve against the daemon's directory, and session-scoped browsers are recreated on every call and linger (process-model area). -- **Detail.** `call()` in the same class already accepts a session (`plugin/opencode/mcpx/daemon.ts:462-467`). -- **Sources.** `plugin/opencode/mcpx/daemon.ts:452-455`; `internal/execsvc/execsvc.go:382` "session := firstNonEmpty(opts.Session, ropts.Env[\"MCPX_SESSION\"], \"exec-\"+runID)"; `plugin/opencode/mcpx-session.ts:664-670`; `v2:packages/core/src/tool/mcp.ts:69` "sessionID: context.sessionID," +- **Detail.** `call()` in the same class already accepts a session (`plugin/core/daemon.ts:462-467`). +- **Sources.** `plugin/core/daemon.ts:452-455`; `internal/execsvc/execsvc.go:382` "session := firstNonEmpty(opts.Session, ropts.Env[\"MCPX_SESSION\"], \"exec-\"+runID)"; `plugin/opencode/mcpx-session.ts:664-670`; `v2:packages/core/src/tool/mcp.ts:69` "sessionID: context.sessionID," ## PLG-40 Plugin `mcpx_exec` reads a field the daemon never returns @@ -652,7 +652,7 @@ Status column: **mcpx @ 05c78b2**. Legend and citation conventions: [../README.m the entire envelope instead of the script's stdout. - **Where.** mcpx plugin only. opencode's own `execute` returns the value, then warnings, then logs. - **mcpx @ 05c78b2.** `plugin/opencode/mcpx-session.ts:619-623`; `Result` fields at `internal/execsvc/execsvc.go:201-213`. - The client type even declares `output?: string` (`plugin/opencode/mcpx/daemon.ts:451`). + The client type even declares `output?: string` (`plugin/core/daemon.ts:451`). - **Value to mcpx.** + med: the model should see stdout, then error, then compact logs, not `runId`, `emits: []`, `artifacts: []` and `durationMs` on every call. - **Effort.** S — use `out.stdout` (or `out.error`). diff --git a/pkgs/mcpx/docs/decisions/0003-declared-vs-enforced-capabilities.md b/pkgs/mcpx/docs/decisions/0003-declared-vs-enforced-capabilities.md index a0dda49a11..2c6bcc3f4b 100644 --- a/pkgs/mcpx/docs/decisions/0003-declared-vs-enforced-capabilities.md +++ b/pkgs/mcpx/docs/decisions/0003-declared-vs-enforced-capabilities.md @@ -290,7 +290,7 @@ they must, since an enforced row without its case fails test 2. The unix socket stays as it is. Then "file permissions are the access control" is true of both listeners. The fix is in `internal/daemon/server.go` and the clients that read the record - (`internal/cli/client.go`, `plugin/opencode/mcpx/daemon.ts`, + (`internal/cli/client.go`, `plugin/core/daemon.ts`, `docs/plugin-discovery.md`). - **`script.permissions`**: a profile other than `all` on a runtime with no permission model is refused before anything runs, naming the runtime and the diff --git a/pkgs/mcpx/docs/environment.md b/pkgs/mcpx/docs/environment.md index eb3d20fe1b..00118a2581 100644 --- a/pkgs/mcpx/docs/environment.md +++ b/pkgs/mcpx/docs/environment.md @@ -90,60 +90,60 @@ and read by name for that reason. -| variable | set by | when | what it is | read by | -| --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `MCPX_SESSION` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); an event consumer | always | the session key this run's tool calls are leased under: --session, else MCPX_SESSION_ID, else one minted for the run | the generated client, which sends it with every call | -| `MCPX_SESSION_ID` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); an event consumer; the opencode plugin; the plugin loader, for a discovered plugin | the CLI passes through the value it was given, which may be empty; the plugin sets it at every plugin.env level | the session the host assigned. Unlike MCPX_SESSION it survives from one command to the next, so it is what session-scoped servers key on | `mcpx` run inside the script or shell, as its session when --session is not given | -| `MCPX_PARENT_SESSION_ID` | `mcpx exec` / `mcpx run`; an event consumer; the opencode plugin | the CLI passes through what it was given; the daemon passes the caller's parent session into a script run's environment; the plugin at plugin.env=full, when there is a parent | the session that spawned this one, so a parent agent and its subagents can share a server | `mcpx` run inside the script or shell, and the generated client for parent-session scoping | -| `MCPX_EPHEMERAL` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | always | 1 when the session key was minted for this run alone, so its instances may be stopped as soon as it ends | the generated client | -| `MCPX_RUN` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | always | this execution's run id, which groups the artifacts it produces | the generated client, when storing an artifact | -| `MCPX_INPUT` | `mcpx exec` / `mcpx run` | mcpx exec and mcpx run, locally and with --remote; not when mcpx serve collects the output | report: nothing in this run can answer a server's question mid-call, so a call that asks one exits 75 with the question instead of waiting for it to expire | the generated client, sent as X-Mcpx-Input | -| `MCPX_HOOK_NAME` | the declared-hook runner, for a hook it runs | always | the declared name of the hook being run | the hook itself | -| `MCPX_HOOK_PHASE` | the declared-hook runner, for a hook it runs; the exec service (`/v1/exec`, `mcpx_exec`) | always | the hook's phase; always observe for config-declared hooks, the exec hook's phase (pre, post, onError, onSuccess) for a per-call exec hook | the hook itself | -| `MCPX_HOOK_POINT` | the exec service (`/v1/exec`, `mcpx_exec`) | always | the point the hook is attached to; script for per-call exec hooks in this version | the hook itself | -| `MCPX_HOOK_ERROR` | the exec service (`/v1/exec`, `mcpx_exec`) | only for a hook running because the script failed; truncated to 1024 bytes | the error the hook is running for, in one line; the full hook context is JSON on stdin | the hook itself | -| `MCPX_HOOK_EVENT_KIND` | the declared-hook runner, for a hook it runs | always | the kind of the event the hook is running for; the full event is JSON on stdin | the hook itself | -| `MCPX_HOOK_EVENT_SEQ` | the declared-hook runner, for a hook it runs | always | the event's sequence number on the daemon's bus | the hook itself | -| `MCPX_HOOK_EVENT_SERVER` | the declared-hook runner, for a hook it runs | empty when the event names no server | the server the event is about | the hook itself | -| `MCPX_HOOK_EVENT_SESSION` | the declared-hook runner, for a hook it runs | empty when the event belongs to no session | the session the event belongs to | the hook itself | -| `MCPX_HOOK_EVENT_URI` | the declared-hook runner, for a hook it runs | empty when the event names no resource | the resource URI the event is about | the hook itself | -| `MCPX_ENDPOINT` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); an event consumer | always | the daemon's HTTP endpoint | the generated client; the plugin as a fallback for MCPX_DAEMON_ENDPOINT | -| `MCPX_SOCKET` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); the plugin loader, for a discovered plugin | empty when the daemon is remote, since its socket is not reachable from here | the daemon's unix socket, which is faster than the endpoint. Also where a daemon binds and a client dials, for anyone who sets it by hand | the generated client, `mcpx` run inside the script or shell, the plugin | -| `MCPX_TRANSPORT_BEARER_TOKEN` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); an event consumer | only when transport.bearerToken is configured | the daemon's bearer token, handed to the script so the generated client can authenticate to a daemon that requires it (#1975); the token itself stays out of the generated code | the generated client, `mcpx` run inside the script or shell, the plugin; also the setting `transport.bearerToken` | -| `MCPX_SETTINGS` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | only when the caller sent call settings with the run (for example a requested pool.callTimeout) | the call-settings header for this run, carried into the script so the generated client forwards the caller's per-call requests on the calls it makes on the script's behalf | the generated client, which sends it as the x-mcpx-settings header | -| `MCPX_ARTIFACTS_LOCAL` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | always | 1 when the daemon shares this filesystem, so artifact({path}) may hand over a path instead of the bytes | the generated client | -| `MCPX_CWD` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | the exec service only when the caller sent its working directory | the directory the caller ran mcpx from, which a remote run cannot discover | the generated client (paths.cwd, and cwd scoping) | -| `MCPX_PID` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | always | the pid of the mcpx process that started the script | the generated client, for pid scoping | -| `MCPX_ENTRY` | the runner, for every script | always | the file the runtime was started on: mcpx's generated launcher, or the script itself under --no-launcher. For exec the script is a generated file | the generated client (paths.entry) | -| `MCPX_CLIENT` | the runner, for every script | always | the generated client module | the generated client (paths.client) | -| `MCPX_CONFIG_PATH` | `mcpx exec` / `mcpx run` | always | the nearest configuration file in effect, empty when there is none | the generated client (paths.config) | -| `MCPX_PATHS_CONFIG` | `mcpx exec` / `mcpx run` | a daemon auto-started by this invocation, only when a --paths-config seed lives in this process's memory; an environment seed needs no forwarding, as the child inherits the environment | the paths.config seed this process resolved configuration discovery from, forwarded so the auto-started daemon resolves the same chain this process did | `mcpx` run inside the script or shell, in configuration discovery (a bootstrap read: paths.config decides which files the settings are read from, so there is no resolved Set to ask); also the setting `paths.config` | -| `MCPX_SCRIPT_DIRS` | `mcpx exec` / `mcpx run` | always | the directories searched for named scripts, nearest first, colon-separated | the generated client (paths.scriptDirs) | -| `MCPX_API_DECLARATION_SHA256` | `mcpx exec` / `mcpx run` | always | the fingerprint of a declared API's declaration, set on the child a declared API launches: PoolID hashes the environment, so editing the declaration replaces the pool instead of keeping a child started for the old one | the pool, as a pool identity input (api serve: PoolID hashes the server environment) | -| `MCPX_ADAPTER_DECLARATION_SHA256` | `mcpx exec` / `mcpx run` | always | the fingerprint of an adapter's declaration, set on the server an adapter launches: PoolID hashes the environment, so editing the declaration replaces the pool instead of keeping a child started for the old one | the pool, as a pool identity input (PoolID hashes the server environment); the daemon, which exempts an adapter's own exact name from the namespace-collision check when the adapter is replaced | -| `MCPX_RUNTIME` | the runner, for every script | always | deno, bun or node; on a dispatched run, the interpreter's name (sh, python3) | the generated client; on a dispatched run, the script itself | -| `MCPX_DISPATCH` | the runner, for every script | only on a dispatched (non-JavaScript) run | how the interpreter was chosen: shebang or interpreter (script.interpreter) | the script itself, and anyone reading its environment | -| `MCPX_ALLOW_READ` | the runner, for every script | only when the permissions allow reading files | 1: the client's file helpers may read. Without it they refuse, naming the permission, rather than leaving it to the sandbox | the generated client | -| `MCPX_LOG_LEVEL` | `mcpx exec` / `mcpx run` | always | the lowest level the script's log keeps | the generated client; `mcpx` run inside the script or shell reads it as logging.level; also the setting `logging.level` | -| `MCPX_LOG_SOURCE` | `mcpx exec` / `mcpx run` | always | which levels record a call site: a level name for that level and above, 0 for none | the generated client | -| `MCPX_DAEMON_ENDPOINT` | the opencode plugin | plugin.env=standard or above, once the plugin has chosen a daemon | the daemon this editor session settled on, so a shell command that runs mcpx talks to the same one instead of looking for its own | `mcpx` run inside the script or shell, as daemon.endpoint; the plugin, as the daemon to use; also the setting `daemon.endpoint` | -| `MCPX_TRACE_IDS` | the opencode plugin | plugin.env=standard or above, when there is anything to say | JSON pairs such as [["session_id","abc"],["worktree","/p"]], extended at full with the parent session and the whole ancestry | `mcpx` run inside the script or shell, which puts every pair on every log record | -| `MCPX_CALL_ID` | the opencode plugin | plugin.env=standard or above | the editor's id for this one tool call | the command | -| `MCPX_OPENCODE_CWD` | the opencode plugin | plugin.env=standard or above | the directory the command runs in, which is not always the project root | the command | -| `MCPX_OPENCODE_DIRECTORY` | the opencode plugin | plugin.env=standard or above | the project directory the editor opened | the command | -| `MCPX_OPENCODE_WORKTREE` | the opencode plugin | plugin.env=standard or above | the project's worktree | the command | -| `MCPX_WORKTREE_NAME` | the opencode plugin | plugin.env=standard or above, when there is a worktree | the worktree's last path element | the command | -| `MCPX_PROJECT_ID` | the opencode plugin | plugin.env=standard or above | the editor's project id | the command | -| `MCPX_HARNESS` | the opencode plugin | plugin.env=standard or above | opencode | the command | -| `MCPX_HARNESS_VERSION` | the opencode plugin | plugin.env=standard or above | the editor's version | the command | -| `MCPX_HARNESS_PID` | the opencode plugin | plugin.env=standard or above | the editor's pid | the command | -| `MCPX_HARNESS_STARTED` | the opencode plugin | plugin.env=standard or above | when the plugin started | the command | -| `MCPX_SHELL_SEQ` | the opencode plugin | plugin.env=standard or above | a counter of shell commands in this editor process | the command | -| `MCPX_SESSION_TITLE` | the opencode plugin | plugin.env=full | the session's title | the command | -| `MCPX_SESSION_DIRECTORY` | the opencode plugin | plugin.env=full | the session's directory | the command | -| `MCPX_SESSION_VERSION` | the opencode plugin | plugin.env=full | the editor version that created the session | the command | -| `MCPX_SESSION_DEPTH` | the opencode plugin | plugin.env=full | how many parents the session has | the command | -| `MCPX_SESSION_CREATED` | the opencode plugin | plugin.env=full, when known | when the session was created, ISO 8601 | the command | -| `MCPX_SESSION_AGE_MS` | the opencode plugin | plugin.env=full, when known | the session's age when the command started, in milliseconds | the command | +| variable | set by | when | what it is | read by | +| --- | --- | --- | --- | --- | +| `MCPX_SESSION` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); an event consumer | always | the session key this run's tool calls are leased under: --session, else MCPX_SESSION_ID, else one minted for the run | the generated client, which sends it with every call | +| `MCPX_SESSION_ID` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); an event consumer; the opencode plugin; the plugin loader, for a discovered plugin | the CLI passes through the value it was given, which may be empty; the plugin sets it at every plugin.env level | the session the host assigned. Unlike MCPX_SESSION it survives from one command to the next, so it is what session-scoped servers key on | `mcpx` run inside the script or shell, as its session when --session is not given | +| `MCPX_PARENT_SESSION_ID` | `mcpx exec` / `mcpx run`; an event consumer; the opencode plugin | the CLI passes through what it was given; the daemon passes the caller's parent session into a script run's environment; the plugin at plugin.env=full, when there is a parent | the session that spawned this one, so a parent agent and its subagents can share a server | `mcpx` run inside the script or shell, and the generated client for parent-session scoping | +| `MCPX_EPHEMERAL` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | always | 1 when the session key was minted for this run alone, so its instances may be stopped as soon as it ends | the generated client | +| `MCPX_RUN` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | always | this execution's run id, which groups the artifacts it produces | the generated client, when storing an artifact | +| `MCPX_INPUT` | `mcpx exec` / `mcpx run` | mcpx exec and mcpx run, locally and with --remote; not when mcpx serve collects the output | report: nothing in this run can answer a server's question mid-call, so a call that asks one exits 75 with the question instead of waiting for it to expire | the generated client, sent as X-Mcpx-Input | +| `MCPX_HOOK_NAME` | the declared-hook runner, for a hook it runs | always | the declared name of the hook being run | the hook itself | +| `MCPX_HOOK_PHASE` | the declared-hook runner, for a hook it runs; the exec service (`/v1/exec`, `mcpx_exec`) | always | the hook's phase; always observe for config-declared hooks, the exec hook's phase (pre, post, onError, onSuccess) for a per-call exec hook | the hook itself | +| `MCPX_HOOK_POINT` | the exec service (`/v1/exec`, `mcpx_exec`) | always | the point the hook is attached to; script for per-call exec hooks in this version | the hook itself | +| `MCPX_HOOK_ERROR` | the exec service (`/v1/exec`, `mcpx_exec`) | only for a hook running because the script failed; truncated to 1024 bytes | the error the hook is running for, in one line; the full hook context is JSON on stdin | the hook itself | +| `MCPX_HOOK_EVENT_KIND` | the declared-hook runner, for a hook it runs | always | the kind of the event the hook is running for; the full event is JSON on stdin | the hook itself | +| `MCPX_HOOK_EVENT_SEQ` | the declared-hook runner, for a hook it runs | always | the event's sequence number on the daemon's bus | the hook itself | +| `MCPX_HOOK_EVENT_SERVER` | the declared-hook runner, for a hook it runs | empty when the event names no server | the server the event is about | the hook itself | +| `MCPX_HOOK_EVENT_SESSION` | the declared-hook runner, for a hook it runs | empty when the event belongs to no session | the session the event belongs to | the hook itself | +| `MCPX_HOOK_EVENT_URI` | the declared-hook runner, for a hook it runs | empty when the event names no resource | the resource URI the event is about | the hook itself | +| `MCPX_ENDPOINT` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); an event consumer | always | the daemon's HTTP endpoint | the generated client; the plugin as a fallback for MCPX_DAEMON_ENDPOINT | +| `MCPX_SOCKET` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); the plugin loader, for a discovered plugin | empty when the daemon is remote, since its socket is not reachable from here | the daemon's unix socket, which is faster than the endpoint. Also where a daemon binds and a client dials, for anyone who sets it by hand | the generated client, `mcpx` run inside the script or shell, the plugin | +| `MCPX_TRANSPORT_BEARER_TOKEN` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); an event consumer | only when transport.bearerToken is configured | the daemon's bearer token, handed to the script so the generated client can authenticate to a daemon that requires it (#1975); the token itself stays out of the generated code | the generated client, `mcpx` run inside the script or shell, the plugin; also the setting `transport.bearerToken` | +| `MCPX_SETTINGS` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | only when the caller sent call settings with the run (for example a requested pool.callTimeout) | the call-settings header for this run, carried into the script so the generated client forwards the caller's per-call requests on the calls it makes on the script's behalf | the generated client, which sends it as the x-mcpx-settings header | +| `MCPX_ARTIFACTS_LOCAL` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | always | 1 when the daemon shares this filesystem, so artifact({path}) may hand over a path instead of the bytes | the generated client | +| `MCPX_CWD` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | the exec service only when the caller sent its working directory | the directory the caller ran mcpx from, which a remote run cannot discover | the generated client (paths.cwd, and cwd scoping) | +| `MCPX_PID` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | always | the pid of the mcpx process that started the script | the generated client, for pid scoping | +| `MCPX_ENTRY` | the runner, for every script | always | the file the runtime was started on: mcpx's generated launcher, or the script itself under --no-launcher. For exec the script is a generated file | the generated client (paths.entry) | +| `MCPX_CLIENT` | the runner, for every script | always | the generated client module | the generated client (paths.client) | +| `MCPX_CONFIG_PATH` | `mcpx exec` / `mcpx run` | always | the nearest configuration file in effect, empty when there is none | the generated client (paths.config) | +| `MCPX_PATHS_CONFIG` | `mcpx exec` / `mcpx run` | a daemon auto-started by this invocation, only when a --paths-config seed lives in this process's memory; an environment seed needs no forwarding, as the child inherits the environment | the paths.config seed this process resolved configuration discovery from, forwarded so the auto-started daemon resolves the same chain this process did | `mcpx` run inside the script or shell, in configuration discovery (a bootstrap read: paths.config decides which files the settings are read from, so there is no resolved Set to ask); also the setting `paths.config` | +| `MCPX_SCRIPT_DIRS` | `mcpx exec` / `mcpx run` | always | the directories searched for named scripts, nearest first, colon-separated | the generated client (paths.scriptDirs) | +| `MCPX_API_DECLARATION_SHA256` | `mcpx exec` / `mcpx run` | always | the fingerprint of a declared API's declaration, set on the child a declared API launches: PoolID hashes the environment, so editing the declaration replaces the pool instead of keeping a child started for the old one | the pool, as a pool identity input (api serve: PoolID hashes the server environment) | +| `MCPX_ADAPTER_DECLARATION_SHA256` | `mcpx exec` / `mcpx run` | always | the fingerprint of an adapter's declaration, set on the server an adapter launches: PoolID hashes the environment, so editing the declaration replaces the pool instead of keeping a child started for the old one | the pool, as a pool identity input (PoolID hashes the server environment); the daemon, which exempts an adapter's own exact name from the namespace-collision check when the adapter is replaced | +| `MCPX_RUNTIME` | the runner, for every script | always | deno, bun or node; on a dispatched run, the interpreter's name (sh, python3) | the generated client; on a dispatched run, the script itself | +| `MCPX_DISPATCH` | the runner, for every script | only on a dispatched (non-JavaScript) run | how the interpreter was chosen: shebang or interpreter (script.interpreter) | the script itself, and anyone reading its environment | +| `MCPX_ALLOW_READ` | the runner, for every script | only when the permissions allow reading files | 1: the client's file helpers may read. Without it they refuse, naming the permission, rather than leaving it to the sandbox | the generated client | +| `MCPX_LOG_LEVEL` | `mcpx exec` / `mcpx run` | always | the lowest level the script's log keeps | the generated client; `mcpx` run inside the script or shell reads it as logging.level; also the setting `logging.level` | +| `MCPX_LOG_SOURCE` | `mcpx exec` / `mcpx run` | always | which levels record a call site: a level name for that level and above, 0 for none | the generated client | +| `MCPX_DAEMON_ENDPOINT` | the opencode plugin | plugin.env=standard or above, once the plugin has chosen a daemon | the daemon this editor session settled on, so a shell command that runs mcpx talks to the same one instead of looking for its own | `mcpx` run inside the script or shell, as daemon.endpoint; the plugin, as the daemon to use; also the setting `daemon.endpoint` | +| `MCPX_TRACE_IDS` | the opencode plugin | plugin.env=standard or above, when there is anything to say | JSON pairs such as [["session_id","abc"],["worktree","/p"]], extended at full with the parent session and the whole ancestry | `mcpx` run inside the script or shell, which puts every pair on every log record | +| `MCPX_CALL_ID` | the opencode plugin | plugin.env=standard or above | the editor's id for this one tool call | the command | +| `MCPX_OPENCODE_CWD` | the opencode plugin | plugin.env=standard or above | the directory the command runs in, which is not always the project root | the command | +| `MCPX_OPENCODE_DIRECTORY` | the opencode plugin | plugin.env=standard or above | the project directory the editor opened | the command | +| `MCPX_OPENCODE_WORKTREE` | the opencode plugin | plugin.env=standard or above | the project's worktree | the command | +| `MCPX_WORKTREE_NAME` | the opencode plugin | plugin.env=standard or above, when there is a worktree | the worktree's last path element | the command | +| `MCPX_PROJECT_ID` | the opencode plugin | plugin.env=standard or above | the editor's project id | the command | +| `MCPX_HARNESS` | the opencode plugin | plugin.env=standard or above | opencode | the command | +| `MCPX_HARNESS_VERSION` | the opencode plugin | plugin.env=standard or above | the editor's version | the command | +| `MCPX_HARNESS_PID` | the opencode plugin | plugin.env=standard or above | the editor's pid | the command | +| `MCPX_HARNESS_STARTED` | the opencode plugin | plugin.env=standard or above | when the plugin started | the command | +| `MCPX_SHELL_SEQ` | the opencode plugin | plugin.env=standard or above | a counter of shell commands in this editor process | the command | +| `MCPX_SESSION_TITLE` | the opencode plugin | plugin.env=full | the session's title | the command | +| `MCPX_SESSION_DIRECTORY` | the opencode plugin | plugin.env=full | the session's directory | the command | +| `MCPX_SESSION_VERSION` | the opencode plugin | plugin.env=full | the editor version that created the session | the command | +| `MCPX_SESSION_DEPTH` | the opencode plugin | plugin.env=full | how many parents the session has | the command | +| `MCPX_SESSION_CREATED` | the opencode plugin | plugin.env=full, when known | when the session was created, ISO 8601 | the command | +| `MCPX_SESSION_AGE_MS` | the opencode plugin | plugin.env=full, when known | the session's age when the command started, in milliseconds | the command | diff --git a/pkgs/mcpx/docs/http-api.md b/pkgs/mcpx/docs/http-api.md index e240a61ac2..348351349b 100644 --- a/pkgs/mcpx/docs/http-api.md +++ b/pkgs/mcpx/docs/http-api.md @@ -216,12 +216,12 @@ handing a generated client the socket path as a URL and hoping. ### The client that exists: `DaemonClient` For harness plugins and Bun/TypeScript programs there is the -plugin's `DaemonClient` (`plugin/opencode/mcpx/daemon.ts`): a +plugin's `DaemonClient` (`plugin/core/daemon.ts`): a connection-reusing client that knows the discovery ladder (a named endpoint first, then the daemon info files, then health checks), speaks to the socket through Bun's `fetch` `unix` option, and reaches every operation through its generated `ops` methods -(`plugin/opencode/mcpx/ops.gen.ts`, generated from the same table), +(`plugin/core/ops.gen.ts`, generated from the same table), with named convenience methods beside them for the common calls. It is tested against a real daemon. It is also **not published as a package** — using it today means taking it from the plugin — and diff --git a/pkgs/mcpx/docs/level-2-page-map.md b/pkgs/mcpx/docs/level-2-page-map.md index f910b2db0a..29b2e80ad6 100644 --- a/pkgs/mcpx/docs/level-2-page-map.md +++ b/pkgs/mcpx/docs/level-2-page-map.md @@ -57,7 +57,7 @@ relative to `pkgs/mcpx/`. Three corrections to the refs as quoted in | 58 | transport options | `modes#transport-options` | `docs/protocol.md` §5; `docs/story.md` "What each transport costs", "Server-sent events, not WebSockets", "Lossless reconnection", "Remote servers without a shim"; `docs/dependencies.md` "Network" | #4821 | — | | 59 | server modes | `modes#server-modes` | `docs/story.md` "mcpx speaks MCP", "Sharing and scope"; `docs/protocol.md` §5 | #4821 | — | | 60 | abstract interfaces | `interfaces#abstract-interfaces` | `internal/api/ops*.go`; `docs/parity.md` | #1851 | the parity table | -| 61 | client interfaces | `interfaces#client-interfaces` | `mcpx client`; `internal/codegen`; `plugin/opencode/mcpx/daemon.ts` (`DaemonClient`) | #1851 | — | +| 61 | client interfaces | `interfaces#client-interfaces` | `mcpx client`; `internal/codegen`; `plugin/core/daemon.ts` (`DaemonClient`) | #1851 | — | | 62 | cli | `cli#cli` | `AGENTS.md` "The loop"; `cmd/mcpx/main.go` | #1851 | — | | 63 | cli arguments | `cli#cli-arguments` | `cmd/mcpx/main.go`; `internal/settings/bind.go` | #1851 | per-command registry flags | | 64 | cli commands | `cli#cli-commands` | `internal/cli/manual.go` `Commands()` | #1851 | yes: the whole command table | @@ -67,7 +67,7 @@ relative to `pkgs/mcpx/`. Three corrections to the refs as quoted in | 68 | binary | `binary#binary` | `docs/dependencies.md`; `package.nix` | #1851 | — | | 69 | script | `scripts#script` | `AGENTS.md` "Scripts", "Script contract"; `docs/story.md` "The script contract", "Named scripts"; `docs/exec.md` | #1851 | — | | 70 | /v1 | `http-api#v1` | `GET /v1/openapi.json` (`internal/api/openapi.go`); `docs/parity.md` | #1851 | yes: rendered from the OpenAPI document | -| 71 | /v1 sdk | `http-api#v1-sdk` | `DaemonClient` (`plugin/opencode/mcpx/daemon.ts`); `/v1/openapi.json` | #1851 | — | +| 71 | /v1 sdk | `http-api#v1-sdk` | `DaemonClient` (`plugin/core/daemon.ts`); `/v1/openapi.json` | #1851 | — | | 72 | plugins | `plugins#plugins` | `plugin/opencode/README.md` | #1855 | — | | 73 | plugin compatibility | `plugins#plugin-compatibility` | `docs/opencode-plugin.md` §1, §5 | #1855 | — | | 74 | plugin interface & config | `plugins#plugin-interface-and-config` | `plugin/opencode/README.md` "Configuration"; `docs/plugin-discovery.md`; `plugin.*` registry rows | #1855 | `plugin.*` rows | diff --git a/pkgs/mcpx/docs/opencode-plugin-v2.md b/pkgs/mcpx/docs/opencode-plugin-v2.md index c48ba377eb..44edad8ffd 100644 --- a/pkgs/mcpx/docs/opencode-plugin-v2.md +++ b/pkgs/mcpx/docs/opencode-plugin-v2.md @@ -112,7 +112,7 @@ same rule as today, with the file gone. ## 5. What the port does **not** need to rewrite -`plugin/opencode/mcpx/daemon.ts` is already harness-free: `discover()`, +`plugin/core/daemon.ts` is already harness-free: `discover()`, `DaemonClient`, `rank()`, `summarise()`, `readInfoFiles()`, `stateDir()` and the health checks take an `env` map and a directory and speak `/v1` over the unix socket with Bun's `fetch(url, { unix })`. v2 keeps Bun and keeps the socket, so diff --git a/pkgs/mcpx/docs/opencode-plugin.md b/pkgs/mcpx/docs/opencode-plugin.md index 7ca03e7326..4ebd724ecb 100644 --- a/pkgs/mcpx/docs/opencode-plugin.md +++ b/pkgs/mcpx/docs/opencode-plugin.md @@ -386,7 +386,7 @@ For porting to codex, claude, pi, manus, this is the part that matters. The shape that ports: **a small core that speaks the daemon API over a unix socket, plus a thin adapter per harness.** The core is -`plugin/opencode/mcpx/daemon.ts` today, and it is already almost harness-free +`plugin/core/daemon.ts` today, and it is already almost harness-free — it takes `$` only for the rung-4 spawn, which §3 removes. Lifting it into a harness-free `core` directory beside `opencode` once a second harness exists would make the split explicit. @@ -452,7 +452,7 @@ Only (1) and (2) are required. Everything else degrades. ### The socket client -- **What.** `plugin/opencode/mcpx/daemon.ts`: find a daemon, then speak +- **What.** `plugin/core/daemon.ts`: find a daemon, then speak `/v1` to it. - **Why.** 0.17 ms against 23 ms for a spawn, on a path that runs for every tool call. And in v2 there is no spawn available at all. diff --git a/pkgs/mcpx/docs/plugins.md b/pkgs/mcpx/docs/plugins.md index 46144b123b..fff6372630 100644 --- a/pkgs/mcpx/docs/plugins.md +++ b/pkgs/mcpx/docs/plugins.md @@ -100,7 +100,7 @@ the plugin's variable and must not be conflated with it.) ### Plugin to daemon -The portable core, `plugin/opencode/mcpx/daemon.ts`, imports nothing from +The portable core, `plugin/core/daemon.ts`, imports nothing from opencode. Its `DaemonClient` / `connect()` finds a daemon by walking a ladder and stopping at the first answer (full design: [plugin-discovery.md](plugin-discovery.md)): @@ -186,7 +186,7 @@ design is [opencode-plugin.md](opencode-plugin.md). | file | what it is for | | --------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `plugin/opencode/mcpx-session.ts` | the opencode adapter: hooks, tools, toasts, and the session id. The only file opencode loads as a plugin. | -| `plugin/opencode/mcpx/daemon.ts` | the portable core: the daemon HTTP client, the discovery ladder, and the remembered-choice file. Imports nothing from opencode. | +| `plugin/core/daemon.ts` | the portable core: the daemon HTTP client, the discovery ladder, and the remembered-choice file. Imports nothing from opencode. | | `plugin/opencode/mcpx-tui.tsx` | optional TUI plugin: an arrow-key picker for the daemon. A different realm with a different API, installed separately. | | `plugin/opencode/skills/` | four skills: `mcpx-basics`, `mcpx-observability`, `mcpx-browser`, `mcpx-daemon`. The same directories are embedded in the mcpx binary and served over MCP, so an MCP host can load them without copying anything. | diff --git a/pkgs/mcpx/docs/public-client.md b/pkgs/mcpx/docs/public-client.md index 5f56cb4b01..ded7cb8000 100644 --- a/pkgs/mcpx/docs/public-client.md +++ b/pkgs/mcpx/docs/public-client.md @@ -2,7 +2,7 @@ `pkgs/mcpx/pkg/client` is the public Go client for the mcpx daemon's /v1 API (#1877, rung 1). Its calls are derived at run time from the -daemon's operation table (`internal/api.Ops`) — method, path, and +daemon's operation table (the `Ops` function in `internal/api`) — method, path, and parameter placement come from the table, never from hand-written per-operation code — so the client cannot drift from the daemon the way a hand-maintained client would. diff --git a/pkgs/mcpx/docs/story.md b/pkgs/mcpx/docs/story.md index a048875d0d..5981768980 100644 --- a/pkgs/mcpx/docs/story.md +++ b/pkgs/mcpx/docs/story.md @@ -2244,7 +2244,7 @@ Spawning is **135× slower** than a warm socket, and almost all of it is process startup rather than transport. Irrelevant for something run once; decisive for anything on the path of every tool call. -`plugin/opencode/mcpx/daemon.ts` therefore talks to the socket directly rather +`plugin/core/daemon.ts` therefore talks to the socket directly rather than shelling out. It returns `undefined` when no daemon is reachable rather than throwing, because a plugin that fails to load has broken the editor for a tool the user may not even be using.