Describe tools for clients and bind validated inputs to callbacks. More...
Typedefs | |
| typedef int(* | mcp_tool_fn) (int argc, const char **returnMessage, const char **args) |
| Callback invoked for a validated tools/call request. | |
Functions | |
| int | set_tool_callback (struct tool *tool, mcp_tool_fn callback) |
| Bind the callback invoked when a client calls a registered tool. | |
| struct tool * | find_tool (const char *name) |
| Look up a registered tool by exact, case-sensitive name. | |
| void | add_argument (struct tool *tool, const char *name, enum type type, const char *description) |
| Append one required argument to a tool's discovery schema. | |
| struct tool * | add_tool (const char *name, const char *description) |
| Register a tool name and its client-visible description during startup. | |
Describe tools for clients and bind validated inputs to callbacks.
| typedef int(* mcp_tool_fn) (int argc, const char **returnMessage, const char **args) |
Callback invoked for a validated tools/call request.
| [in] | argc | Number of registered arguments, validated before invocation. |
| [out] | returnMessage | Set *returnMessage to null-terminated response text. |
| [in] | args | Array of argc strings in add_argument() registration order. NULL when argc is zero; no extra sentinel element. |
All arguments are required. The core rejects missing, extra, duplicate and incorrectly typed inputs before invocation, so argc is redundant for a fixed-signature callback and a defensive count check is optional. Strings are decoded JSON text, booleans are "true"/"false", and finite numbers are JSON-compatible numeric text (possibly exponent notation). The callback must validate ranges/enumerations before applying changes.
|
extern |
Append one required argument to a tool's discovery schema.
| [in] | tool | Valid handle returned by add_tool() or find_tool(). |
| [in] | name | Nonempty input key, unique among the tool's argument names. |
| [in] | type | JSON input type: TYPE_STR, TYPE_INT, TYPE_FLOAT or TYPE_BOOL. |
| [in] | description | Meaning, units, limits or choices; NULL omits the property's description. |
tools/list places the argument in inputSchema.properties and its name in inputSchema.required. TYPE_INT advertises integer; TYPE_FLOAT advertises number. Descriptions do not generate enum/minimum/maximum constraints: enforce these in the callback. Callback order is the order of add_argument() calls.
|
extern |
Register a tool name and its client-visible description during startup.
| [in] | name | Unique, nonempty, case-sensitive name used in tools/call. |
| [in] | description | Human-readable behavior and effects; NULL omits this field from tools/list. |
The description becomes the tool's description field in tools/list. Explain what the tool changes/reads, side effects and when changes take effect. Argument meanings, units and accepted values belong in add_argument() descriptions. These strings are metadata: they are not parsed as commands or schemas, and they do not implement validation.
Register arguments and a callback before mcp_prepare(). All registration strings are borrowed and must remain valid and unchanged until free_tools(). No callback or argument is created implicitly.
|
extern |
Look up a registered tool by exact, case-sensitive name.
| [in] | name | Tool name; NULL is permitted and has no match. |
Does not allocate memory.
|
extern |
Bind the callback invoked when a client calls a registered tool.
| [in] | tool | Valid registered tool handle. |
| [in] | callback | Non-NULL callback. |
May replace a callback during startup. A tool without a callback can appear in discovery, but calling it produces MCP_INTERNAL_ERROR.