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

@zuora/agent-toolkit

v0.1.0-beta.1

Published

Zuora billing operations as callable tools for AI agent frameworks.

Readme

@zuora/agent-toolkit

Beta release — not intended for production use yet. Customers are welcome to try the kit in sandbox or other non-production environments for evaluation and feedback. APIs may change before the 1.0 stable release.

Introduction

Zuora Agent Kit is an SDK that turns Zuora billing operations into tools an AI agent can call. This package, @zuora/agent-toolkit, provides the TypeScript SDK; the Python package, zuora-agent-toolkit, is planned.

Instead of wiring each Zuora REST API by hand for an LLM, the kit:

  1. Connects to your tenant's Zuora MCP server using OAuth.
  2. Discovers available operations at runtime — the tool inventory is not hardcoded.
  3. Normalizes them into a shared tool shape, ZuoraToolDefinition.
  4. Exposes them in the format your agent framework expects: OpenAI Chat Completions, OpenAI Agents SDK, LangChain, or Vercel AI SDK.

Your agent can then do things like "list accounts" or "run a query" through tool calls, while the kit handles authentication, filtering (read-only vs. writes and tool bundles), approval rules, and observability.

To discover the bundles and tools available for your tenant, see Discovery and execution below.

Quick start

import { Agent, run } from "@openai/agents";
import { createZuoraOpenAIAgentsToolkit } from "@zuora/agent-toolkit/openai-agents";

const toolkit = await createZuoraOpenAIAgentsToolkit({ env: true });
try {
  const agent = new Agent({ name: "Billing Agent", tools: await toolkit.getTools() });
  const result = await run(agent, "How many active accounts do we have?");
  console.log(result.finalOutput);
} finally {
  await toolkit.close();
}

Set ZUORA_BASE_URL, ZUORA_CLIENT_ID, and ZUORA_CLIENT_SECRET in your environment. See Credentials for other auth options.

Adapter status

| Subpath | Factory | Status | |---|---|---| | @zuora/agent-toolkit/openai | createZuoraOpenAIAgentToolkit | ✅ Implemented | | @zuora/agent-toolkit/openai-agents | createZuoraOpenAIAgentsToolkit | ✅ Implemented | | @zuora/agent-toolkit/langchain | createZuoraLangChainToolkit | ✅ Implemented | | @zuora/agent-toolkit/vercel-ai | createZuoraVercelAIToolkit | ✅ Implemented | | @zuora/agent-toolkit/mcp | — | 🚧 Coming soon |

Changelog

[0.1.0-beta.1]

  • First beta release — customers are welcome to evaluate it in sandbox or other non-production environments; it is not intended for production use yet.
  • Added an introduction explaining runtime tool discovery, the shared tool definition, framework adapters, and built-in safety and observability controls.

[0.1.0-alpha.1]

  • Fixed HITL approval policy handling with correct request.environment usage
  • Improved tool name resolution
  • Removed deprecated CLI_AGENT_SPLIT_OPERATIONS references
  • Test and documentation updates

[0.1.0-alpha.0]

Initial alpha release.

Installation

Requires Node.js 18 or later.

npm install @zuora/agent-toolkit@beta

Framework packages are peer dependencies — install only what you use:

# OpenAI Chat Completions (requires openai >=4)
npm install openai

# OpenAI Agents SDK (requires @openai/agents >=0.13)
npm install @openai/agents

# LangChain (requires @langchain/core >=1.2.1)
npm install @langchain/core @langchain/langgraph @langchain/openai

# Vercel AI SDK (requires ai >=7 — v7 is a breaking rewrite from v6)
npm install ai @ai-sdk/openai

Version notes

  • Vercel AI SDK — ai >=7 is required. v7 introduced ToolSet, isStepCount, and jsonSchema(), which this adapter depends on. v6 is not compatible.
  • LangChain — @langchain/core >=1.2.1 is required for DynamicStructuredTool and JSON Schema parameter support.
  • @langchain/langgraph and @langchain/openai are not direct peer dependencies but are needed to run the agent (see examples).

Credentials

Pass env: true to read credentials from the environment automatically:

