@@ -295,7 +295,8 @@ func (c *Client) elicit(ctx context.Context, req *ElicitRequest) (*ElicitResult,
295295 }
296296
297297 // Validate that the requested schema only contains top-level properties without nesting
298- if err := validateElicitSchema (req .Params .RequestedSchema ); err != nil {
298+ schema , err := validateElicitSchema (req .Params .RequestedSchema )
299+ if err != nil {
299300 return nil , jsonrpc2 .NewError (CodeInvalidParams , err .Error ())
300301 }
301302
@@ -305,11 +306,11 @@ func (c *Client) elicit(ctx context.Context, req *ElicitRequest) (*ElicitResult,
305306 }
306307
307308 // Validate elicitation result content against requested schema
308- if req . Params . RequestedSchema != nil && res .Content != nil {
309+ if schema != nil && res .Content != nil {
309310 // TODO: is this the correct behavior if validation fails?
310311 // It isn't the *server's* params that are invalid, so why would we return
311312 // this code to the server?
312- resolved , err := req . Params . RequestedSchema .Resolve (nil )
313+ resolved , err := schema .Resolve (nil )
313314 if err != nil {
314315 return nil , jsonrpc2 .NewError (CodeInvalidParams , fmt .Sprintf ("failed to resolve requested schema: %v" , err ))
315316 }
@@ -324,14 +325,23 @@ func (c *Client) elicit(ctx context.Context, req *ElicitRequest) (*ElicitResult,
324325
325326// validateElicitSchema validates that the schema conforms to MCP elicitation schema requirements.
326327// Per the MCP specification, elicitation schemas are limited to flat objects with primitive properties only.
327- func validateElicitSchema (schema * jsonschema.Schema ) error {
328- if schema == nil {
329- return nil // nil schema is allowed
328+ func validateElicitSchema (wireSchema any ) (* jsonschema.Schema , error ) {
329+ if wireSchema == nil {
330+ return nil , nil // nil schema is allowed
331+ }
332+
333+ data , err := json .Marshal (wireSchema )
334+ if err != nil {
335+ return nil , err
336+ }
337+ var schema * jsonschema.Schema
338+ if err := json .Unmarshal (data , & schema ); err != nil {
339+ return nil , err
330340 }
331341
332342 // The root schema must be of type "object" if specified
333343 if schema .Type != "" && schema .Type != "object" {
334- return fmt .Errorf ("elicit schema must be of type 'object', got %q" , schema .Type )
344+ return nil , fmt .Errorf ("elicit schema must be of type 'object', got %q" , schema .Type )
335345 }
336346
337347 // Check if the schema has properties
@@ -342,12 +352,12 @@ func validateElicitSchema(schema *jsonschema.Schema) error {
342352 }
343353
344354 if err := validateElicitProperty (propName , propSchema ); err != nil {
345- return err
355+ return nil , err
346356 }
347357 }
348358 }
349359
350- return nil
360+ return schema , nil
351361}
352362
353363// validateElicitProperty validates a single property in an elicitation schema.
0 commit comments