Anthropic tool use

agent402-anthropic-tools · npm · MIT

Turns Agent402 tools into Anthropic Messages API tool definitions (input_schema format) for server-side agents and custom tool loops. For Claude clients that speak MCP, the hosted connector at /mcp is the shorter path; this package is for direct Messages API integrations.

Install

npm install @anthropic-ai/sdk agent402-anthropic-tools

Example

import Anthropic from "@anthropic-ai/sdk";
import { agent402Tools } from "agent402-anthropic-tools";

const client = new Anthropic();
const { tools, execute } = await agent402Tools({ slugs: ["extract", "hash", "render", "screenshot"] });

const res = await client.messages.create({
  model: "claude-sonnet-4-6",
  max_tokens: 1024,
  tools,
  messages: [{ role: "user", content: "Get the title of https://example.com/article" }],
});

const block = res.content.find((b) => b.type === "tool_use");
if (block) {
  const result = await execute(block.name, block.input);
  console.log(result);
}

What it exposes

  • One native tool per catalog slug you pass in slugs (a short list gives the model better tool selection).
  • With no slugs, the free-tier catalog: every compute-payable tool (freeOnly: true is the default).
  • An execute(name, args) function that runs a tool call and pays for it underneath.
  • baseUrl points the adapter at a self-hosted Agent402 instance.

How payment works

  • Free tier: compute-payable tools settle with a sha256 proof-of-work solved in-process. No wallet, no API key.
  • Wallet-only tools (browser, network, memory, live data): set freeOnly: false and pass a payment-wrapped fetch. An @x402/fetch fetch pays in USDC over x402; a stock mppx fetch pays over MPP. The same 402 carries both offers.
  • Prices come from the live catalog at /api/pricing and are quoted in every 402 before anything is signed.
const { tools, execute } = await agent402Tools({
  freeOnly: false,
  fetch: payFetch, // your @x402/fetch-wrapped fetch
});

A call that fails is not charged: settlement runs after the tool and only on a successful response. Background: What x402 is · MPP (Machine Payments Protocol).

Tools to try first

Extract article$0.010
extract
Hash$0.001
hash
Browser render$0.02
render
Screenshot$0.004
screenshot
Domain WHOIS (RDAP)$0.005
whois
Web search$0.02
search

Every tool, price and input schema: the catalog.

Links

agent402-anthropic-tools on npm · source on GitHub · configuration reference
Guides: Use Agent402 from Claude Code, Cursor, VS Code, Windsurf, Cline, Roo Code, Codex CLI, Gemini CLI, Muse Code, Continue, ElizaOS, AgentCore and any OpenAI SDK · Make your AI agent pay for what it needs: x402 in 5 minutes
All integrations