| Variable | Purpose | |---|---| | ZUORA_BASE_URL | Tenant REST API endpoint (required) | | ZUORA_CLIENT_ID / ZUORA_CLIENT_SECRET | OAuth credentials (required) | | ZUORA_TOOLKIT_MODE | readOnly (default) or writeEnabled |

ZUORA_TOOLKIT_MODE is only read when env: true is set, and is overridden by an explicit configuration.mode.

You can also pass credentials explicitly:

import { SafetyMode } from "@zuora/agent-toolkit";

const toolkit = await createZuoraOpenAIAgentToolkit({
  baseUrl: process.env.ZUORA_BASE_URL!,
  auth: {
    clientId: process.env.ZUORA_CLIENT_ID!,
    clientSecret: process.env.ZUORA_CLIENT_SECRET!,
  },
  configuration: { mode: SafetyMode.ReadOnly },
});

env: true reads only credentials and base URL from the environment — all other config fields (configuration, approvalPolicy, observability, etc.) can still be set explicitly alongside it.

Use a client scoped to the minimum permissions your agent needs. Never use admin credentials.

Usage

Which OpenAI adapter should I use?

  • Use @zuora/agent-toolkit/openai-agents + createZuoraOpenAIAgentsToolkit if you are building with the @openai/agents library (the higher-level agent runtime).
  • Use @zuora/agent-toolkit/openai + createZuoraOpenAIAgentToolkit if you are using the raw openai Chat Completions API and managing the tool-call loop yourself.

OpenAI Agents SDK

import { Agent, run } from "@openai/agents";
import { SafetyMode } from "@zuora/agent-toolkit";
import { createZuoraOpenAIAgentsToolkit } from "@zuora/agent-toolkit/openai-agents";

const toolkit = await createZuoraOpenAIAgentsToolkit({
  env: true,
  configuration: { mode: SafetyMode.ReadOnly },
});

// Scope to specific bundles and cap tool count — improves model accuracy
const tools = (await toolkit.getTools({ bundles: ["accounts", "query"] })).slice(0, 50);
const agent = new Agent({ name: "Billing Agent", tools });
const result = await run(agent, "How many active billing accounts do we have?");

await toolkit.close();

If you already have a ZuoraOpenAIAgentToolkit instance (for example, shared across multiple agents or reused from an existing integration), you can convert its tools to Agents SDK format without opening a second MCP connection:

import { buildAgentsTools } from "@zuora/agent-toolkit/openai-agents";
import { tool } from "@openai/agents";

// `tool` is passed in rather than imported directly so @openai/agents stays
// an optional peer dependency and the module loads without it installed.
const tools = await buildAgentsTools(tool, chatToolkit, { bundles: ["query"] });
const agent = new Agent({ name: "Billing Agent", tools });
await run(agent, "...");
// chatToolkit must stay open while tools are in use — close it when done

If you are starting fresh (no existing toolkit), prefer createZuoraOpenAIAgentsToolkit directly — it handles the connection internally.

LangChain

import { ChatOpenAI } from "@langchain/openai";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { SafetyMode } from "@zuora/agent-toolkit";
import { createZuoraLangChainToolkit } from "@zuora/agent-toolkit/langchain";

const toolkit = await createZuoraLangChainToolkit({
  env: true,
  configuration: { mode: SafetyMode.ReadOnly },
});

// Scope to specific bundles and cap tool count — improves model accuracy
const tools = (await toolkit.getTools({ bundles: ["accounts", "query"] })).slice(0, 50);

const agent = createReactAgent({
  llm: new ChatOpenAI({ model: "gpt-4o" }),
  tools,
});

// LangChain owns the tool-call loop — no manual dispatch needed
const result = await agent.invoke({
  messages: [{ role: "user", content: "List 3 active accounts" }],
});

const answer = result.messages.at(-1)?.content;
console.log(typeof answer === "string" ? answer : JSON.stringify(answer));

await toolkit.close();

Vercel AI SDK

getToolSet() returns a ToolSet (Record<string, Tool>) — the format streamText and generateText require. All other adapters use getTools() which returns an array.

