Generate Tools from TypeScript Source Code
You have existing TypeScript functions and you want to turn them into agent capabilities without rewriting anything. Forge scans your source files, reads the exported function signatures and JSDoc comments, and generates tool specs and runnable capability code automatically. This walkthrough uses a billing module as the running example.Prerequisites
- TypeScript source files with exported functions
- JSDoc comments on the functions you want to expose (recommended but not strictly required)
- The Svantic CLI installed (
npm install -g @svantic/cli)
Step 1: Write Your Functions
Forge works best with exported functions that have JSDoc annotations. Here is a typical billing module:Step 2: Scan the File
Step 3: Generate Tools
Generate all functions:Step 4: Review the Generated Code
The generated capabilities delegate to your original functions:How JSDoc Becomes LLM Descriptions
Forge maps your JSDoc annotations directly to tool and parameter descriptions:
If a function has no JSDoc, Forge generates a description from the function name (
charge becomes "Invoke the charge function"). This works but produces weaker LLM tool selection — add real descriptions whenever possible.
Type Mapping
Forge infers JSON Schema types from your TypeScript signatures:
Complex or deeply nested generics may not resolve cleanly. In those cases, Forge emits a warning and falls back to
{ type: 'string' }. Simplify the signature or add a @param override.
Programmatic Usage
Scanning Multiple Files
Pass multiple--scan flags or use a glob:
.tool-spec.yaml and .capabilities.ts pair. Combine them later with svantic forge agent (see Composing Agents).
Handling Classes
Forge scans exported class methods as well as standalone functions. Each public method becomes a separate tool, prefixed with the class name:billing_charge, billing_refund.
Private and protected methods are skipped. Static methods are included.
Updating After Code Changes
Re-run the scan command after modifying your source files. Forge regenerates the Tool Spec and capabilities, overwriting previous output. Any manual edits in*.custom.ts files in the output directory are preserved.