Skip to content

Class: FluentRouter<TContext>

Defined in: packages/core/src/core/builder/FluentRouter.ts:44

Fluent router that shares prefix, description, and middleware across child tools created via .query(), .mutation(), .action().

Type Parameters

Type ParameterDescription
TContextBase application context

Constructors

Constructor

ts
new FluentRouter<TContext>(prefix): FluentRouter<TContext>;

Defined in: packages/core/src/core/builder/FluentRouter.ts:51

Parameters

ParameterType
prefixstring

Returns

FluentRouter<TContext>

Methods

action()

ts
action(action): FluentToolBuilder<TContext>;

Defined in: packages/core/src/core/builder/FluentRouter.ts:141

Create a neutral action tool under this router's prefix.

Parameters

ParameterTypeDescription
actionstringAction name (e.g. 'update' → tool name 'prefix.update')

Returns

FluentToolBuilder<TContext>

A FluentToolBuilder with the prefixed name and inherited config


describe()

ts
describe(text): this;

Defined in: packages/core/src/core/builder/FluentRouter.ts:61

Set the shared description for all tools in this router.

Parameters

ParameterTypeDescription
textstringHuman-readable description

Returns

this

this for chaining


interactive()

ts
interactive(): this;

Defined in: packages/core/src/core/builder/FluentRouter.ts:110

Enable human-in-the-loop interaction for all tools in this router.

All child tools will inherit the .interactive() flag, meaning their handlers can use ask() and ask.redirect() directly.

Returns

this

this for chaining

Example

typescript
const admin = f.router('admin')
    .use(requireAdmin)
    .interactive()   // ← all children can use ask()

mutation()

ts
mutation(action): FluentToolBuilder<TContext>;

Defined in: packages/core/src/core/builder/FluentRouter.ts:131

Create a destructive mutation tool under this router's prefix.

Parameters

ParameterTypeDescription
actionstringAction name (e.g. 'delete' → tool name 'prefix.delete')

Returns

FluentToolBuilder<TContext>

A FluentToolBuilder with the prefixed name and inherited config


query()

ts
query(action): FluentToolBuilder<TContext>;

Defined in: packages/core/src/core/builder/FluentRouter.ts:121

Create a read-only query tool under this router's prefix.

Parameters

ParameterTypeDescription
actionstringAction name (e.g. 'list' → tool name 'prefix.list')

Returns

FluentToolBuilder<TContext>

A FluentToolBuilder with the prefixed name and inherited config


tags()

ts
tags(...tags): this;

Defined in: packages/core/src/core/builder/FluentRouter.ts:90

Set capability tags shared by all tools in this router.

Parameters

ParameterTypeDescription
...tagsstring[]Tag strings for filtering

Returns

this

this for chaining


use()

Call Signature

ts
use<TDerived>(mw): FluentRouter<TContext & TDerived>;

Defined in: packages/core/src/core/builder/FluentRouter.ts:75

Add middleware shared by all tools in this router.

Accepts both MiddlewareDefinition from f.middleware() and raw MiddlewareFn functions.

Type Parameters
Type Parameter
TDerived extends Record<string, unknown>
Parameters
ParameterTypeDescription
mwMiddlewareDefinition<TContext, TDerived>Middleware function or MiddlewareDefinition
Returns

FluentRouter<TContext & TDerived>

Router with narrowed TContext type (when using MiddlewareDefinition)

Call Signature

ts
use(mw): this;

Defined in: packages/core/src/core/builder/FluentRouter.ts:78

Add middleware shared by all tools in this router.

Accepts both MiddlewareDefinition from f.middleware() and raw MiddlewareFn functions.

Parameters
ParameterTypeDescription
mwMiddlewareFn<TContext>Middleware function or MiddlewareDefinition
Returns

this

Router with narrowed TContext type (when using MiddlewareDefinition)