Repository navigation
fix(config): keep ${VAR} references when a command edits a config file - #1765
Merged
Merged
Conversation
infer mcp and infer agents edited the copy of their file loaded to run with,
whose ${VAR} references were already expanded, and saved it back. A header
written as x-api-key: ${AGENTMAIL_API_KEY} ended up as the plain key on disk,
or empty when the variable was unset.
An edit now starts from a copy loaded as written. LoadMCP and LoadAgents keep
expanding for running and refuse to save, while LoadMCPForEdit and
LoadAgentsForEdit back the edit commands. plugins.yaml, keybindings.yaml and
sandbox.yaml are read from the merged config to run, so their loaders, used
only to edit, now load as written too. A sandbox grant keeps ${HOME} in the
paths already there.
A save keeps the file's mode, so a file its owner tightened to 0600 stays that
way.
Closes #1764
The regression test built the mcp subtree on its own, so the root's PersistentPreRunE never loaded the config. Each case now runs infer mcp <edit> through a fresh root.NewCommand(), whose State owns a Viper of its own, with SetArgs, SetOut and ExecuteContext(t.Context()). HOME and the working directory point at temp dirs and every INFER_* variable is blanked, so neither this machine's config, the repository's .infer nor the developer's environment reaches a run.
edenreich
added a commit
that referenced
this pull request
Nov 8, 2026
…1767) ## Summary A Kubernetes workspace names the hosted MCP servers of this machine's `~/.infer/mcp.yaml` its pods get, and the adapter writes them into each new Orchestrator: ```yaml # ~/.infer/mcp.yaml servers: - name: agentmail enabled: true url: https://mcp.agentmail.to/mcp headers: x-api-key: ${AGENTMAIL_API_KEY} # ~/.infer/daemon.yaml workspaces: - name: code-reviewer kind: kubernetes namespace: agents image: ghcr.io/inference-gateway/cli:latest secrets: - code-reviewer-credentials mcp_servers: - agentmail ``` - `mcp_servers` is accepted on a Kubernetes workspace, also one placed on a cluster through `compute`. Any other kind fails validation, like `secrets`. - When a session's Orchestrator is created, each named server goes into `spec.mcp.servers` with its name, URL and headers, and `spec.mcp.enabled` is set. - `mcp.yaml` is read as written (`LoadMCPForEdit`), so a header stays a `${VAR}` reference the pod expands from its own `secrets`. A header that holds a value rather than a reference is refused with an error naming the server and the header, never the value, so no secret lands in a Kubernetes object. - A name `mcp.yaml` lacks and a container server (`run: true`) fail with an error naming the server before the Orchestrator is created. - An older operator types `spec.mcp.servers` entries as strings and refuses the create as invalid. That now also reads as the existing "may predate ..., upgrade it" error, naming v0.33.0. - The servers are read when the Orchestrator is created, like `secrets`, so running sessions keep theirs. Closes #1760 ## Draft: waiting on the operator This writes `spec.mcp.servers` entries with a `name`, a `url` and `headers`, the shape inference-gateway/operator#324 gives the field, which no operator release has yet. Until it ships, a workspace with `mcp_servers` fails its teleport with the upgrade error and every other workspace is unaffected. `newFieldsOperatorVersion` is v0.33.0, the next operator release, which `binding_service` already needs. It has to follow the release operator#324 actually lands in. ## Tests - `TestCreateGivesThePodTheNamedMCPServersAsWritten` runs `create` against a fake cluster: no servers leaves `spec.mcp` unset, named servers carry their URLs and header references (a URL built from scheme, host, port and path included), and a missing name, a container server and a header holding a value fail without creating anything. The header's variable is set in the test's environment, and its value never reaches the Orchestrator. - `TestCreateNamesTheOperatorVersionMCPServersNeed` checks the upgrade error when an older operator refuses the entries as invalid. The 422 there is modeled on the apiserver's schema error, not captured from a live older operator. - Config tests cover `mcp_servers` on a local workspace and on a workspace placed through `compute`. - `task test:e2e`, `task precommit:run` and `go test ./...` pass. The e2e suite does not run Kubernetes workspaces, and no cluster with an operator that renders hosted servers exists yet. ## Example and docs - `examples/session-teleport` gains a `k8s-mcp` workspace. It gets the demo MCP server from `examples/mcp`, deployed into the cluster with `task mcp:install`, behind an `x-api-key: ${DEMO_MCP_KEY}` header the pod fills from the `demo-mcp-credentials` Secret. `task mcp:status` runs `infer mcp status` in the pod. The walkthrough states it needs operator v0.33.0 or newer. - `docs/daemon.md` documents `mcp_servers` beside `secrets`, with the AgentMail example. ## Known gaps - A refusal fails after the session's TLS Secret exists, as a missing `secrets` entry already does. A retry reuses it. - A `${VAR}` in a server's `port` still cannot be read as written, the gap noted in #1765. ## Cross-repo impact - `operator`: inference-gateway/operator#324 renders `spec.mcp.servers` into the pod's `mcp.yaml`. This PR depends on it. - `desktop`: inference-gateway/desktop#480 writes `mcp_servers` under a workspace in `daemon.yaml`, the shape this reads. - `docs`: inference-gateway/docs#1146 documents `mcp_servers` on Kubernetes workspaces.
Contributor
|
🎉 This PR is included in version 0.250.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1764
Summary
Every
infer mcpcommand that savesmcp.yaml, and everyinfer agentscommand that savesagents.yaml, wrote the file back with each${VAR}reference replaced by the variable's value. They edited the copy loaded to run with, whichLoadYAMLhad already passed throughos.ExpandEnv. A header written asx-api-key: ${AGENTMAIL_API_KEY}ended up as the plain key on disk in a 0644 file, or empty when the variable was unset, and the MCP supervisor then skipped the server.Re-reading the file at save time would not help, because
UpdateEntryreceives a whole entry read from the expanded copy. An edit now starts from a copy loaded as written.Changes
config/utils/yamlfile.go:LoadYAMLkeeps expanding, for running.LoadYAMLAsWrittenreads a file as written, for editing. Both share one loader.config/mcp.go,config/agents.go:LoadMCPandLoadAgentsload to run with, and their entries refuse to save with an error that says why, instead of writing values over references.LoadMCPForEditandLoadAgentsForEditload as written and can save.infer mcpadd,update,remove,enable,disable,enable-globalanddisable-global, andinfer agentsadd,updateandremove. Listing, status, start and stop keep the expanded copy.config/plugins.go,config/keybindings.go,config/sandbox.go: a run reads these from the merged config, so their loaders are only used to edit and now load as written.ResolveDirexpands a pluginsdiritself. A saved sandbox grant keeps${HOME}in the paths already there.docs/mcp-integration.md,docs/agents-configuration.md: edits keep${VAR}references and the file's mode.Tests
cmd/mcp/mcp_test.go(new) reproduces the issue for all seveninfer mcpedit commands, run asinfer mcp <edit>through a freshroot.NewCommand()withMCP_CHECK_KEYset:PersistentPreRunEloads the config into a Viper of its own, as a real run does.INFER_*variable is blanked. So neither this machine's config, the repository's.infer, nor the developer's environment reaches a run.main, all seven fail with the key written intomcp.yaml.environmentreference surviving an update, and the expanded copy refusing to save;LoadMCPrefusing to save and leaving the file untouched;${HOME}surviving a saved sandbox grant;LoadYAMLAsWrittenkeeping a reference through a save, and the file mode kept or defaulted.Verification
task precommit:runpasses (mod tidy, mocks, fmt, lint with 0 issues, markdownlint).go test ./...passes.task test:e2epasses in 307s.Trade-offs
port: ${MCP_PORT}, now fails to parse in the edit commands. Before, an edit wrote the expanded value over it. Running is unchanged./Users/me/reposbeside an existing${HOME}/reposentry adds a second entry rather than matching the first.Cross-repo impact
desktop: none needed. feat(settings): manage MCP servers in an MCPs tab and let agents pick theirs desktop#480 editsmcp.yamlitself and runs onlyinfer mcp start,stopandstatus, which never saved the file.docs: no docs ticket. This is a fix to how the CLI saves its own files, and the CLI docs in this repo are updated with it.