mcp: advertise per-tool arg names in the jerboa dispatcher schema
ober
a7fcc608fd61053a223a1b9ef098781e344c76c7
--- a/mcp/server.ss +++ b/mcp/server.ss @@ -368,8 +368,28 @@ (unique (append '("list" "describe") (map tool-short-name (routable-tools))))) +(def (tool-arg-signature t) + ;; Compact one-line arg spec for a tool, e.g. "check_balance(file_path?, code?)". + ;; ! marks a required arg, ? optional. Lets the dispatcher advertise every + ;; routable tool's args up front so callers needn't round-trip via describe. + (let* ([s (hash-ref t "schema")] + [props (hash-ref s "properties")] + [req (hash-get* s "required" '())]) + (string-append + (tool-short-name t) + "(" + (string-join + (map (lambda (kv) + (string-append (car kv) (if (member (car kv) req) "!" "?"))) + (hash->list props)) + ", ") + ")"))) + +(def (routable-args-manifest) + (string-join (map tool-arg-signature (routable-tools)) "; ")) + (def (manifest-line t) - (string-append "- " (tool-short-name t) ": " (hash-ref t "description"))) + (string-append "- " (tool-arg-signature t) ": " (hash-ref t "description"))) (def (dispatcher-manifest) (string-join (map manifest-line (routable-tools)) "\n")) @@ -4193,7 +4213,11 @@ (schema (list (list "tool" (jhash "type" "string" "description" "Tool to invoke, or \"list\"/\"describe\"" "enum" (routable-tool-names))) - (list "args" (property "object" "Tool arguments"))) + (list "args" (property "object" + (string-append + "Arguments for the chosen tool, as an object. " + "Accepted args per tool (\"!\"=required, \"?\"=optional): " + (routable-args-manifest))))) '("tool")) dispatcher #f '()))