forge-toolkit: хелперы для разработки MCP-серверов на Go. - toolkit: args/schema/result/env/probe/server - toolkit/validate: валидаторы синтаксиса - configreload: live-reload конфига по контент-хэшу - docs: ARCHITECTURE, quickstart, mcp-contract - template/ и examples/hello-tool/ - CI (Gitea Actions), лицензия Apache-2.0
70 lines
2.3 KiB
Go
70 lines
2.3 KiB
Go
package toolkit
|
|
|
|
// Schema строит JSON Schema 2020-12 для входных аргументов тула.
|
|
// properties обязана быть объектом, а не null: часть LLM-провайдеров
|
|
// отклоняет "properties": null как невалидную схему тула без аргументов.
|
|
func Schema(properties map[string]any, required []string) map[string]any {
|
|
if properties == nil {
|
|
properties = map[string]any{}
|
|
}
|
|
s := map[string]any{
|
|
"type": "object",
|
|
"properties": properties,
|
|
}
|
|
if len(required) > 0 {
|
|
s["required"] = required
|
|
}
|
|
return s
|
|
}
|
|
|
|
// StrProps описывает строковое свойство (опц. enum допустимых значений).
|
|
func StrProps(desc string, required bool, enum ...string) map[string]any {
|
|
s := map[string]any{"type": "string", "description": desc}
|
|
if len(enum) > 0 {
|
|
s["enum"] = enum
|
|
}
|
|
return s
|
|
}
|
|
|
|
// IntProps описывает целочисленное свойство.
|
|
func IntProps(desc string, required bool) map[string]any {
|
|
return map[string]any{"type": "integer", "description": desc}
|
|
}
|
|
|
|
// NumProps описывает числовое свойство.
|
|
func NumProps(desc string, required bool) map[string]any {
|
|
return map[string]any{"type": "number", "description": desc}
|
|
}
|
|
|
|
// BoolProps описывает булево свойство.
|
|
func BoolProps(desc string, required bool) map[string]any {
|
|
return map[string]any{"type": "boolean", "description": desc}
|
|
}
|
|
|
|
// ArrayStringProps описывает массив строк.
|
|
func ArrayStringProps(desc string, required bool) map[string]any {
|
|
return map[string]any{
|
|
"type": "array",
|
|
"description": desc,
|
|
"items": map[string]any{"type": "string"},
|
|
}
|
|
}
|
|
|
|
// ArrayNumberProps описывает массив чисел.
|
|
func ArrayNumberProps(desc string, required bool) map[string]any {
|
|
return map[string]any{
|
|
"type": "array",
|
|
"description": desc,
|
|
"items": map[string]any{"type": "number"},
|
|
}
|
|
}
|
|
|
|
// ObjectProps описывает объект со строковыми значениями (напр. headers).
|
|
func ObjectProps(desc string, required bool) map[string]any {
|
|
return map[string]any{
|
|
"type": "object",
|
|
"description": desc,
|
|
"additionalProperties": map[string]any{"type": "string"},
|
|
}
|
|
}
|