tools
consttools:object
Type Declaration
Section titled “Type Declaration”function
Section titled “function”function: (
defs) =>Middleware=toolsFunction
Create function tools with Zod schemas.
Creates a middleware that registers function tools on an agent.
Accepts a single ToolDef or an array of ToolDefs.
Tools are registered via ctx.registerTool() in the agent hook
and are available to the LLM for the agent’s lifetime.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Example
Section titled “Example”agent.use(tools.function({ name: "add", description: "Add two numbers", schema: z.object({ a: z.number(), b: z.number() }), execute: async ({ a, b }) => a + b,}))mcp: (
config) =>Middleware=mcpTools
Connect to an MCP server and register its tools.
Creates a tools.mcp() middleware that connects to an MCP server,
discovers its tools, and registers them on the agent.
One server per .use() call. For multiple servers, call .use() multiple times.
Requires @modelcontextprotocol/sdk as a peer dependency (optional install).
Parameters
Section titled “Parameters”config
Section titled “config”MCP server connection configuration
Returns
Section titled “Returns”Middleware that connects to the MCP server and registers its tools
Example
Section titled “Example”// Local process via stdioagent.use(tools.mcp({ name: "crm", transport: "stdio", command: "npx", args: ["-y", "@acme/crm-mcp"],}))
// Remote server via HTTPagent.use(tools.mcp({ name: "docs", transport: "http", url: "https://mcp.example.com", headers: { "Authorization": "Bearer token" },}))