Skip to content

fix: judge plugin requiresEnv against the runtime environment - #189

Merged
liuedcson merged 2 commits into
mainfrom
fix/steppage-requires-env
Sep 24, 2026
Merged

liuedcson merged 2 commits into
mainfrom
fix/steppage-requires-env

Conversation

@liuedcson

Copy link
Copy Markdown
Collaborator

Problem

/plugin reported the pre-installed StepPage plugin as missing STEPFUN_API_KEY for every logged-in user, even though the plugin works fine.

Two code paths disagreed about what "has a credential" means:

  • Runtime (resolveStepMcpEnvironment) spawns the server with process.env → manifest declared env → Step login credential fallback for STEPFUN_API_KEY.
  • Doctor (diagnoseStepPlugin) checked the plugin's provision.requiresEnv against bare process.env only.

So a user who had run /login — the normal case — was told a variable was missing that the runtime supplies on its own from auth.json. The warning also only described the situation ("a Step login credential can supply it at runtime") instead of saying what to do about it. requiresEnv gates no behaviour, so this was pure noise in the Installed list.

Change

  • Move resolveStepMcpEnvironment into step/mcp-environment.ts so the doctor and the runtime share one resolution. It needs its own module: mcp.ts imports plugins.ts, so plugins.ts cannot import the resolver from mcp.ts without closing a module cycle. mcp.ts re-exports it, so existing consumers are unchanged.
  • diagnoseStepPlugin takes { env?, authPath? } and judges requiresEnv against the resolved runtime environment.
  • Reword the remaining warning to point at /login, so it only appears when neither a shell value nor a credential exists — and then says what to do.

Tests

requiresEnv had no coverage. Added both directions to test/step-plugins.test.ts:

  • credential in auth.json + empty shell env → no warning
  • no credential + empty shell env → warning naming the variable and /login

npm run check passes (biome, layer-direction, public-boundary, tsgo); step-plugins.test.ts and mcp.test.ts pass.

`diagnoseStepPlugin` checked `process.env` for the variables a plugin's
provision block declares, while the server it describes is spawned with
`resolveStepMcpEnvironment`, which falls back to the Step login credential
for STEPFUN_API_KEY. Every logged-in user therefore saw the built-in
StepPage plugin warn about a missing STEPFUN_API_KEY that the runtime
supplies on its own, and the warning told them a credential "can supply it
at runtime" rather than what to do.

Move `resolveStepMcpEnvironment` into `step/mcp-environment.ts` so the
doctor and the runtime share one resolution — `mcp.ts` imports `plugins.ts`,
so plugins cannot import the resolver from `mcp.ts` without a cycle — inject
env/authPath into `diagnoseStepPlugin`, and reword the remaining warning to
point at `/login`.
Review follow-up on the previous commit, which compared `requiresEnv`
against the login fallback but still passed no declared environment.

`connectStepMcpServer` layers three sources: the process environment, the
server's own declared `env`, and the Step login credential. The doctor
consulted only the first and third, so a plugin that carried its key in
`mcpServers.<name>.env` was still reported as missing it. Match the servers
whose command is the provisioned one and judge the requirement against each
of their resolved environments. Only an inline `mcpServers` record can start
a server, since discovery skips a string declaration path, so that is the
only shape consulted.

A Step login also only ever supplies its own credential, so `/login` is no
longer offered for an unrelated variable; those are pointed at exporting it
or declaring it in the manifest. `STEP_LOGIN_SUPPLIED_ENV` keeps that list
next to the resolver that honours it rather than hardcoded in the message.
@liuedcson
liuedcson requested a review from ZouR-Ma September 24, 2026 09:11
@liuedcson
liuedcson merged commit 7dd66cb into main Sep 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant