platform
This commit is contained in:
1 parent
e706f7d907
commit
21bcb63440
42 files changed
+5903
No files matched your search
@@ -0,0 +1,55 @@
|
||||
package mcp
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
// Tiny JSON-Schema builders for tool input schemas. They keep tool definitions
|
||||
// readable without a schema dependency.
|
||||
|
||||
// Props is a set of named property schemas for Object.
|
||||
type Props map[string]json.RawMessage
|
||||
|
||||
// Object builds an object JSON Schema from named property schemas and the list
|
||||
// of required keys. required may be nil.
|
||||
func Object(p Props, required []string) json.RawMessage {
|
||||
schema := map[string]any{"type": "object"}
|
||||
if len(p) > 0 {
|
||||
schema["properties"] = p
|
||||
} else {
|
||||
schema["properties"] = map[string]any{}
|
||||
}
|
||||
if len(required) > 0 {
|
||||
schema["required"] = required
|
||||
}
|
||||
b, _ := json.Marshal(schema)
|
||||
return b
|
||||
}
|
||||
|
||||
// Scalar builds a single-typed schema with a description (e.g. Scalar("integer", …)).
|
||||
func Scalar(typ, desc string) json.RawMessage {
|
||||
b, _ := json.Marshal(map[string]string{"type": typ, "description": desc})
|
||||
return b
|
||||
}
|
||||
|
||||
func String(desc string) json.RawMessage { return Scalar("string", desc) }
|
||||
func Integer(desc string) json.RawMessage { return Scalar("integer", desc) }
|
||||
func Number(desc string) json.RawMessage { return Scalar("number", desc) }
|
||||
func Bool(desc string) json.RawMessage { return Scalar("boolean", desc) }
|
||||
func ObjectValue(desc string) json.RawMessage {
|
||||
return Scalar("object", desc)
|
||||
}
|
||||
|
||||
// StringArray builds an array-of-strings schema.
|
||||
func StringArray(desc string) json.RawMessage {
|
||||
b, _ := json.Marshal(map[string]any{
|
||||
"type": "array", "description": desc, "items": map[string]string{"type": "string"},
|
||||
})
|
||||
return b
|
||||
}
|
||||
|
||||
// ObjectArray builds an array-of-objects schema.
|
||||
func ObjectArray(desc string) json.RawMessage {
|
||||
b, _ := json.Marshal(map[string]any{
|
||||
"type": "array", "description": desc, "items": map[string]string{"type": "object"},
|
||||
})
|
||||
return b
|
||||
}
|
||||
Reference in new issue
Block a user