import { openai } from "@ai-sdk/openai";
import { streamText, isStepCount } from "ai";
import { SafetyMode } from "@zuora/agent-toolkit";
import { createZuoraVercelAIToolkit } from "@zuora/agent-toolkit/vercel-ai";

const toolkit = await createZuoraVercelAIToolkit({
  env: true,
  configuration: { mode: SafetyMode.ReadOnly },
});

// `getToolSet()` returns a ToolSet (`Record<string, Tool>`) rather than an array,
// so `.slice()` is not available — the second argument is the only way to cap tool count.
// Omit it to return all matching tools.
const tools = await toolkit.getToolSet(
  { bundles: ["accounts", "query"] },
  50,
);

const { textStream } = streamText({
  model: openai("gpt-4o"),
  tools,
  stopWhen: isStepCount(20), // SDK drives the tool-call loop — no manual dispatch needed
  messages: [{ role: "user", content: "List 3 active accounts" }],
});

for await (const chunk of textStream) {
  process.stdout.write(chunk);
}
console.log();

await toolkit.close();

OpenAI Chat Completions

import OpenAI from "openai";
import {
  createZuoraOpenAIAgentToolkit,
  handleToolCalls,
} from "@zuora/agent-toolkit/openai";
import { SafetyMode } from "@zuora/agent-toolkit";

const toolkit = await createZuoraOpenAIAgentToolkit({
  env: true,
  configuration: { mode: SafetyMode.ReadOnly },
});

const client = new OpenAI();
const tools = await toolkit.getTools({ bundles: ["accounts", "query"] });
const messages: OpenAI.ChatCompletionMessageParam[] = [
  { role: "user", content: "List 3 active accounts" },
];

for (let step = 0; step < 20; step++) {
  const response = await client.chat.completions.create({
    model: "gpt-4o",
    messages,
    tools,
  });

  const choice = response.choices[0];
  if (!choice) break;
  messages.push(choice.message);

  if (choice.finish_reason === "tool_calls") {
    // handleToolCalls returns { messages, abortTurn, requireToolOnNextStep, followUpToolNames }.
    // For basic loops, only `messages` is needed. See examples/openai/hitl.ts for advanced usage.
    const { messages: toolMessages } = await handleToolCalls({ toolkit, response });
    messages.push(...toolMessages);
    continue;
  }

  console.log(choice.message.content);
  break;
}

await toolkit.close();

Configuration

Top-level config shape — all fields except credentials are optional:

{
  env: true,                      // reads ZUORA_BASE_URL, ZUORA_CLIENT_ID, ZUORA_CLIENT_SECRET
  configuration: {                // tool filtering, safety, and routing
    mode: SafetyMode.ReadOnly,
    bundles: { accounts: true },
    context: {                    // scopes operations to the specified entity / org
      entityIds: "entity-1",     // → Zuora-Entity-Ids header
      orgIds: "org-1",           // → Zuora-Org-Ids header
    },
  },
  // approvalPolicy: …           // see "Approval policy" section below
  observability: {                // optional: events and logging
    onEvent: (event) => { … },
  },
}

Safety modes

configuration: {
  mode: SafetyMode.ReadOnly,      // only read operations (default)
  // or
  mode: SafetyMode.WriteEnabled,  // read + write operations
}

Tool bundles

Select groups of tools by Zuora domain:

configuration: {
  bundles: {
    accounts: true,
    subscriptions: true,
    query: true,
  },
}

Available bundles: accounts, catalog, subscriptions, orders, billing, payments, usage, revenue, finance, workflows, query, admin, files. Which bundles are available depends on your Zuora tenant's MCP endpoint.

You can also filter at call time via getTools(). Note that configuration.bundles uses an object ({ accounts: true }) and is fixed at toolkit creation time; getTools({ bundles: [...] }) uses an array and filters the already-loaded catalog at call time.

// Filter by bundle
toolkit.getTools({ bundles: ["accounts", "query"] })

// Include or exclude specific tools by exact name
toolkit.getTools({ include: ["get_account", "list_accounts"] })
toolkit.getTools({ exclude: ["delete_account"] })

