Skip to content

Commit 058dd22

Browse files
committed
address review comments
1 parent 079bb32 commit 058dd22

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

mcp/tool.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,21 @@ func applySchema(data json.RawMessage, resolved *jsonschema.Resolved) (json.RawM
103103
return data, nil
104104
}
105105

106+
// validateToolName checks whether name is a valid tool name, reporting a
107+
// non-nil error if not.
106108
func validateToolName(name string) error {
107109
if name == "" {
108110
return fmt.Errorf("tool name cannot be empty")
109111
}
110112
if len(name) > 128 {
111113
return fmt.Errorf("tool name exceeds maximum length of 128 characters (current: %d)", len(name))
112114
}
115+
// For consistency with other SDKs, report characters in the order the appear
116+
// in the name.
113117
var invalidChars []string
114118
seen := make(map[rune]bool)
115119
for _, r := range name {
116-
if !((r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == '_' || r == '-' || r == '.') {
120+
if !validToolNameRune(r) {
117121
if !seen[r] {
118122
invalidChars = append(invalidChars, fmt.Sprintf("%q", string(r)))
119123
seen[r] = true
@@ -125,3 +129,11 @@ func validateToolName(name string) error {
125129
}
126130
return nil
127131
}
132+
133+
// validToolNameRune reports whether r is valid within tool names.
134+
func validToolNameRune(r rune) bool {
135+
return (r >= 'a' && r <= 'z') ||
136+
(r >= 'A' && r <= 'Z') ||
137+
(r >= '0' && r <= '9') ||
138+
r == '_' || r == '-' || r == '.'
139+
}

0 commit comments

Comments
 (0)