npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

agent-tool-generator

v0.0.7

Published

Generate AI SDK tools from OpenAPI/Swagger specs

Readme

agent-tool-generator

A CLI tool that generates type-safe AI SDK tools from OpenAPI 3.x and Swagger 2.0 specifications. Point it at a spec and get one tool per operation, complete with Zod schemas and auth handling — ready to plug into any AI SDK agent.

Installation

pnpm add agent-tool-generator

Quick Start

pnpm dlx agent-tool-generator \
  -i ./swagger.json \
  -o ./src/tools/my-api \
  -n MyApi

This reads swagger.json, detects whether it's Swagger 2.0 or OpenAPI 3.x, and writes generated tools to src/tools/my-api/.

If the package is installed in your project, you can also run:

pnpm exec agent-tool-generator \
  -i ./swagger.json \
  -o ./src/tools/my-api \
  -n MyApi

CLI Options

| Flag | Short | Description | Default | | --- | --- | --- | --- | | --input <source> | -i | OpenAPI/Swagger spec source: local path or http(s) URL (JSON/YAML) | required | | --output <dir> | -o | Output directory for generated files | required | | --name <name> | -n | API name used for type names (e.g. SentinelOne) | required | | --endpoint <name> | -e | Only generate tools for endpoint paths containing this value (e.g. users) | | | --strip-prefix <prefix> | | Path prefix to strip when deriving tool names | | | --emit-jsdoc | | Emit JSDoc comments in generated tool files with required input/output details | false | | --auth-type <type> | | Auth type: apiKey, bearer, basic | apiKey | | --auth-header <name> | | Auth header name | Authorization | | --auth-prefix <prefix> | | Auth value prefix | Bearer | | --auth-in <location> | | Auth location: header, query | header | | --help | -h | Show help | |

Filter by endpoint path:

pnpm dlx agent-tool-generator \
  -i ./swagger.json \
  -o ./src/tools/my-api \
  -n MyApi \
  -e users

Generated Output

Given a spec, the generator produces:

src/tools/my-api/
├── _types.ts              # Shared options type (baseUrl, auth)
├── accounts/
│   ├── get-accounts.ts    # One file per operation
│   └── post-accounts.ts
├── agents/
│   └── get-agents.ts
└── ...
  • One file per operation — each exports a tool factory function
  • Grouped by tag — operations are organized into subdirectories by their first OpenAPI tag
  • Direct file imports — barrel index.ts files are not generated

Usage in Code

import { getAccounts } from "./tools/my-api/accounts/get-accounts.js";
import { postAccounts } from "./tools/my-api/accounts/post-accounts.js";

const tools = {
  getAccounts: getAccounts({ baseUrl: "https://api.example.com", apiToken: API_TOKEN }),
  postAccounts: postAccounts({ baseUrl: "https://api.example.com", apiToken: API_TOKEN }),
};

Each generated tool is compatible with the AI SDK tool() interface and includes:

  • A Zod input schema derived from the spec's path, query, and body parameters
  • A description pulled from the operation's summary/description
  • An execute function that makes the HTTP request with proper auth
  • Optional JSDoc blocks (--emit-jsdoc) that document required input and output contracts

Supported Specs

  • Swagger 2.0 — auto-detected via "swagger": "2.x" or the presence of definitions
  • OpenAPI 3.x — auto-detected via "openapi": "3.x"

Specs can be JSON or YAML, from a local file or a remote http:// / https:// URL.

Peer Dependencies

  • ai ^5.0.0
  • zod ^4.0.0

Scripts

| Script | Description | | --- | --- | | pnpm generate | Run the local TypeScript CLI (repo development) | | pnpm build | Build the package with tsup | | pnpm test | Run the package's configured test command |

License

ISC