From 17e55d59f848db7b3f69d4407a4019a8376460d0 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Sun, 15 Nov 2026 21:06:08 -0600 Subject: [PATCH] fix(mcpx): clear the golangci gate (28 findings), regenerate environment doc, make config test hermetic --- pkgs/mcpx/docs/environment.md | 110 +++++++++--------- pkgs/mcpx/internal/cli/adapter_import.go | 11 -- .../mcpx/internal/cli/adapter_import_parse.go | 2 +- pkgs/mcpx/internal/cli/run.go | 20 ++-- pkgs/mcpx/internal/cli/scripts.go | 6 - pkgs/mcpx/internal/codegen/emit.go | 16 +-- pkgs/mcpx/internal/config/config_test.go | 4 + pkgs/mcpx/internal/daemon/routes_settings.go | 2 +- .../e2e/feature_coverage_guard_test.go | 2 +- pkgs/mcpx/internal/mcpauth/failover.go | 8 +- pkgs/mcpx/internal/mcpauth/failover_test.go | 4 +- pkgs/mcpx/internal/mcpclient/redirect_test.go | 8 +- pkgs/mcpx/internal/mcpserver/server.go | 2 +- pkgs/mcpx/internal/pluginsession/hooks.go | 2 +- pkgs/mcpx/internal/pool/budget.go | 10 +- pkgs/mcpx/internal/recipes/recipes.go | 16 --- pkgs/mcpx/internal/runner/runner.go | 2 +- pkgs/mcpx/internal/runner/runtimes.go | 2 +- pkgs/mcpx/internal/testsupport/childenv.go | 2 +- 19 files changed, 100 insertions(+), 129 deletions(-) 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/internal/cli/adapter_import.go b/pkgs/mcpx/internal/cli/adapter_import.go index f1406c3f3b..f8e9ecf55f 100644 --- a/pkgs/mcpx/internal/cli/adapter_import.go +++ b/pkgs/mcpx/internal/cli/adapter_import.go @@ -9,7 +9,6 @@ import ( "os/exec" "path/filepath" "regexp" - "sort" "strings" "time" "unicode" @@ -733,13 +732,3 @@ func versionDrift(s adapter.Spec) (declared, found string, drift bool) { } return s.Provenance.BinaryVersion, found, found != s.Provenance.BinaryVersion } - -// sortedFlagNames is a small deterministic-order helper for notes. -func sortedFlagNames(flags []importFlag) []string { - var names []string - for _, f := range flags { - names = append(names, f.flag()) - } - sort.Strings(names) - return names -} diff --git a/pkgs/mcpx/internal/cli/adapter_import_parse.go b/pkgs/mcpx/internal/cli/adapter_import_parse.go index cfb0af0d1f..d74fd3a397 100644 --- a/pkgs/mcpx/internal/cli/adapter_import_parse.go +++ b/pkgs/mcpx/internal/cli/adapter_import_parse.go @@ -568,7 +568,7 @@ func firstSentence(s string) string { } var helpRowRE = regexp.MustCompile(`^\s{1,6}(\S+)\s{2,}(\S.*)$`) -var usageBracketRE = regexp.MustCompile("\\[([^\\[\\]]*)\\]") +var usageBracketRE = regexp.MustCompile(`\[([^\[\]]*)\]`) // optionalPositionalNames extracts the positional names a help text's // usage block marks optional: the bracketed [name] form (argparse diff --git a/pkgs/mcpx/internal/cli/run.go b/pkgs/mcpx/internal/cli/run.go index 52bbfbc706..f1c592835c 100644 --- a/pkgs/mcpx/internal/cli/run.go +++ b/pkgs/mcpx/internal/cli/run.go @@ -166,7 +166,7 @@ func Run(ctx context.Context, args []string, env Env, stdio Stdio) int { // to be reached for mid-command ("...actually, show me") as // chosen up front. if err := app.CmdTUI(ctx, nil); err != nil { - fmt.Fprintln(stdio.err(), "mcpx:", err) + _, _ = fmt.Fprintln(stdio.err(), "mcpx:", err) return 1 } return 0 @@ -198,7 +198,7 @@ func Run(ctx context.Context, args []string, env Env, stdio Stdio) int { config.SetPathsConfigSeed(splitList(strings.TrimPrefix(args[0], "--paths-config="))) args = args[1:] case args[0] == "--version" || args[0] == "-v": - fmt.Fprintln(stdio.out(), "mcpx", Version) + _, _ = fmt.Fprintln(stdio.out(), "mcpx", Version) return 0 case args[0] == "--help" || args[0] == "-h": _ = app.CmdHelp(ctx, nil) @@ -209,14 +209,14 @@ func Run(ctx context.Context, args []string, env Env, stdio Stdio) int { // `mcpx ls --plumbing-strict-unknown-keys` does. rest, err := app.ApplyGlobalSettingFlags(args) if err != nil { - fmt.Fprintln(stdio.err(), "mcpx:", err) + _, _ = fmt.Fprintln(stdio.err(), "mcpx:", err) return 2 } if len(rest) < len(args) { args = rest continue } - fmt.Fprintf(stdio.err(), "unknown global flag %q\n", args[0]) + _, _ = fmt.Fprintf(stdio.err(), "unknown global flag %q\n", args[0]) return 2 } } @@ -233,7 +233,7 @@ func Run(ctx context.Context, args []string, env Env, stdio Stdio) int { // terminal the TUI cannot have been meant, and help with // success stays the answer for a pipe. if isTerminal(os.Stdin) && isTerminal(os.Stdout) { - fmt.Fprintln(stdio.err(), "mcpx:", err) + _, _ = fmt.Fprintln(stdio.err(), "mcpx:", err) return 1 } _ = app.CmdHelp(ctx, nil) @@ -260,7 +260,7 @@ func Run(ctx context.Context, args []string, env Env, stdio Stdio) int { h, rest = app.CmdExec, args } } else { - fmt.Fprintf(stdio.err(), "unknown command %q\n\n", cmd) + _, _ = fmt.Fprintf(stdio.err(), "unknown command %q\n\n", cmd) _ = app.CmdHelp(ctx, nil) return 2 } @@ -270,7 +270,7 @@ func Run(ctx context.Context, args []string, env Env, stdio Stdio) int { // file is reported once, up front, rather than by whichever command // happens to read the offending value first. if err := app.SettingsErr(); err != nil { - fmt.Fprintln(stdio.err(), "mcpx:", err) + _, _ = fmt.Fprintln(stdio.err(), "mcpx:", err) return 2 } @@ -288,14 +288,14 @@ func Run(ctx context.Context, args []string, env Env, stdio Stdio) int { // prefix with "mcpx:" -- only the status carries over. var se *exitStatusError if !errors.As(err, &se) { - fmt.Fprintln(stdio.err(), "mcpx:", err) + _, _ = fmt.Fprintln(stdio.err(), "mcpx:", err) } return ec.ExitCode() } if errors.Is(err, ErrNoDaemon) { - fmt.Fprintln(stdio.err(), "mcpx: daemon is not running and could not be started") + _, _ = fmt.Fprintln(stdio.err(), "mcpx: daemon is not running and could not be started") } else { - fmt.Fprintln(stdio.err(), "mcpx:", err) + _, _ = fmt.Fprintln(stdio.err(), "mcpx:", err) } return 1 } diff --git a/pkgs/mcpx/internal/cli/scripts.go b/pkgs/mcpx/internal/cli/scripts.go index 2d312255a3..e077d97b0e 100644 --- a/pkgs/mcpx/internal/cli/scripts.go +++ b/pkgs/mcpx/internal/cli/scripts.go @@ -61,12 +61,6 @@ func scriptResolver() scriptresolve.Resolver { } } -// scriptPath resolves the configured search path, splicing the built-in list -// wherever the user left a null. -func scriptPath() searchpath.Resolved { - return scriptResolver().Path() -} - // scriptSearchDirs is the flat list, kept for the environment variable the // runner passes to scripts. func scriptSearchDirs() []string { diff --git a/pkgs/mcpx/internal/codegen/emit.go b/pkgs/mcpx/internal/codegen/emit.go index 6c5ed82cbd..38c3be0cc5 100644 --- a/pkgs/mcpx/internal/codegen/emit.go +++ b/pkgs/mcpx/internal/codegen/emit.go @@ -119,14 +119,6 @@ func toolDecl(t Tool, indent string) string { return b.String() } -// Module renders the importable client module for the TypeScript target -// (the TypeScript entry in the Language table, language.go). Scripts do: -// -// import { fff, chrome_devtools } from "./.mcpx/client.ts"; -// -// or use the default `tools` object. The module is written to disk, so the -// JavaScript runtime's own module cache applies and startup stays at tens of -// milliseconds. // RecipeMeta is one saved script (a recipe), as search() surfaces it // beside tools (CODE-36): the script's name, its summary as the // description, and its placeholder names. The daemon renders the @@ -138,6 +130,14 @@ type RecipeMeta struct { Required []string } +// Module renders the importable client module for the TypeScript target +// (the TypeScript entry in the Language table, language.go). Scripts do: +// +// import { fff, chrome_devtools } from "./.mcpx/client.ts"; +// +// or use the default `tools` object. The module is written to disk, so the +// JavaScript runtime's own module cache applies and startup stays at tens of +// milliseconds. // Module renders the client with no saved scripts in search(). func Module(nss []Namespace, endpoint, session string) string { return ModuleWithRecipes(nss, endpoint, session, nil) diff --git a/pkgs/mcpx/internal/config/config_test.go b/pkgs/mcpx/internal/config/config_test.go index c990652736..b5d2cce4e6 100644 --- a/pkgs/mcpx/internal/config/config_test.go +++ b/pkgs/mcpx/internal/config/config_test.go @@ -166,6 +166,10 @@ func TestAnUnknownKeyInTheMcpxBlockIsRefused(t *testing.T) { } func TestServerKeysAnotherHostWritesAreRecordedNotRefused(t *testing.T) { + // MCPX_CONFIG short-circuits the search path (chain.go); the devshell + // sets it, so without this the merged load below reads that file + // instead of the test fixtures and the ignored key is lost. + t.Setenv("MCPX_CONFIG", "") // A server entry is shared with every other MCP host. Claude Code // writes "type" and Cline writes "alwaysAllow"; refusing them would // make a config that works everywhere else fail here. diff --git a/pkgs/mcpx/internal/daemon/routes_settings.go b/pkgs/mcpx/internal/daemon/routes_settings.go index 88f0021e73..d7387fe02c 100644 --- a/pkgs/mcpx/internal/daemon/routes_settings.go +++ b/pkgs/mcpx/internal/daemon/routes_settings.go @@ -1066,7 +1066,7 @@ func (s *Server) handleAPIsAdd(w http.ResponseWriter, r *http.Request) { writeErr(w, http.StatusBadRequest, err) return } - if err := req.apiDeclaration.Validate(); err != nil { + if err := req.Validate(); err != nil { writeErr(w, http.StatusBadRequest, err) return } diff --git a/pkgs/mcpx/internal/e2e/feature_coverage_guard_test.go b/pkgs/mcpx/internal/e2e/feature_coverage_guard_test.go index a08a18d2ab..6c8a9eeaed 100644 --- a/pkgs/mcpx/internal/e2e/feature_coverage_guard_test.go +++ b/pkgs/mcpx/internal/e2e/feature_coverage_guard_test.go @@ -318,7 +318,7 @@ func TestFeatureCoverageGuardSkipsPartialExecutionModes(t *testing.T) { t.Fatalf("set %s: %v", name, err) } if violations := featureCoverageGuardViolations(0, nil); violations != nil { - flag.Set(name, orig) + _ = flag.Set(name, orig) t.Fatalf("with %s set, guard returned %v, want nil (evaluation excluded)", name, violations) } if err := flag.Set(name, orig); err != nil { diff --git a/pkgs/mcpx/internal/mcpauth/failover.go b/pkgs/mcpx/internal/mcpauth/failover.go index 527ddecc90..03062fc66d 100644 --- a/pkgs/mcpx/internal/mcpauth/failover.go +++ b/pkgs/mcpx/internal/mcpauth/failover.go @@ -146,10 +146,10 @@ func Classify(err error) Block { if !errors.As(err, &ae) { return BlockHard } - switch { - case ae.Status == 429: + switch ae.Status { + case 429: return BlockSoft - case ae.Status == 403: + case 403: if ae.RetryAfter > 0 { return BlockSoft } @@ -456,7 +456,7 @@ func (m *Minter) Mint(ctx context.Context, keyPEM []byte, appID, installationID if err != nil { return "", time.Time{}, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() body, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<20)) if resp.StatusCode < 200 || resp.StatusCode >= 300 { return "", time.Time{}, &APIError{Status: resp.StatusCode, Body: string(body)} diff --git a/pkgs/mcpx/internal/mcpauth/failover_test.go b/pkgs/mcpx/internal/mcpauth/failover_test.go index f44e8ea363..9a486889d8 100644 --- a/pkgs/mcpx/internal/mcpauth/failover_test.go +++ b/pkgs/mcpx/internal/mcpauth/failover_test.go @@ -188,7 +188,7 @@ func TestMintInstallationToken(t *testing.T) { gotPath = req.URL.Path gotJWT = strings.TrimPrefix(req.Header.Get("Authorization"), "Bearer ") w.Header().Set("Content-Type", "application/json") - fmt.Fprint(w, `{"token":"installation-token-xyz","expires_at":"2030-01-01T00:00:00Z"}`) + _, _ = fmt.Fprint(w, `{"token":"installation-token-xyz","expires_at":"2030-01-01T00:00:00Z"}`) })) defer srv.Close() @@ -241,7 +241,7 @@ func TestAppIdentityMintsAndCaches(t *testing.T) { mints := 0 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { mints++ - fmt.Fprint(w, `{"token":"minted-1","expires_at":"2999-01-01T00:00:00Z"}`) + _, _ = fmt.Fprint(w, `{"token":"minted-1","expires_at":"2999-01-01T00:00:00Z"}`) })) defer srv.Close() diff --git a/pkgs/mcpx/internal/mcpclient/redirect_test.go b/pkgs/mcpx/internal/mcpclient/redirect_test.go index ea0b0a60f1..c1b79968aa 100644 --- a/pkgs/mcpx/internal/mcpclient/redirect_test.go +++ b/pkgs/mcpx/internal/mcpclient/redirect_test.go @@ -99,7 +99,7 @@ func TestHTTPStreamClientRefusesCrossOriginRedirect(t *testing.T) { body, err := tr.get(context.Background(), "") if body != nil { - body.Close() + _ = body.Close() } assertCrossOriginRedirectReturned(t, err, http.StatusFound) assertRedirectTargetNotReached(t, seen) @@ -114,7 +114,7 @@ func TestLegacySSEInitialGETRefusesCrossOriginRedirect(t *testing.T) { tr, err := NewLegacySSE(context.Background(), HTTPOptions{URL: source.URL, Headers: map[string]string{"X-API-Key": redirectTestAPIKey}}) if tr != nil { - tr.Close() + _ = tr.Close() } assertCrossOriginRedirectReturned(t, err, http.StatusFound) assertRedirectTargetNotReached(t, seen) @@ -126,7 +126,7 @@ func TestLegacySSEPOSTRefusesCrossOriginRedirect(t *testing.T) { switch r.URL.Path { case "/sse": w.Header().Set("Content-Type", "text/event-stream") - fmt.Fprint(w, "event: endpoint\ndata: /post\n\n") + _, _ = fmt.Fprint(w, "event: endpoint\ndata: /post\n\n") w.(http.Flusher).Flush() <-r.Context().Done() case "/post": @@ -141,7 +141,7 @@ func TestLegacySSEPOSTRefusesCrossOriginRedirect(t *testing.T) { if err != nil { t.Fatal(err) } - defer tr.Close() + defer func() { _ = tr.Close() }() err = tr.Send(context.Background(), []byte(`{"jsonrpc":"2.0","id":1,"method":"tools/list"}`)) assertCrossOriginRedirectReturned(t, err, http.StatusTemporaryRedirect) diff --git a/pkgs/mcpx/internal/mcpserver/server.go b/pkgs/mcpx/internal/mcpserver/server.go index 30928411b8..2cfe41c82b 100644 --- a/pkgs/mcpx/internal/mcpserver/server.go +++ b/pkgs/mcpx/internal/mcpserver/server.go @@ -934,7 +934,7 @@ func (s *Server) handle(ctx context.Context, c *Conn, req request) *response { if version == "" && c != nil { version = c.Version() } - if version != "" && !(capName == "completions" && !Defines(version, FeatCompletions)) { + if version != "" && (capName != "completions" || Defines(version, FeatCompletions)) { // The completions exemption: 2024-11-05 has no completions // capability to advertise with, but completion/complete // itself is older than the capability (see FeatCompletions), diff --git a/pkgs/mcpx/internal/pluginsession/hooks.go b/pkgs/mcpx/internal/pluginsession/hooks.go index 192b70dcb7..b7834a8ce0 100644 --- a/pkgs/mcpx/internal/pluginsession/hooks.go +++ b/pkgs/mcpx/internal/pluginsession/hooks.go @@ -1,4 +1,4 @@ -// Manifest-hook resolution for plugin sessions (#1873 slice 2, +// Package pluginsession provides manifest-hook resolution for plugin sessions (#1873 slice 2, // #10046): the declarations Registry.Open records become live bus // subscribers, owned by the session and dropped by its Close. // diff --git a/pkgs/mcpx/internal/pool/budget.go b/pkgs/mcpx/internal/pool/budget.go index 5963fbcfe6..529e192239 100644 --- a/pkgs/mcpx/internal/pool/budget.go +++ b/pkgs/mcpx/internal/pool/budget.go @@ -68,11 +68,6 @@ func RequestedCallTimeout(ctx context.Context) (time.Duration, bool) { return d, ok && d > 0 } -// callTimeout is the effective budget for one upstream request: the -// pool's configured CallTimeout, lowered by a caller's per-call request -// when one is present and smaller. A configured value of zero or less -// means the operator set no bound, so a per-call request then applies -// exactly as asked. // CallTimeout is the pool's resolved per-call budget for ctx: the // configured CallTimeout, lowered by a caller's per-call request when // one is present and smaller. It is the same value upstream calls are @@ -83,6 +78,11 @@ func (p *Pool) CallTimeout(ctx context.Context) time.Duration { return p.callTimeout(ctx) } +// callTimeout is the effective budget for one upstream request: the +// pool's configured CallTimeout, lowered by a caller's per-call request +// when one is present and smaller. A configured value of zero or less +// means the operator set no bound, so a per-call request then applies +// exactly as asked. func (p *Pool) callTimeout(ctx context.Context) time.Duration { cfg := p.cfg.CallTimeout req, ok := RequestedCallTimeout(ctx) diff --git a/pkgs/mcpx/internal/recipes/recipes.go b/pkgs/mcpx/internal/recipes/recipes.go index b4ee07314c..30f975bb0e 100644 --- a/pkgs/mcpx/internal/recipes/recipes.go +++ b/pkgs/mcpx/internal/recipes/recipes.go @@ -392,10 +392,6 @@ func scanCode(src string) []bool { return code } -// refs finds every `@name` in the body, ignoring declarations, comments and -// anything inside a string. -func refs(src string) []string { return refsFor(src, langJS) } - // refsFor is refs with the code mask of the body's own language: a // Python or shell comment is not JavaScript, and an `@name` inside one // ('# Contact @alice') is text, not a placeholder -- while Parse used @@ -587,14 +583,6 @@ func (r Recipe) Render(values map[string]any) (string, error) { return strings.TrimRight(b.String(), "\n") + "\n", nil } -// substitute replaces `@name` placeholders on one line. code is the -// scanCode mask for exactly this line's bytes: an `@name` outside code -// position (in a comment or a string) is copied through untouched, so a -// filled value is never spliced into a literal. -func substitute(line string, code []bool, lits map[string]string) string { - return substituteFor(line, code, lits, langJS) -} - // substituteFor is substitute in the body's language: a Python // decorator (an `@name` as the first thing on its line, at a statement // boundary) is language syntax, never a placeholder, so it is copied @@ -630,10 +618,6 @@ func substituteFor(line string, code []bool, lits map[string]string, lang string return b.String() } -// literal renders one value as a JavaScript literal; literalFor is -// the language-aware form Render uses. -func literal(p Placeholder, v any) (string, error) { return literalFor(langJS, p, v) } - func literalFor(lang string, p Placeholder, v any) (string, error) { switch p.Type { case TypeNumber: diff --git a/pkgs/mcpx/internal/runner/runner.go b/pkgs/mcpx/internal/runner/runner.go index 7d78618c9e..76e01035be 100644 --- a/pkgs/mcpx/internal/runner/runner.go +++ b/pkgs/mcpx/internal/runner/runner.go @@ -782,7 +782,7 @@ func Run(ctx context.Context, opts Options) (*Result, error) { rt.Bin = abs } } - if rt.Kind == KindNode && !(devshellIsFlake(opts.Devshell) && rt.Bin == rt.Invoke) { + if rt.Kind == KindNode && (!devshellIsFlake(opts.Devshell) || rt.Bin != rt.Invoke) { // A devshell-deferred runtime has no host binary to probe: Bin // is still the bare name the shell will resolve. Probing it // here would fail the run before the shell gets its chance. diff --git a/pkgs/mcpx/internal/runner/runtimes.go b/pkgs/mcpx/internal/runner/runtimes.go index cf11e08f7e..6ba7f52cda 100644 --- a/pkgs/mcpx/internal/runner/runtimes.go +++ b/pkgs/mcpx/internal/runner/runtimes.go @@ -440,7 +440,7 @@ func checkNodeTransformTypes(bin string) error { return fmt.Errorf("probe node runtime %s for --experimental-transform-types: create temporary TypeScript script: %w", bin, err) } probePath := probe.Name() - defer os.Remove(probePath) + defer func() { _ = os.Remove(probePath) }() if _, err := probe.WriteString("enum McpxTransformTypesProbe { Supported }; void McpxTransformTypesProbe.Supported;\n"); err != nil { _ = probe.Close() return fmt.Errorf("probe node runtime %s for --experimental-transform-types: write temporary TypeScript script: %w", bin, err) diff --git a/pkgs/mcpx/internal/testsupport/childenv.go b/pkgs/mcpx/internal/testsupport/childenv.go index 28d24fe37f..0140d78a43 100644 --- a/pkgs/mcpx/internal/testsupport/childenv.go +++ b/pkgs/mcpx/internal/testsupport/childenv.go @@ -1,4 +1,4 @@ -// The test child environment: an allowlist, not an inheritance. +// Package testsupport provides the test child environment: an allowlist, not an inheritance. // // Every end-to-end test starts a real mcpx binary as a child process. That // child used to inherit the developer's whole environment minus MCPX_*