Skip to content

Add MCP server config writers for coding agents - #7539

Draft
simonfaltum wants to merge 6 commits into
mainfrom
aitools-mcp/01-agentconfig
Draft

simonfaltum wants to merge 6 commits into
mainfrom
aitools-mcp/01-agentconfig

Conversation

@simonfaltum

@simonfaltum simonfaltum commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

This pull request is part of a stack that adds the hidden databricks aitools mcp command group. It adds the layer that knows where each coding agent keeps its MCP server entries, and writes one entry without changing anything else in the file. No command uses it yet.

Changes

  • libs/aitools/mcp/agentconfig adds Upsert, Remove and Read. Writes are atomic, keep the file mode, and are skipped when the entry already matches.
  • Upsert refuses an entry this CLI did not write unless force is set. It also refuses a server name outside [A-Za-z0-9_-], and a command or args that would make the entry unrecognizable later.
  • An update changes only the launch keys the agent's builder writes. Other keys stay. In env, only DATABRICKS_CONFIG_FILE is the CLI's.
  • JSON and JSONC are edited with hujson patches, so only changed members are touched. TOML is edited as text, only the server's own tables, and the result is decoded again before it is written.
  • libs/aitools/agents gives seven agents an MCP spec: Claude Code, Codex, Cursor, Copilot CLI, Gemini CLI, OpenCode and Antigravity.
  • libs/localenv exports ProtectMultilineStrings, renamed with no behavior change.

Why

Each agent keeps MCP servers in a different file and shape. A user's agent config must keep its other settings, so the writer keeps comments and layout outside the entry it changes, and refuses any file it cannot parse.

Decisions to review

  • TOML updates rewrite the server's own tables. Comments inside those tables are lost on update. Editing single lines would keep them; that is not in this change.
  • Keys the user added survive a re-add, including a Copilot tools list they narrowed. The alternative replaces the whole entry.
  • OpenCode with both opencode.json and opencode.jsonc present is refused, and the OpenCode entry uses the current docs' form: mcp.servers, variables under environment, no enabled key.
  • ~/.claude.json is written without a lock. Claude Code takes none, so a write it makes between our read and rename would be lost. The window is milliseconds.

Tests

  • TestRoundTripPerAgent writes, rewrites and removes an entry for each agent, on fixtures with unrelated keys. It also passes with CRLF fixtures.
  • Byte-level tests cover update, add and remove layouts in LF and CRLF files.
  • Ran: go test -race ./libs/aitools/... ./libs/localenv/... ./libs/testserver/, go test ./cmd/aitools/..., the TestAccept/cmd/aitools and TestAccept/localenv acceptance tests, GOOS=windows and GOOS=darwin go vet, golangci-lint (0 issues), and ./task checks.
  • Not tested: whether agents read the entries this writes. Windows and macOS CI have not run yet.

How to review

Read writer.go (Upsert, keepUserKeys, mergeEnv) and toml.go (put, dropTable, appendBlock) closely. json.go is patch plumbing over hujson.

This pull request and its description were written by Isaac.

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: 07cc225

Run: 43449193151

Env 🔄​flaky 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 270 15 9:32
💚​ aws-windows-latest-4core-16gb 1 272 13 7:47
💚​ azure linux-2core-8gb 1 269 15 8:41
🔄​ azure-windows-latest-4core-16gb 1 1 270 13 7:32
💚​ gcp linux-2core-8gb 1 270 15 9:46
🔄​ gcp-windows-latest-4core-16gb 1 1 271 13 8:22
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
🔄​ TestSyncIncrementalFileOverwritesFolder ✅​p ✅​p ✅​p 🔄​f ✅​p 🔄​f
Top 7 slowest tests (at least 2 minutes):
duration env testname
3:18 aws-windows-latest-4core-16gb TestAccept
3:17 gcp-windows-latest-4core-16gb TestAccept
3:15 azure-windows-latest-4core-16gb TestAccept
2:51 gcp linux-2core-8gb TestFilerWorkspaceFilesExtensionsReadDir
2:27 gcp-windows-latest-4core-16gb TestFilerReadWrite/workspace_files_extensions
2:27 aws linux-2core-8gb TestFilerWorkspaceFilesExtensionsDelete
2:26 azure-windows-latest-4core-16gb TestSyncIncrementalFileSync

simonfaltum and others added 6 commits November 13, 2026 14:40
Add a per-agent description of where each coding agent keeps its user-scope
MCP server entries, and the writers that add, remove and list the entries
this CLI owns without touching anything else in the file.

- libs/aitools/mcpconfig: Spec (path, format, root key, entry shape, ownership).
- libs/aitools/agents: MCP spec for seven agents, nil for the others;
  SupportsMCP and MCPAgents.
- libs/aitools/mcp/agentconfig: Upsert, Remove and Read over JSON and TOML
  config files. Writes are atomic, keep the file mode, write through
  symlinks, and skip the write when the entry already matches. Files that
  cannot be parsed are refused and left untouched. Entries not written by
  this CLI are refused unless forced.

JSON keeps key order and the bytes of values it does not change. TOML is
decoded and re-encoded, so comments are dropped on any rewrite.

Co-authored-by: Isaac <no-reply@databricks.com>
JSON and JSONC entries are changed with hujson patches, so comments, trailing
commas, a leading BOM and the bytes of everything else are kept. TOML entries
are changed as text: only the lines of the server's own tables are replaced
or removed, and the edited text is decoded and checked before it is written.

Upsert refuses a command that is not named databricks, since such an entry
could not be recognized later. A symlink whose target is missing is refused
rather than replaced. OpenCode prefers an existing opencode.jsonc.

Co-authored-by: Isaac <no-reply@databricks.com>
JSON: a comment on the previous member's line stays there when a member
is added. An empty table gets its closing brace on its own line. A file
with only comments and an empty object keeps its comments. Removing the
last member keeps a strict file strict and keeps a trailing comma that
was there. Inserted text uses the file's line ending.

Upsert updates an entry this CLI wrote only in the keys the builders
write, so keys the user added (for example disabled or enabled) survive
a re-add. An entry that differs only in those keys is not rewritten.
--force still replaces a foreign entry as a whole. Antigravity entries
no longer write disabled: false, since the key is optional.

Upsert refuses a server name outside [A-Za-z0-9_-] and says whether the
command or the args are wrong. Error messages show paths with forward
slashes. Tests set the agent overrides on the context instead of the
process environment.

Co-authored-by: Isaac <no-reply@databricks.com>
- Update sets only the launch keys (command, args, env, environment,
  type). Other keys are kept, and defaults such as Copilot's tools list
  are written only on first add. An entry whose launch keys match is not
  rewritten.
- JSON updates patch the changed launch keys in place, so the other
  members keep their bytes. Numbers in user values are decoded with
  UseNumber.
- JSON duplicate member names on the root and server path are refused
  as ErrConfigInvalid.
- TOML table headers are found with multi-line strings protected, using
  localenv's helper, now exported as ProtectMultilineStrings. Quoted keys
  are parsed, so a quoted "genie.x" is not "genie", and a header-like line
  inside a string is text.
- Removing a table keeps one blank line between its neighbours, and
  removing the first server leaves no blank first line.
- Remove checks the server name as Upsert does.
- The OpenCode path returns stat errors other than not-exist.
- New config directories are created 0700.
- Smaller fixes: top-level JSON error wording, IsUnmanaged comment,
  mcpconfig.IsDatabricksBinary, BOM strip via bytes.CutPrefix,
  ValidServerName without a package-level regexp, and a Windows-safe
  path assertion in toml_test.

Co-authored-by: Isaac <no-reply@databricks.com>
Update only what the CLI owns in an existing entry. Launch keys are the ones
the agent's builder writes, so a key the builder never writes (type, for most
agents) is kept. In env tables only DATABRICKS_CONFIG_FILE is the CLI's, and
user variables are kept.

Compare TOML edits as TOML text, so inf and nan in an unrelated table no longer
block an edit. Add blank-line layout that keeps one blank line before a new
server and restores the file's own bytes when the server is removed again.

Refuse OpenCode when both opencode.json and opencode.jsonc exist, and treat a
dangling opencode.jsonc link as the file to edit, so the write is refused.

Keep CRLF on the newlines hujson writes for a new member. Collapse the TOML
set/update/remove wrappers into one put, and fix the test comments and
assertions flagged in review.

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@simonfaltum
simonfaltum force-pushed the aitools-mcp/01-agentconfig branch from 6f07e48 to 07cc225 Compare November 13, 2026 15:05

This branch has not been deployed

No deployments
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