Skip to content

fix(mecated): mcp add settings corruption and late illegal-name failure - #2038

Merged
tgrunnagle merged 2 commits into
mainfrom
fix/mcp-mutate-nested-indent
Oct 1, 2026
Merged

tgrunnagle merged 2 commits into
mainfrom
fix/mcp-mutate-nested-indent

Conversation

@tgrunnagle

@tgrunnagle tgrunnagle commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two mecated mcp add bugs.

Settings corruption with a mode-only mcp section

mecated mcp add corrupted settings when the mcp: section held only mode (e.g. mcp: {mode: global} in block form). The inserted servers: fragment was parsed standalone at column 1 and kept that position, so goccy/go-yaml serialized it as a top-level key instead of mcp.servers — mecatl then never found the server:

mcp:
  mode: global
servers:          # should be under mcp
    - name: 'srv'

RemoveDirectMCPServer had the inverse bug: removing the last server replaced the section with mode: global written at the document root. This is also the most likely way operators reach the mode-only state in the first place (remove → add).

Fix

Add alignDirectMCPEntry, which shifts a standalone fragment to the column of the parent mapping's existing keys before appending — the same approach provider_map_mutate.go already uses. Both the add (servers insertion) and remove (mode: global re-insertion) paths use it.

Illegal server names fail late and opaquely

mecated mcp add connector-gateway ... ran discovery and custody selection, then failed with invalid permission config schema at mcp (line N). Server names must match [A-Za-z0-9_]+ without __ because they derive the MCP_<NAME>_TOKEN env var (ADR 0082). The CLI and mcplifecycle.Add now validate the name first, before discovery or custody selection (which can provision key material), with an actionable error:

invalid MCP server name "connector-gateway": names may contain only ASCII letters, digits, and single underscores, because the name becomes part of an environment variable name (try "connector_gateway")

permconfig.ValidateMCPServerName is exported so the schema and the early check share one rule. The naming rule is documented in user-docs/features/mcp-oauth-and-credentials.md.

Tests

  • New TestDirectMCPMutationNestsUnderModeOnlySection: add then remove against 2- and 4-space indented mcp: mode: global, parsed through the real schema to assert mcp.mode and mcp.servers land correctly. Mutation-checked: fails without the fix.
  • New TestDirectMCPLifecycleAddRejectsIllegalNameBeforeDiscovery and CLI-level TestDirectMCPAddRejectsIllegalNameBeforeDiscovery (discovery stub fails the test if called; asserts no progress output and settings unchanged). Both mutation-checked.
  • go test passes for permconfig, mcplifecycle, and cmd/mecated MCP tests; task docs and task site:build pass; go run ./cmd/mecademo shows tool call, permission ask/approval, and result.

Pre-existing gate failures (also on main, unrelated to this change)

  • task lint: 3 staticcheck SA4023 findings in cmd/mecatl-executor/main.go and internal/executionexecutor/executor.go.
  • task test:race: TestDevelopmentReleaseInputsRemainBoundAfterPathReplacement, TestDevelopmentReleaseDownloadNeverUsesHTTP (microvmmanager, "release bundle omitted the platform manifest") and TestMecatedCLICompositionValidatesMicroVMDefaultAfterReadiness (cmd/mecated).

Follow-ups (not in this PR)

  • Flow-style mcp: {mode: global} still fails add, cleanly with "updated settings document is invalid" rather than corrupting the file.
  • ValidateYAML accepted the corrupted output (unknown top-level servers/mode keys), which is why the bug surfaced late. Consider whether stricter root-key validation is wanted.

🤖 Generated with Claude Code

Adding a server to an mcp section that held only `mode` appended a
`servers` fragment parsed at column 1, which serialized as a top-level
key instead of mcp.servers, so the server was never found. Removing
the last server had the inverse bug, writing `mode: global` at the
document root. Shift the fragment to the existing keys' column, as
provider_map_mutate already does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@tgrunnagle
tgrunnagle requested a review from jhrozek October 1, 2026 08:40
`mecated mcp add connector-gateway ...` ran protected-resource
discovery and credential custody selection, then failed schema
validation with an opaque "invalid permission config schema at mcp"
error: names must match [A-Za-z0-9_]+ without "__" because they derive
the MCP_<NAME>_TOKEN environment variable.

Validate the name first, in both the CLI and mcplifecycle.Add, with an
error that states the rule, the reason, and a suggested legal name.
Export permconfig.ValidateMCPServerName so the schema and the early
check share one rule, and document the naming rule on the owning page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@tgrunnagle tgrunnagle changed the title fix(permconfig): keep MCP mutations nested under mode-only mcp section fix(mecated): mcp add settings corruption and late illegal-name failure Oct 1, 2026
@tgrunnagle
tgrunnagle merged commit 38e8c15 into main Oct 1, 2026
37 checks passed
@tgrunnagle
tgrunnagle deleted the fix/mcp-mutate-nested-indent branch October 1, 2026 09:38
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Oct 7, 2026
2 tasks

This branch was successfully deployed

1 active deployment
Preview — 5b81f2d3 Deployed Oct 1, 2026 by vercel[bot]
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.

2 participants