tinyrelaycommit

Commit 5175718db635

browse files at this commit | history

1diff --git a/internal/mcp/tools.go b/internal/mcp/tools.go
2index c79d29f..b8eb599 100644
3--- a/internal/mcp/tools.go
4+++ b/internal/mcp/tools.go
5@@ -9,6 +9,7 @@ import (
6 "net/http"
7 "regexp"
8 "sort"
9+ "strconv"
10 "strings"
11 )
12
13@@ -168,11 +169,8 @@ func validate(schema map[string]any, value any, path string) error {
14 return fmt.Errorf("%s %s", where(), err)
15 }
16 }
17- if options, ok := schema["enum"].([]string); ok {
18- text, _ := value.(string)
19- if !contains(options, text) {
20- return fmt.Errorf("%s must be one of %s", where(), strings.Join(options, ", "))
21- }
22+ if options := enumOptions(schema["enum"]); len(options) > 0 && !contains(options, scalar(value)) {
23+ return fmt.Errorf("%s must be one of %s", where(), strings.Join(options, ", "))
24 }
25 if pattern, ok := schema["pattern"].(string); ok {
26 text, _ := value.(string)
27@@ -286,6 +284,42 @@ func required(schema map[string]any) []string {
28 return nil
29 }
30
31+// enumOptions renders enum members as strings so integer and string enums
32+// compare the same way.
33+func enumOptions(value any) []string {
34+ switch list := value.(type) {
35+ case []string:
36+ return list
37+ case []int:
38+ out := make([]string, 0, len(list))
39+ for _, item := range list {
40+ out = append(out, strconv.Itoa(item))
41+ }
42+ return out
43+ case []any:
44+ out := make([]string, 0, len(list))
45+ for _, item := range list {
46+ out = append(out, scalar(item))
47+ }
48+ return out
49+ }
50+ return nil
51+}
52+
53+func scalar(value any) string {
54+ switch v := value.(type) {
55+ case string:
56+ return v
57+ case float64:
58+ return strconv.FormatFloat(v, 'f', -1, 64)
59+ case int:
60+ return strconv.Itoa(v)
61+ case bool:
62+ return strconv.FormatBool(v)
63+ }
64+ return ""
65+}
66+
67 func number(value any) (float64, bool) {
68 switch n := value.(type) {
69 case int:

About

ownerc01503e8035f
visibilitypublic
head5175718db635

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs