Skip to content

[BUG] infer mcp edits write expanded ${VAR} values into mcp.yaml #1764

Closed

Description

@edenreich

Summary

Every infer mcp command that saves mcp.yaml writes the file back with each ${VAR} reference replaced by the variable's value, or by nothing when it is unset. A header written as x-api-key: ${AGENTMAIL_API_KEY} turns into the plain key on disk, readable by anyone who can read the file, and the reference is gone for every later run.

LoadMCP reads the file through configutils.LoadYAML, which runs os.ExpandEnv over the whole text before unmarshalling. That is right for running, since a server's headers must hold the values. But CreateEntry, UpdateEntry and DeleteEntry, behind add, update, remove, enable and disable, save that same expanded config with SaveMCP, and so do enable-global and disable-global. SaveYAML also writes the file with mode 0644.

The same round trip, LoadYAML then SaveYAML, loads and saves agents.yaml (whose environment values may be ${VAR} references), keybindings.yaml and plugins.yaml. compute.yaml already avoids it: LoadComputeFile reads without expansion, so infer compute edits keep ${VAR}.

Found while building the desktop's MCPs tab (inference-gateway/desktop#480), which edits mcp.yaml itself to keep references intact. Hosted servers with headers come from #1757.

Steps to Reproduce

  1. Write a server whose header is a reference:

    # ~/.infer/mcp.yaml
    enabled: true
    servers:
      - name: hosted
        enabled: true
        url: http://127.0.0.1:9/mcp
        headers:
          x-api-key: ${MCP_CHECK_KEY}
  2. Run MCP_CHECK_KEY=fake-secret-value infer mcp disable hosted.

  3. Read the file: grep x-api-key ~/.infer/mcp.yaml.

Expected Behavior

x-api-key: ${MCP_CHECK_KEY}. A command that edits the file changes the entry it was asked to change and writes every other value as it was written, references included. infer mcp start, stop and status, which do not save, already leave the file as written.

Actual Behavior

x-api-key: fake-secret-value. With MCP_CHECK_KEY unset, the header is written empty instead, and from then on the MCP supervisor skips the server as one with an unresolved header.

Acceptance Criteria

  • infer mcp add, update, remove, enable, disable, enable-global and disable-global keep every ${VAR} reference in mcp.yaml as written. Running keeps expanding them as today.
  • infer agents commands that save agents.yaml keep ${VAR} references in environment the same way, and so does every other config that is loaded with LoadYAML and saved with SaveYAML.
  • Files that can hold secrets after an edit are written with mode 0600, or the save keeps the file's existing mode.
  • A test edits a file holding a ${VAR} reference with that variable set, and asserts the reference survives.

Activity

  1. added
    bug
    on Nov 8, 2026
  2. added theissue type on Nov 8, 2026
  3. moved this from Todo to In progress in 2026on Nov 8, 2026
  4. moved this from In progress to QA in 2026on Nov 8, 2026
  5. moved this from QA to Done in 2026on Nov 8, 2026
  6. inference-gateway-releaser commented on Nov 9, 2026

    @inference-gateway-releaser
    Contributor

    🎉 This issue has been resolved in version 0.250.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugreleased

    Type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions