Skip to content

HTTP / REST tools

Some capabilities are just an HTTP endpoint away. httpTool turns a REST call into a uniform Tool (source: "http") — you declare the method, URL, headers and input schema, and toolnexus handles the request, argument substitution, and response for you. No client code, no glue.

import { httpTool } from "toolnexus"
const getPost = httpTool({
name: "get_post",
description: "Fetch a blog post by id",
method: "GET",
url: "https://api.example.com/posts/{id}", // {id} filled from args
headers: { Authorization: "Bearer ${API_TOKEN}" }, // ${ENV} expands at call time, never logged
inputSchema: {
type: "object",
properties: { id: { type: "number" } },
required: ["id"],
},
})
tk.register(getPost)
  • URL placeholders{id} in the URL is filled from the matching arg and consumed (it won’t be re-sent in the body). Great for path params.
  • Querystring — name specific args as query (Go Query, Python query=[...]) and they’re sent as ?a=…&b=… instead of in the body.
  • Body encoding — for non-GET requests, body selects "json" (default), "form", or "raw".
  • Result mode"text" (default), "json", or "status+text" shapes what the tool returns to the model.

Rather than declare endpoints one by one, you can import an OpenAPI spec and get a tool per operation (best-effort). It’s the bulk path to the same source: "http" tools; see the per-language README for the import entry point and current coverage.

Compare with native function tools