Skip to main content

Type Alias: CreateToolGateOptions

CreateToolGateOptions = object

Defined in: toolGate.ts:30

Options for createToolGate.

Properties​

buildContext?​

optional buildContext?: (ctx) => Record<string, unknown>

Defined in: toolGate.ts:61

Called once per invocation to produce extra key-value pairs that are merged into the handler args. Receives the full ToolCallContext so context can vary by identity or by call args.

Parameters​

ParameterType
ctxToolCallContext

Returns​

Record<string, unknown>


enforceScope?​

optional enforceScope?: boolean

Defined in: toolGate.ts:49

When true (default), checks requiredScope against identity.scopes and returns an isError result when the scope is absent. Set to false to skip the scope check (e.g. when all scopes are enforced by gates).


gates?​

optional gates?: ToolCallGate[]

Defined in: toolGate.ts:43

Global authorization gates run after the scope check, in order, before per-tool gates. Each receives the full ToolCallContext — both identity and the validated call args — so gate predicates may be conditional on either. Gates own their own error handling — onError covers the tool handler only.


i18n?​

optional i18n?: object

Defined in: toolGate.ts:74

Renders a LocalizedError — thrown by a gate or by the handler — as an isError result { error: <message>, code } in the caller's locale, instead of letting the SDK surface its source-language message. Gates run outside the handler, so this is the one place both are covered.

getLocale defaults to the MCP request's Accept-Language (getRequestLocale()); return a fixed locale to pin the agent contract to one language. onError still runs for a handler error before it is rendered. Errors that are not localized behave exactly as without this option.

catalog​

catalog: Pick<Catalog, "getI18n">

getLocale?​

optional getLocale?: (ctx) => string | string[] | null | undefined | Promise<string | string[] | null | undefined>

Parameters​
ParameterType
ctxToolCallContext
Returns​

string | string[] | null | undefined | Promise<string | string[] | null | undefined>


onError?​

optional onError?: (error, ctx) => void | Promise<void>

Defined in: toolGate.ts:55

Called when the tool handler throws. Use for error reporting/telemetry. The error is always rethrown after this hook completes. Note: scope-check failures and gate rejections do not trigger onError.

Parameters​

ParameterType
errorunknown
ctxToolCallContext

Returns​

void | Promise<void>


resolveIdentity?​

optional resolveIdentity?: () => ToolIdentity

Defined in: toolGate.ts:35

Called once per tool invocation to resolve the caller's identity. Defaults to getIdentity() from the request context.

Returns​

ToolIdentity