Repository navigation
fix(config): address dotted MCP server names in config set - #1826
Conversation
setMCPServerValue parsed keys with SplitN(key, ".", 3), so a server name containing dots could never be configured: mcp_servers.github.v2.type resolved to name "github" and field "v2.type", failing with a misleading unknown-field error, while runConfigUnset already accepts the same dotted name. alibaba#1661 switched providers/custom_providers to last-dot parsing; this completes the same fix for mcp_servers, with segment validation so mistyped keys cannot create empty-segment names.
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s). |
|
Hi maintainers — both the CLA and code-review checks pass, but this PR has not had a human review yet. Could someone take a look when available? Please let me know if there is a required update from me. |
NanaseInori
left a comment
There was a problem hiding this comment.
Reviewed both changed files, the surrounding field setter and its prefix-gated caller, #1825, and the existing discussion. The issue-number search returned only this PR. The provider-name work in #1661 addresses a different setter; this is a justified follow-up for MCP configuration.
Splitting at the last dot preserves the complete server name while leaving the existing flat field validation unchanged. Empty/whitespace-only name segments are rejected before the map is touched. The new tests cover accumulating fields under github.v2, preserving dot-free names, avoiding a leaked github entry, and rejecting malformed keys without changing the existing server. I found no blocking defect in this patch.
Allowing a new dotted MCP name is appropriate here: config set is also the creation path, so copying the provider setter's existing-entry requirement would prevent the intended operation.
Validation was source and regression-test inspection. I did not independently execute the CLI round trip, race detector, or full repository suite.
This review was conducted by NanaseInori's review bot, using the model GPT-6 Astra Pro. If you need a human review, please manually @NanaseInori.
Description
ocr config set mcp_servers.<name>.<field>could not address any server name containing a dot:setMCPServerValueparsed keys withstrings.SplitN(key, ".", 3), somcp_servers.github.v2.typeresolved to namegithub+ fieldv2.typeand failed withunknown MCP server field "v2.type", whileconfig unset mcp_servers.github.v2already handles the same dotted name. Sinceconfig setis the only documented way to create MCP servers, dotted names were un-creatable, and hand-edited dotted entries could only be deleted, never updated.This completes the parsing #1661 established for
providers.*/custom_providers.*: the last dot now separates the field from the server name, and a newvalidateMCPServerNamekeeps mistyped keys (mcp_servers..command,mcp_servers.a..command, whitespace segments) rejected, with rejected writes leaving the config untouched.I deliberately did not carry over #1661's "dotted names must exist before their fields can be set" guard: providers have a separate creation entry (
ocr config set provider <name>/ the provider command), while for MCP serversconfig setitself is the creation path — the guard would make dotted names entirely uncreatable instead of addressable.Type of Change
How Has This Been Tested?
make testpasses locally (25 packages,-race -count=1)New regressions in
config_cmd_test.go:TestSetMCPServerValue_DottedServerName— dotted name is stored under its full spelling, fields accumulate acrosstype/command, dot-free names keep their meaning, no prefix-named entry leaks.TestSetMCPServerValue_DottedServerNameRejectsEmptySegments— malformed keys are all rejected and leave the existing config unchanged.Manual: built main and this branch side by side — on main both
config set mcp_servers.github.v2.type stdioand...command npxfail withunknown MCP server field; on this branch they succeed (exit 0) andconfig unset mcp_servers.github.v2round-trips (Deleted MCP server "github.v2".). Alsogo vet ./cmd/opencodereview/andgofmt -lclean.Checklist
go fmt,go vet)AI tool used: ZCode (GLM) drafted the change and tests under my direction; I reviewed every line before submitting.
Related Issues
Fixes #1825