Skip to main content

Type Alias: CreateGatedToolRegistrarOptions

CreateGatedToolRegistrarOptions = object

Defined in: createGatedToolRegistrar.ts:54

Options for createGatedToolRegistrar.

Properties​

buildContext?​

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

Defined in: createGatedToolRegistrar.ts:88

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: createGatedToolRegistrar.ts:76

When true (default), checks def.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?: (ctx) => void | Promise<void>[]

Defined in: createGatedToolRegistrar.ts:70

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. Throw to reject the call; return (or resolve) to continue. Gates own their own error handling — onError covers the tool handler only.

Parameters​

ParameterType
ctxToolCallContext

Returns​

void | Promise<void>


i18n?​

optional i18n?: object

Defined in: createGatedToolRegistrar.ts:106

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>


notFoundMessage?​

optional notFoundMessage?: string

Defined in: createGatedToolRegistrar.ts:93

Message returned as an isError result when the handler resolves to null or undefined. Defaults to "Not found".


onError?​

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

Defined in: createGatedToolRegistrar.ts:82

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: createGatedToolRegistrar.ts:61

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

Returns​

ToolIdentity


server​

server: McpServer

Defined in: createGatedToolRegistrar.ts:56

The MCP server instance to register tools on.