Skip to content

fix(server): reject non-string group names - #3630

Merged
twishabansal merged 5 commits into
feat/groupsfrom
fix/group-name-type-validation
Jul 20, 2026
Merged

fix(server): reject non-string group names#3630
twishabansal merged 5 commits into
feat/groupsfrom
fix/group-name-type-validation

Conversation

@twishabansal

@twishabansal twishabansal commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Description

Reinstates the (!present || rawName == nil) guard in UnmarshalResourceConfig that was accidentally dropped during the merge of the groups stack into feat/groups.

Without the guard, a config like:

kind: group
name: 123

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 TestParseConfigGroupNameValidation covering all four cases.

@twishabansal
twishabansal requested a review from a team as a code owner July 15, 2026 08:59

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/server/config.go Outdated
@twishabansal twishabansal assigned Yuan325 and unassigned duwenxin99 Jul 15, 2026
@twishabansal twishabansal added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Jul 15, 2026
@Yuan325

Yuan325 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

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) :

  • Length: 1–128 characters
  • Case-sensitive
  • Allowed characters: A-Z, a-z, 0-9, _, -, .
  • No spaces, commas, or special characters
  • Unique within a server_

func NameValidation(name string) error {

Seems like numbers and certain characters are allowed~ should we follow these? prompt names does not have any rules.

@Deeven-Seru

Deeven-Seru commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

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 (0-9) as characters, the protocol uses JSON-RPC, meaning the name identifier must fundamentally be typed as a string.

If a user writes name: 123 in their config without quotes, the Go YAML parser strictly evaluates it as an int. This correctly causes the .(string) type assertion to fail because an integer is not a string.

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 name: true turning into "true").

Users are still completely free to use numbers in their names! They just need to explicitly quote them (e.g., name: "123"). The YAML parser will then treat it as a string which passes the type assertion, and our NameValidation regex perfectly handles validating the characters against the spec.

@Yuan325

Yuan325 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

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! :)

@Yuan325

Yuan325 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

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 :)

Comment thread cmd/internal/config_test.go
@twishabansal twishabansal removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Jul 20, 2026
@twishabansal
twishabansal merged commit e32c4c4 into feat/groups Jul 20, 2026
15 of 16 checks passed
@twishabansal
twishabansal deleted the fix/group-name-type-validation branch July 20, 2026 07:31
@github-actions

Copy link
Copy Markdown
Contributor

🧨 Preview deployments removed.

Cloudflare Pages environments for pr-3630 have been deleted.

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.

4 participants