Skip to content

feat(settings): manage MCP servers in an MCPs tab and let agents pick theirs - #480

Merged
edenreich merged 1 commit into
mainfrom
feat/mcps-tab
Nov 8, 2026
Merged

edenreich merged 1 commit into
mainfrom
feat/mcps-tab

Conversation

@edenreich

@edenreich edenreich commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #476

Summary

Settings gets an MCPs tab for the servers of ~/.infer/mcp.yaml, and the agent editor picks the servers an agent uses. A hosted server authenticates with headers whose values are secrets from the Secrets tab (#479), written as ${VARIABLE} and never as the secret. A server goes to this computer and to Kubernetes workspaces, so an agent on its own computer can reach it there once the CLI and operator counterparts land.

The tab edits mcp.yaml as written rather than through infer mcp. Its write commands load the file with every ${VARIABLE} expanded and save it back that way. infer mcp disable turned x-api-key: ${MCP_CHECK_KEY} into the plain value of the variable, which both breaks the reference and leaves the secret on disk. infer mcp start, stop and status leave the file as written, and those are the only ones the app runs.

Changes

  • backend/src/mcp_settings.rs (new):
    • Reads and writes mcp.yaml as YAML, so a ${VARIABLE} stays a reference. An edit keeps every key the form does not know, such as include_tools, env or volumes, and every other server.
    • A hosted server has a URL and headers. A header is <prefix>${VARIABLE}, such as Bearer ${GITHUB_TOKEN}. A header written in mcp.yaml with a plain value reads back as literal, without its value, so the value never reaches the UI.
    • A container server (run: true) has an image (oci) and a port. Saving starts or stops its shared container to match whether this computer gets it, and deleting stops it first.
    • enabled is whether this computer connects to a server. A hosted server can also go to Kubernetes workspaces, listed under their mcp_servers in daemon.yaml, the shape [FEATURE] Kubernetes workspaces give their pods MCP servers cli#1760 proposes. A change there reports that daemon.yaml changed, so the tab asks for a CLI restart.
    • Refused: an invalid or taken name, a hosted server without an http(s) URL, a container server without an image and a port or given to a workspace, two headers with one name, a header whose variable no secret or API key provides, a non-Kubernetes workspace, and turning a hosted server into a container one or back.
    • The global switch is enabled at the top of mcp.yaml.
  • backend/src/tools.rs: mcp_status keeps the per-server rows of infer mcp status beside the counts the status bar shows.
  • backend/src/markdown_agents.rs: mcpServers in an agent's frontmatter reads and writes as a list of server names, and is gone from the file when none is picked. An inline server definition, which Claude Code also accepts, is left out, since agent files travel and never carry a URL or a header.
  • backend/src/workspace_settings.rs: list_secret becomes list_on, which lists any item under any key of the workspaces named, and WorkspaceConfig reads mcp_servers without the Workspaces tab writing it.
  • backend/src/config.rs: update_file runs under one lock, so two edits of one config file at once never drop each other's change. No closure passed to it calls it again.
  • frontend/components/McpTab.tsx (new): rows with their kind, connection state and where they go, a warning on each place a server goes that has no secret for one of its headers, the hosted and container forms, and the restart notice.
  • frontend/lib/mcp-form.ts (new): the connection state of a row, the missing secrets per place and the variables a header can pick, with tests.
  • frontend/components/AgentEditor.tsx: an MCP servers list of checkboxes, saved as mcpServers. With none picked, the agent uses every server of its computer. A picked server that is gone shows as missing.
  • AGENTS.md: the DOM contract gains the MCP form ids, mcp-enabled, agent-mcp-<server>, and the buttons New hosted server, New container server, Save server, Add header, Check MCP servers, Edit server <name>, Delete server <name> and Remove header <n>.
  • e2e/tests/mcp-settings.yaml: a hosted server added under MCPs lands in mcp.yaml and goes to this computer.

Acceptance criteria of #476

Verification

  • cargo fmt --check, cargo clippy --all-targets -- -D warnings and cargo test pass in backend/. That is 259 tests, through the pre-commit hook. New tests cover reading headers as references, the literal case, a save keeping unknown keys and other servers without expanding anything, every refusal, removing a server, the global switch, the status rows, and mcpServers round-tripping with an inline definition left out.
  • bun run build passes and bun test passes 227 tests. cargo test -p desktop-e2e validates the e2e YAML.
  • Against a CLI built from main, in a throwaway home:
    • infer mcp status --format json reads a file in this shape and probes each server at its url.
    • infer mcp start, stop and status leave the file byte for byte as written.
    • infer mcp disable writes the expanded header value.
  • The installed infer here is v0.247.1, which predates url and probed http://localhost/mcp instead. Hosted servers need v0.248.0 or later.
  • I did not run the macOS e2e suite, because it drives the real UI. The new test adds a hosted server without headers, since the driver can neither pick a select option nor tick a checkbox.

Known gaps

Cross-repo impact

… theirs

The MCPs tab lists the servers of mcp.yaml with their connection state from
infer mcp status, beside the global switch. A hosted server takes a URL and
headers whose values are secrets from the Secrets tab, written as ${VARIABLE}.
A container server takes an image and a port, and its container follows
whether this computer gets it.

The tab edits mcp.yaml as written rather than through infer mcp, whose write
commands save the file with every ${VARIABLE} expanded. An edit keeps the keys
the form does not know.

A hosted server can be given to Kubernetes workspaces through mcp_servers in
daemon.yaml, and the agent editor saves the servers an agent picks as
mcpServers in its file.

Every update_file now runs under one lock, so two edits of one config file at
once never drop each other's change.
@edenreich
edenreich marked this pull request as ready for review November 8, 2026 18:40
@edenreich
edenreich merged commit 096f055 into main Nov 8, 2026
1 check passed
@edenreich
edenreich deleted the feat/mcps-tab branch November 8, 2026 18:42
edenreich added a commit to inference-gateway/cli that referenced this pull request Nov 8, 2026
#1765)

Closes #1764

## Summary

Every `infer mcp` command that saves `mcp.yaml`, and every `infer
agents` command that saves `agents.yaml`, wrote the file back with each
`${VAR}` reference replaced by the variable's value. They edited the
copy loaded to run with, which `LoadYAML` had already passed through
`os.ExpandEnv`. A header written as `x-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 `UpdateEntry`
receives a whole entry read from the expanded copy. An edit now starts
from a copy loaded as written.

## Changes

- `config/utils/yamlfile.go`:
- `LoadYAML` keeps expanding, for running. `LoadYAMLAsWritten` reads a
file as written, for editing. Both share one loader.
- A save keeps the file's mode, so a file its owner tightened to 0600
stays that way. A new file still gets 0644.
- `config/mcp.go`, `config/agents.go`:
- `LoadMCP` and `LoadAgents` load to run with, and their entries refuse
to save with an error that says why, instead of writing values over
references.
- `LoadMCPForEdit` and `LoadAgentsForEdit` load as written and can save.
- The edit commands use the edit loaders: `infer mcp` `add`, `update`,
`remove`, `enable`, `disable`, `enable-global` and `disable-global`, and
`infer agents` `add`, `update` and `remove`. 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. `ResolveDir` expands a plugins `dir`
itself. 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 seven `infer
mcp` edit commands, run as `infer mcp <edit>` through a fresh
`root.NewCommand()` with `MCP_CHECK_KEY` set:
- The root's `PersistentPreRunE` loads the config into a Viper of its
own, as a real run does.
- HOME and the working directory are 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.
- Each case checks that the reference survives, the value never lands in
the file, and the 0600 mode stays.
- Against unmodified `main`, all seven fail with the key written into
`mcp.yaml`.
- Config tests cover:
- an agent's `environment` reference surviving an update, and the
expanded copy refusing to save;
  - `LoadMCP` refusing to save and leaving the file untouched;
  - `${HOME}` surviving a saved sandbox grant;
  - the plugins dir expanding;
- `LoadYAMLAsWritten` keeping a reference through a save, and the file
mode kept or defaulted.
- Existing tests that create, update or delete entries move to the edit
loaders. The expansion tests stay on the run loaders.

## Verification

- `task precommit:run` passes (mod tidy, mocks, fmt, lint with 0 issues,
markdownlint).
- `go test ./...` passes.
- `task test:e2e` passes in 307s.

## Trade-offs

- A non-string field written as a reference, such as `port:
${MCP_PORT}`, now fails to parse in the edit commands. Before, an edit
wrote the expanded value over it. Running is unchanged.
- A sandbox grant compares paths as written, so approving
`/Users/me/repos` beside an existing `${HOME}/repos` entry adds a second
entry rather than matching the first.

## Cross-repo impact

- `desktop`: none needed. inference-gateway/desktop#480 edits `mcp.yaml`
itself and runs only `infer mcp start`, `stop` and `status`, 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.
edenreich added a commit to inference-gateway/cli that referenced this pull request Nov 8, 2026
…1766)

## Summary

A Markdown agent now names the MCP servers its threads bring up with
`mcpServers`, the key Claude Code uses:

```yaml
---
name: timekeeper
description: Tells the current time in any timezone.
mcpServers:
  - demo-server
---
```

- Without the key a thread gets the enabled servers of its computer, as
before. An empty list gives it none.
- The worker connects only the named servers and starts only those with
`run: true`, so an agent never starts a container it does not use.
- A named server comes up even when `mcp.yaml` sets `enabled: false` for
it. A server can then stay off for plain chats and serve only the agent
that names it, such as an agent's own mailbox. The top-level
`mcp.enabled: false` still turns MCP off for every agent.
- A name the computer's `mcp.yaml` lacks is skipped with a warning, and
the thread still opens.
- An inline server definition is ignored with a warning, so agent files
never carry a URL, a header or a secret.

Closes #1759

## How it flows

The list takes the path the tool lists take:

1. `mdagent.go` reads `mcpServers` as names.
2. `ResolveThreadAgent` puts them on the thread options when a thread
opens as the agent on the daemon.
3. `ThreadOptions.MCPServers` is part of `Portable()`, so a relay or a
teleport carries the resolved list, never the agent name. It is
`omitzero`, so an empty list survives the wire as `[]`.
4. The worker gets `INFER_AGENT_MCP_SERVERS`, and the container narrows
`mcp.yaml` with `mcp.SelectServers` before the MCP supervisor connects
or starts anything.

A subagent the `Agent` tool starts gets the same list on every spawn
path: a daemon thread, `headless --keep-alive` and the tmux pane.

## Tests

- `tests/e2e/agent_mcp_test.go` runs two stateless MCP servers (protocol
2026-07-28, `server/discover` without `initialize` or a session). The
daemon opens a thread as an agent naming `chosen` (disabled in
`mcp.yaml`) and `ghost`. The model is offered `MCP_chosen_echo` and not
`MCP_other_echo`, the call reaches `chosen`, and `other` gets no request
at all. A thread without an agent then gets `other` and not `chosen`.
Against a binary built from `main`, the agent's thread gets `other`
instead and the test fails.
- Unit tests cover the frontmatter (names, an empty list, an inline
definition), the `Portable()` and JSON round trip, the worker env, the
`Agent` tool's env and thread options, and `SelectServers`.
- `task test:e2e`, `task precommit:run` and `go test ./...` pass.

## Examples and docs

- `examples/mcp/agents/` holds `timekeeper`, which uses only the demo
server, and `summarizer`, which uses none. Both are mounted into the
example's CLI container.
- `docs/subagents.md` documents the key in a new MCP Servers section and
drops it from the ignored keys and the limitations.
`docs/mcp-integration.md` points to it.

## Known gaps

- The warning for a missing server names the server and not the agent.
The worker never learns the agent's name, since a relay carries the
resolved lists instead. The daemon tags the worker's log lines with the
conversation.
- For a subagent the `Agent` tool starts, MCP tool names in a `tools`
list are still dropped as unknown, because MCP tools register after the
session starts. A thread opened as the agent on the daemon keeps them.
This is documented under Limitations.

## Cross-repo impact

- `desktop`: inference-gateway/desktop#480 already writes `mcpServers`
from the agent editor and opens threads by agent name, so no frame
change is needed.
- `docs`: inference-gateway/docs#1136 documents `mcpServers` for
Markdown agents.
edenreich added a commit to inference-gateway/cli 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.
@inference-gateway-maintainer

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.60.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@inference-gateway-maintainer inference-gateway-maintainer Bot added the released Shipped in a release label Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] MCPs tab, and agents pick the MCP servers they use

1 participant