Skip to content

Function: autoDiscover()

ts
function autoDiscover(
   registry, 
   dir, 
options?): Promise<string[]>;

Defined in: packages/core/src/server/autoDiscover.ts:182

Scan a directory and auto-register all discovered tool builders.

Eliminates the need for a central index.ts that manually imports and registers every tool. New tools are automatically picked up when they are dropped into the scanned directory.

Parameters

ParameterTypeDescription
registryToolRegistryLikeA ToolRegistry instance to register discovered tools
dirstringPath to the tools directory (absolute or relative to CWD)
optionsAutoDiscoverOptionsDiscovery options (pattern, recursive, loader, resolve)

Returns

Promise<string[]>

Array of discovered file paths (for logging/debugging)

Throws

If the directory does not exist or is not readable

Example

typescript
const registry = new ToolRegistry<AppContext>();
const files = await autoDiscover(registry, './src/tools');
console.log(`Discovered ${files.length} tool files`);