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:| File | Contents |
|---|---|
billing.tool-spec.yaml | The intermediate Tool Spec YAML |
billing.capabilities.ts | Capability wrappers that call your original 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:| JSDoc Element | Maps To |
|---|---|
| Function-level comment | description field on the tool |
@param name - text | description on the matching parameter property |
@returns text | Appended to the tool description as “Returns: …” |
@default value | default field on the parameter |
@example | Ignored (not included in tool spec) |
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:| TypeScript Type | JSON Schema Type |
|---|---|
string | { type: 'string' } |
number | { type: 'number' } |
boolean | { type: 'boolean' } |
string[], Array<string> | { type: 'array', items: { type: 'string' } } |
{ key: string } (inline object) | { type: 'object', properties: { key: { type: 'string' } } } |
| Named interface/type alias | Resolved and inlined as { type: 'object', properties: {...} } |
T | undefined, T? | Property is omitted from required |
Literal union 'a' | 'b' | { type: 'string', enum: ['a', 'b'] } |
Record<string, T> | { type: 'object', additionalProperties: { type: ... } } |
unknown, any | { type: 'string', description: 'JSON-encoded value' } |
{ 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.