@@ -69,17 +69,20 @@ func requiredParam[T comparable](r mcp.CallToolRequest, p string) (T, error) {
69
69
70
70
// Check if the parameter is present in the request
71
71
if _ , ok := r .GetArguments ()[p ]; ! ok {
72
- return zero , fmt . Errorf ( "missing required parameter: %s" , p )
72
+ return zero , MissingRequiredParameterError { Parameter : p }
73
73
}
74
74
75
75
// Check if the parameter is of the expected type
76
76
if _ , ok := r .GetArguments ()[p ].(T ); ! ok {
77
- return zero , fmt .Errorf ("parameter %s is not of type %T" , p , zero )
77
+ return zero , InvalidParameterTypeError {
78
+ Parameter : p ,
79
+ Expected : fmt .Sprintf ("%T" , zero ),
80
+ Actual : fmt .Sprintf ("%T" , r .GetArguments ()[p ]),
81
+ }
78
82
}
79
83
80
84
if r .GetArguments ()[p ].(T ) == zero {
81
- return zero , fmt .Errorf ("missing required parameter: %s" , p )
82
-
85
+ return zero , MissingRequiredParameterError {Parameter : p }
83
86
}
84
87
85
88
return r .GetArguments ()[p ].(T ), nil
@@ -112,7 +115,11 @@ func OptionalParam[T any](r mcp.CallToolRequest, p string) (T, error) {
112
115
113
116
// Check if the parameter is of the expected type
114
117
if _ , ok := r .GetArguments ()[p ].(T ); ! ok {
115
- return zero , fmt .Errorf ("parameter %s is not of type %T, is %T" , p , zero , r .GetArguments ()[p ])
118
+ return zero , InvalidParameterTypeError {
119
+ Parameter : p ,
120
+ Expected : fmt .Sprintf ("%T" , zero ),
121
+ Actual : fmt .Sprintf ("%T" , r .GetArguments ()[p ]),
122
+ }
116
123
}
117
124
118
125
return r .GetArguments ()[p ].(T ), nil
@@ -163,13 +170,21 @@ func OptionalStringArrayParam(r mcp.CallToolRequest, p string) ([]string, error)
163
170
for i , v := range v {
164
171
s , ok := v .(string )
165
172
if ! ok {
166
- return []string {}, fmt .Errorf ("parameter %s is not of type string, is %T" , p , v )
173
+ return []string {}, InvalidParameterTypeError {
174
+ Parameter : p ,
175
+ Expected : "string" ,
176
+ Actual : fmt .Sprintf ("%T" , v ),
177
+ }
167
178
}
168
179
strSlice [i ] = s
169
180
}
170
181
return strSlice , nil
171
182
default :
172
- return []string {}, fmt .Errorf ("parameter %s could not be coerced to []string, is %T" , p , r .GetArguments ()[p ])
183
+ return []string {}, InvalidParameterTypeError {
184
+ Parameter : p ,
185
+ Expected : "[]string" ,
186
+ Actual : fmt .Sprintf ("%T" , r .GetArguments ()[p ]),
187
+ }
173
188
}
174
189
}
175
190
0 commit comments