Skip to main content

Generate Tools from an OpenAPI Spec

You have an API spec and you want agent tools. Forge reads OpenAPI v3 (or Swagger 2.0) definitions, extracts the operations you pick, and generates type-safe TypeScript capabilities with auth handling baked in. This walkthrough uses a Zendesk Support API spec as the running example.

Prerequisites

  • A valid OpenAPI v3 or Swagger 2.0 spec file (JSON or YAML)
  • The Svantic CLI installed (npm install -g @svantic/cli)

Step 1: List Available Operations

Before generating anything, inspect what the spec offers:
Output:
Each line shows the generated tool name, HTTP method, and path. Tool names are derived from operationId when available, otherwise from the method and path.

Step 2: Generate Specific Tools

Pick the operations you need with --pick:
This generates two files in ./tools/: It also writes a zendesk.tool-spec.yaml — the intermediate Tool Spec that you can inspect, edit, and regenerate from.

Step 3: Review the Generated Code

The capabilities file exports one function per tool:

Step 4: Use the Tools in Your Agent

Register the generated capabilities with an agent:

Programmatic Usage

Use the SDK directly instead of the CLI:

Listing operations programmatically

Auth Detection

Forge reads the securitySchemes section of your OpenAPI spec and maps it to auth configuration automatically: The env values are suggestions. Override them in the Tool Spec YAML or in the generated code.

Overriding auth at generation time

Swagger 2.0 Support

Forge accepts Swagger 2.0 specs. They are automatically converted to OpenAPI 3.0 internally before generation. The conversion handles:
  • definitions to components/schemas
  • basePath + host to servers[0].url
  • securityDefinitions to securitySchemes
If the automatic conversion produces unexpected results, convert your spec manually with a tool like swagger2openapi and pass the v3 file to Forge.

Filtering Operations

Beyond --pick, you can filter by tag or path prefix:

Regenerating After Spec Changes

If the upstream API spec changes, regenerate from the updated file. Forge overwrites the capabilities and Tool Spec YAML but preserves any file named *.custom.ts in the output directory, so you can keep manual overrides safe.