fix(server): reject non-string group names - #3630
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds validation tests for config group names and refactors nameless group configuration parsing. The reviewer suggested optimizing the nameless group parsing logic by checking the resource kind first, which avoids redundant map lookups for non-group resources.
|
Good catch on name validation! :) Is there a reason to completely reject non-string names? For MCP specification, the tool name have these rules (https://modelcontextprotocol.io/specification/draft/server/tools#tool-names) :
mcp-toolbox/internal/server/config.go Line 520 in 1b416ed Seems like numbers and certain characters are allowed~ should we follow these? prompt names does not have any rules. |
|
Thanks a lot @Yuan325, The key distinction here is between the allowed characters inside a name and the underlying data type parsed from the YAML. While the MCP spec allows digits ( If a user writes If we were to accept raw integers and secretly convert them to strings under the hood, we'd be bypassing strict YAML typing, which is innaccurate (e.g., a boolean Users are still completely free to use numbers in their names! They just need to explicitly quote them (e.g., |
|
Hi @Deeven-Seru, in the config file, if a user defines name as an integer (like name: 123) and our server rejects it, that is completely acceptable and expected. Because we unmarshal into a generic map[string]any first, the parser evaluates 123 as an int, meaning the .(string) type assertion will fail and safely return an error stating that a string is required. I also noticed that @twishabansal has already added test cases specifically covering these scenarios (like name: 123), which should address your concerns and ensure our validation behaves correctly. LMK if you have any other thoughts! :) |
|
I also just realized that the NameValidation was removed previously during migration to flat-format config file, I'll submit a PR to add that back to Tool's unmarshaling~ Thanks for point that out @Deeven-Seru :) |
|
🧨 Preview deployments removed. Cloudflare Pages environments for |
Description
Reinstates the
(!present || rawName == nil)guard inUnmarshalResourceConfigthat was accidentally dropped during the merge of the groups stack intofeat/groups.Without the guard, a config like:
would silently default to the empty (default) group instead of returning a parse error. Deeven Seru flagged this in the review of #3575.
The fix ensures non-string name values (
name: 123,name: true) are rejected with"missing 'name' field or it is not a string", while legitimately absent or null names are still accepted as the default group.Adds regression tests to
TestParseConfigGroupNameValidationcovering all four cases.