Documentation
¶
Overview ¶
Package toolhelp answers, from a tool's advertised input schema, what the tool takes: the refusal of a call whose arguments do not match it (#2811), help on every tool that chooses its operation by a command or an action (#2815), and one example call fitting what a caller said it wants to do (#2809). Everything here reads the schema the server shows a client, so no answer can drift from what the tool accepts.
It is its own package rather than more of pkg/middleware, which is at its file and exported-surface budgets.
Index ¶
- func Example(schema map[string]any, intent string) map[string]any
- func HelpField(schema map[string]any) (field string, ok bool)
- func HelpMiddleware(lookup SchemaLookup) mcp.Middleware
- func RefusalMiddleware(lookup SchemaLookup) mcp.Middleware
- func RepeatMiddleware(session func(ctx context.Context) string, db *sql.DB) mcp.Middleware
- type SchemaLookup
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Example ¶
Example is one call of a tool that fits what a caller said it wants to do, read from the tool's input schema (#2809): for a tool that chooses its operation by a command or action enum, the value whose words best match the intent, every parameter that value requires (a placeholder naming its type), and any enum parameter whose value the intent names ("assets shared with me" gives manage_asset's action list with scope shared). A tool with no such enum gets its required parameters. Nil when the schema declares nothing.
func HelpField ¶ added in v1.169.1
HelpField is the argument help is answered on for a tool with this input schema: its command or action field, when that is an enum. ok is false for a tool help does not apply to.
func HelpMiddleware ¶
func HelpMiddleware(lookup SchemaLookup) mcp.Middleware
HelpMiddleware answers `help` on every tool that takes a command or an action (#2815), from the tool's advertised input schema, so the answer is what the tool accepts and cannot drift from it. A tool whose command enum lists help itself (manage_script) answers its own and is passed through, as is a call to any tool whose schema the lookup cannot read or that chooses no command by an enum.
The answer lists each command with the parameters whose description names it (the schemas write "publish: ..." or "grant, revoke: ..."), the parameters every command shares, and an example call per command.
Placement: inner to authorization and the gates, so a persona that may not call the tool is refused as for any other command, and inner to the error contract.
func RefusalMiddleware ¶
func RefusalMiddleware(lookup SchemaLookup) mcp.Middleware
RefusalMiddleware rewrites an argument refusal so it names what the call got wrong and what the tool accepts (#2811): each property the schema does not declare with the accepted name it most likely meant, each value of the wrong type or outside an enum, and every accepted parameter with its type. The code and category are unchanged. Any other result, or a refusal whose tool schema cannot be read, is returned as it was.
Placement: outer to the error contract, whose normalized refusal it reads, and inner to audit, which records the same code and category either way.
func RepeatMiddleware ¶
RepeatMiddleware is the layer that tells an agent how to report what the platform could not do for it (#2820), and, since #2885, when: the first time a capability does not exist, on any refusal after the session's first, and when a session's calls show a pattern worth an improvement post or a knowledge capture. internal/feedbackprompt holds the rules; this layer keeps its place in the chain, outer to the error contract whose normalized refusal it reads. Each session's record is kept in db when there is one, shared by every replica, and in memory otherwise (feedbackprompt.Shared).