MCPcopy Create free account
hub / github.com/docker/docker-agent / operationSchema

Function operationSchema

pkg/tools/builtin/openapi/openapi.go:294–334  ·  view source on GitHub ↗

operationSchema builds a JSON Schema object describing the tool parameters.

(op *v3.Operation)

Source from the content-addressed store, hash-verified

292
293// operationSchema builds a JSON Schema object describing the tool parameters.
294func operationSchema(op *v3.Operation) map[string]any {
295 properties := map[string]any{}
296 var required []string
297
298 // Path and query parameters.
299 for _, p := range op.Parameters {
300 if p == nil {
301 continue
302 }
303
304 prop := schemaProxyToProperty(p.Schema)
305 if p.Description != "" {
306 prop["description"] = p.Description
307 }
308
309 properties[p.Name] = prop
310 if p.Required != nil && *p.Required {
311 required = append(required, p.Name)
312 }
313 }
314
315 // JSON request body properties (prefixed with "body_").
316 if body := requestBodySchema(op); body != nil {
317 for name, propProxy := range body.Properties.FromOldest() {
318 properties["body_"+name] = schemaProxyToProperty(propProxy)
319 }
320 for _, req := range body.Required {
321 required = append(required, "body_"+req)
322 }
323 }
324
325 schema := map[string]any{
326 "type": "object",
327 "properties": properties,
328 }
329 if len(required) > 0 {
330 schema["required"] = required
331 }
332
333 return schema
334}
335
336// requestBodySchema extracts the JSON schema from an operation's request body, if any.
337func requestBodySchema(op *v3.Operation) *base.Schema {

Callers 1

operationToToolMethod · 0.85

Calls 2

schemaProxyToPropertyFunction · 0.85
requestBodySchemaFunction · 0.85

Tested by

no test coverage detected