61 lines
2.4 KiB
Go
61 lines
2.4 KiB
Go
package tools
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"git.totmin.ru/en2zmax/forge-toolkit"
|
|
"github.com/modelcontextprotocol/go-sdk/mcp"
|
|
)
|
|
|
|
// toolkit.go — тонкие адаптеры к общему тулкиту (модуль forge-toolkit).
|
|
// Локальные имена сохраняют хендлеры независимыми от пакета-источника.
|
|
|
|
func requestArgs(req *mcp.CallToolRequest) map[string]any { return toolkit.RequestArgs(req) }
|
|
|
|
func getString(args map[string]any, key, def string) string { return toolkit.GetString(args, key, def) }
|
|
|
|
func requireString(args map[string]any, key string) (string, error) {
|
|
return toolkit.RequireString(args, key)
|
|
}
|
|
|
|
func getInt(args map[string]any, key string, def int) int { return toolkit.GetInt(args, key, def) }
|
|
|
|
func getBool(args map[string]any, key string, def bool) bool { return toolkit.GetBool(args, key, def) }
|
|
|
|
func schema(properties map[string]any, required []string) map[string]any {
|
|
return toolkit.Schema(properties, required)
|
|
}
|
|
|
|
func strProps(desc string, required bool, enum ...string) map[string]any {
|
|
return toolkit.StrProps(desc, required, enum...)
|
|
}
|
|
|
|
func intProps(desc string, required bool) map[string]any { return toolkit.IntProps(desc, required) }
|
|
|
|
func boolProps(desc string, required bool) map[string]any { return toolkit.BoolProps(desc, required) }
|
|
|
|
func textResult(text string) *mcp.CallToolResult { return toolkit.Text(text) }
|
|
|
|
func errorResult(msg string) *mcp.CallToolResult { return toolkit.Error(msg) }
|
|
|
|
// addTool регистрирует инструмент без probe-паттернов (read-only).
|
|
func addTool(s *mcp.Server, tool *mcp.Tool, h mcp.ToolHandler) { s.AddTool(tool, h) }
|
|
|
|
// patternsFn — эмиттер permission-паттернов разрешений для probe-запросов.
|
|
type patternsFn = toolkit.PatternsFn
|
|
|
|
// addPatternTool регистрирует изменяющий инструмент с поддержкой probe: хост
|
|
// получает канонический паттерн ресурса, не выполняя действие.
|
|
func addPatternTool(s *mcp.Server, tool *mcp.Tool, fn patternsFn, h mcp.ToolHandler) {
|
|
toolkit.RegisterPatternTool(s, tool, fn, h)
|
|
}
|
|
|
|
// jsonText сериализует значение в читаемый JSON для ответа модели.
|
|
func jsonText(v any) string {
|
|
b, err := json.MarshalIndent(v, "", " ")
|
|
if err != nil {
|
|
return "{}"
|
|
}
|
|
return string(b)
|
|
}
|