Skip to content

Native tools — your own functions

A native tool wraps a plain function: return a string (→ output) or throw (→ error result). It joins the toolkit like any other tool.

import { defineTool } from "toolnexus"
tk.register(defineTool({
name: "add", description: "Add two numbers and return the sum.",
inputSchema: {
type: "object",
properties: { a: { type: "number" }, b: { type: "number" } },
required: ["a", "b"],
},
run: ({ a, b }) => `${Number(a) + Number(b)}`,
}))

Java and C# also support annotation-driven tools (@ToolMethod / [ToolMethod] on a class). See Native tools.

Next: HTTP / REST tools.