@@ -69,17 +69,20 @@ func requiredParam[T comparable](r mcp.CallToolRequest, p string) (T, error) {
6969
7070 // Check if the parameter is present in the request
7171 if _ , ok := r .GetArguments ()[p ]; ! ok {
72- return zero , fmt . Errorf ( "missing required parameter: %s" , p )
72+ return zero , MissingRequiredParameterError { Parameter : p }
7373 }
7474
7575 // Check if the parameter is of the expected type
7676 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+ }
7882 }
7983
8084 if r .GetArguments ()[p ].(T ) == zero {
81- return zero , fmt .Errorf ("missing required parameter: %s" , p )
82-
85+ return zero , MissingRequiredParameterError {Parameter : p }
8386 }
8487
8588 return r .GetArguments ()[p ].(T ), nil
@@ -112,7 +115,11 @@ func OptionalParam[T any](r mcp.CallToolRequest, p string) (T, error) {
112115
113116 // Check if the parameter is of the expected type
114117 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+ }
116123 }
117124
118125 return r .GetArguments ()[p ].(T ), nil
@@ -163,13 +170,21 @@ func OptionalStringArrayParam(r mcp.CallToolRequest, p string) ([]string, error)
163170 for i , v := range v {
164171 s , ok := v .(string )
165172 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+ }
167178 }
168179 strSlice [i ] = s
169180 }
170181 return strSlice , nil
171182 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+ }
173188 }
174189}
175190
0 commit comments