// Narrow to write-enabled tools for this call only (per-call mode overrides global config)
toolkit.getTools({ mode: SafetyMode.WriteEnabled })

Exclude / include specific tools

configuration.bundles.billing.exclude is evaluated once at toolkit creation and applies permanently to that bundle. getTools({ exclude }) filters the already-loaded catalog on each call and works across all bundles.

include and exclude can be combined: include acts as an allowlist first, then exclude removes from that set. A tool passes if it matches include (when set) and is not in exclude.

configuration: {
  bundles: {
    billing: {
      exclude: ["create_invoice", "delete_invoice"],
      // or use include to allowlist specific tools: include: ["list_invoices"]
      // or combine both: include: ["run_reports", "list_invoices"], exclude: ["delete_billing_run"]
    },
  },
}

Enabling or disabling individual tools

To enable or disable specific tools without affecting their entire bundle:

configuration: {
  tools: {
    "delete_invoice": false,   // disable one tool
    "run_reports": true,       // explicitly enable (useful when a bundle is partially restricted)
  },
}

Approval policy

Approval policies are checked before a tool executes. An "allow" decision lets execution proceed; "deny" blocks it with an APPROVAL_REJECTED error. If no policy is configured, no additional approval check is performed.

Approval policies are an additional guardrail, not a way to enable writes: write operations must also be enabled through configuration.mode: SafetyMode.WriteEnabled. The read-only execution guard runs before the approval policy.

approvalPolicy is a top-level config field (not inside configuration):

import { ApprovalPolicyPreset, SafetyMode } from "@zuora/agent-toolkit";

const toolkit = await createZuoraOpenAIAgentToolkit({
  env: true,
  configuration: { mode: SafetyMode.WriteEnabled },
  approvalPolicy: ApprovalPolicyPreset.HighRisk,
  // or a custom handler:
  // approvalPolicy: async (request) => {
  //   if (request.tool.meta.riskLevel === "high") return "deny";
  //   return "allow";
  // },
});

Built-in presets automatically allow or deny operations; they do not display an approval prompt. Operations that do not match a preset's denial condition are allowed by that policy.

| Preset | Behavior | |---|---| | Off | No additional approval restriction | | AllWrites | Denies all write operations | | HighRisk | Denies all high-risk operations, including reads | | ProductionWrites | Denies writes when the detected environment is production | | ProductionHighRisk | Denies high-risk operations when the detected environment is production |

Custom handlers can be synchronous or async and receive:

| Field | Contents | |---|---| | request.tool | Tool definition, including access and risk metadata for the invoked operation | | request.input | Arguments supplied to the tool | | request.environment | "production" or "sandbox", inferred from baseUrl |

Environment detection: unrecognized URLs currently default to "sandbox". Production-only presets therefore do not block operations on unrecognized URLs; use a custom policy if your endpoint is not recognized as production.

Custom handler return values: "allow" (proceed) · "deny" (block) · { decision: "allow" | "deny", reason?: string }. Only decision is used; reason is not currently included in the rejection error.

A custom async approvalPolicy can integrate your own approval workflow. For an example combining interactive approval through the OpenAI shouldExecute hook with an automated toolkit policy, see examples/openai/hitl.ts. In that example, the hook prompts before writes and returns a declined result to the model if the user refuses. The toolkit policy separately denies high-risk operations in production, even if the user approved them.

Context

Pass routing and observability identifiers via configuration.context. All values are strings — use comma-separation for multiple IDs:

| Key | Effect | |---|---| | entityIds | Forwarded as Zuora-Entity-Ids to scope operations to the specified entity | | orgIds | Forwarded as Zuora-Org-Ids to scope operations to the specified org |

const toolkit = await createZuoraOpenAIAgentToolkit({
  env: true,
  configuration: {
    mode: SafetyMode.WriteEnabled,
    context: {
      entityIds: "entity-1,entity-2",  // comma-separated for multiple
      orgIds: "org-1",
    },
  },
});

Observability

observability: {
  onEvent: (event) => { /* synchronous observer */ },
  emit: async (event) => { /* async sink — await is respected */ },
  logger: { info: console.info, warn: console.warn, error: console.error },
  includePayloads: false, // default; set true to include tool input keys and
                          // truncated values in events — secrets are redacted
}

Emitted event names:

| Event | When | |---|---| | tool.called | Tool invocation starts | | tool.completed | Tool returns successfully | | tool.failed | Tool throws or returns an error | | approval.requested | Approval policy triggers before execution | | approval.decided | Approval decision recorded (approved / denied) | | metadata.loaded | Tool catalog fetched from MCP on initialize() | | async.poll.checked | A polling iteration completed for an async job |

Lifecycle

Always call close() when done — it closes the underlying MCP connection and allows the process to exit cleanly:

const toolkit = await createZuoraOpenAIAgentToolkit({ env: true });
try {
  // use toolkit
} finally {
  await toolkit.close();
}

Discovery and execution

listTools() returns ZuoraToolDefinition[] — framework-agnostic metadata for inspection and logging.
getTools() returns framework-native tool objects (e.g. ChatCompletionTool[]) ready to pass directly to the LLM.

const tools = await toolkit.listTools();           // ZuoraToolDefinition[]
const def = await toolkit.describeTool("get_account");  // ZuoraToolDefinition
const bundles = await toolkit.listBundles();           // ZuoraBundleName[]
const bundle = await toolkit.describeBundle("subscriptions");  // { name, description, toolCount, tools: ZuoraToolDefinition[] }

const result = await toolkit.callTool("get_account", { accountKey: "…" });

For tools that start async jobs (e.g. Data Query), the tool result automatically includes a follow-up instruction telling the model which tool to call next — the model drives polling on subsequent steps without any extra code.

Errors

All SDK errors are ZuoraAgentToolkitError with a typed code:

| Code | Meaning | |---|---| | OAUTH_TOKEN_ERROR | Authentication or token refresh failed | | TOOL_EXECUTION_ERROR | MCP tool call failed | | TOOL_NOT_FOUND | Unknown tool name | | BUNDLE_NOT_FOUND | Unknown bundle name | | APPROVAL_REJECTED | Approval policy rejected the operation | | MALFORMED_METADATA | Server returned incomplete or invalid tool metadata | | ASYNC_JOB_TIMEOUT | Async job polling timed out |

import { ZuoraAgentToolkitError } from "@zuora/agent-toolkit";

try {
  await toolkit.callTool("create_invoice", { accountId: "A-1" });
} catch (err) {
  if (err instanceof ZuoraAgentToolkitError && err.code === "APPROVAL_REJECTED") {
    // handle rejection
  }
}

When using framework adapters, ZuoraAgentToolkitError surfaces from handleToolCalls() (OpenAI Chat Completions), run() (OpenAI Agents SDK), agent.invoke() (LangChain), or during stream consumption with generateText() / streamText() (Vercel AI SDK).

Key exported types

import type {
  ZuoraToolDefinition,  // full tool descriptor: name, description, inputSchema, meta
  ZuoraBundleName,      // union of all valid bundle name strings
  ToolSelection,        // filter shape passed to getTools() / listTools() — { bundles?, include?, exclude?, mode? }
  ZuoraToolkitEvent,    // observability event payload
  ApprovalPolicy,       // type for the approvalPolicy config field
} from "@zuora/agent-toolkit";
import { ZuoraAgentToolkitError, ApprovalPolicyPreset, SafetyMode } from "@zuora/agent-toolkit";

Examples

Working examples are available in the source repository:

| Example | Description | |---|---| | examples/openai/index.ts | Minimal Chat Completions agent loop | | examples/openai/advanced.ts | Observability, hooks, async jobs, discovery | | examples/openai/hitl.ts | Human-in-the-loop (HITL) approval | | examples/openai-agents/index.ts | OpenAI Agents SDK agent | | examples/openai-agents-cli/ | Interactive CLI agent + planner + dual-layer approval (HITL + toolkit) | | examples/langchain-agents-cli/ | Interactive LangChain CLI agent + planner + dual-layer approval (HITL + toolkit) | | examples/langchain/index.ts | LangChain ReactAgent with Zuora tools | | examples/vercel-ai/index.ts | Vercel AI SDK streamText agent |