Skip to content

Class: PromptRegistry<TContext>

Defined in: packages/core/src/prompt/PromptRegistry.ts:111

Type Parameters

Type ParameterDefault type
TContextvoid

Constructors

Constructor

ts
new PromptRegistry<TContext>(): PromptRegistry<TContext>;

Returns

PromptRegistry<TContext>

Accessors

size

Get Signature

ts
get size(): number;

Defined in: packages/core/src/prompt/PromptRegistry.ts:484

Number of registered prompts.

Returns

number

Methods

clear()

ts
clear(): void;

Defined in: packages/core/src/prompt/PromptRegistry.ts:481

Remove all registered prompts.

Returns

void


configurePagination()

ts
configurePagination(options): void;

Defined in: packages/core/src/prompt/PromptRegistry.ts:128

Configure stateless cursor-based pagination for prompts/list. Overrides the default page size of 50.

Parameters

ParameterTypeDescription
optionsPromptPaginationOptionsPagination configuration (pageSize, modes, secrets)

Returns

void


getAllPrompts()

ts
getAllPrompts(): McpPromptDef[];

Defined in: packages/core/src/prompt/PromptRegistry.ts:223

Get all registered MCP Prompt definitions.

Returns the compiled prompt metadata for prompts/list.

Returns

McpPromptDef[]

Deprecated

Use listPrompts({ filter }) instead for pagination support.


getPrompts()

ts
getPrompts(filter): McpPromptDef[];

Defined in: packages/core/src/prompt/PromptRegistry.ts:237

Get prompt definitions filtered by tags.

Uses Set-based lookups for O(1) tag matching.

Parameters

ParameterType
filterPromptFilter

Returns

McpPromptDef[]

Deprecated

Use listPrompts({ filter }) instead for pagination support.


has()

ts
has(name): boolean;

Defined in: packages/core/src/prompt/PromptRegistry.ts:478

Check if a prompt with the given name is registered.

Parameters

ParameterType
namestring

Returns

boolean


listPrompts()

ts
listPrompts(request?): Promise<{
  nextCursor?: string;
  prompts: McpPromptDef[];
}>;

Defined in: packages/core/src/prompt/PromptRegistry.ts:281

Get paginated prompt definitions for prompts/list.

Applies tag filters and decodes stateless cursors to return the requested slice of prompts, along with a nextCursor if more exist. Memory consumption is strictly O(1) across connections.

Parameters

ParameterTypeDescription
request?{ cursor?: string; filter?: PromptFilter; }Configuration containing optional filter and cursor.
request.cursor?string-
request.filter?PromptFilter-

Returns

Promise<{ nextCursor?: string; prompts: McpPromptDef[]; }>

Object with the array of prompts and an optional nextCursor.


notifyChanged()

ts
notifyChanged(): void;

Defined in: packages/core/src/prompt/PromptRegistry.ts:462

Notify all connected clients that the prompt catalog has changed.

Sends notifications/prompts/list_changed to all connected clients, causing them to re-fetch prompts/list and update their UI.

Debounced: Multiple calls within 100ms are coalesced into a single notification to prevent storms during bulk registration or RBAC updates.

Use cases:

  • RBAC change: user promoted/demoted → visible prompts change
  • SOP update: compliance rules changed → prompt logic updated
  • Feature flag: new prompt enabled for beta users

Returns

void

Example

typescript
// In your RBAC webhook handler:
app.post('/webhooks/role-changed', async (req) => {
    await db.users.updateRole(req.userId, req.newRole);
    promptRegistry.notifyChanged(); // All clients refresh instantly
});

register()

ts
register(builder): void;

Defined in: packages/core/src/prompt/PromptRegistry.ts:169

Register a single prompt builder.

Validates that the prompt name is unique and triggers buildPromptDefinition() to compile at registration time.

Parameters

ParameterTypeDescription
builderPromptBuilder<TContext>A prompt builder (from definePrompt())

Returns

void

Throws

If a prompt with the same name is already registered


registerAll()

ts
registerAll(...builders): void;

Defined in: packages/core/src/prompt/PromptRegistry.ts:181

Register multiple prompt builders at once.

Parameters

ParameterType
...buildersPromptBuilder<TContext>[]

Returns

void


routeGet()

ts
routeGet(
   ctx, 
   name, 
args): Promise<PromptResult>;

Defined in: packages/core/src/prompt/PromptRegistry.ts:339

Route an incoming prompts/get request to the correct builder.

Looks up the builder by name and delegates to its execute() method. Returns an error prompt result if the prompt is not found.

Parameters

ParameterTypeDescription
ctxTContextApplication context (from contextFactory)
namestringPrompt name from the incoming MCP request
argsRecord<string, string>Raw string arguments from the MCP client

Returns

Promise<PromptResult>

The hydrated prompt result


setDefaultHydrationTimeout()

ts
setDefaultHydrationTimeout(ms): void;

Defined in: packages/core/src/prompt/PromptRegistry.ts:156

Set a global hydration timeout for ALL prompts in this registry.

Individual prompts can override with their own hydrationTimeout. If neither is set, no timeout is applied (backward compatible).

Enterprise use case: The platform team sets a 5s global deadline. Critical prompts like morning_briefing set their own 3s deadline. Simple prompts (no external I/O) inherit the 5s safety net.

Parameters

ParameterTypeDescription
msnumberMaximum hydration time in milliseconds (must be > 0)

Returns

void

Example

typescript
const promptRegistry = new PromptRegistry<AppContext>();
promptRegistry.setDefaultHydrationTimeout(5000); // 5s global safety net

useInterceptor()

ts
useInterceptor(interceptor): void;

Defined in: packages/core/src/prompt/PromptRegistry.ts:213

Register a global Prompt Interceptor.

Interceptors run AFTER the handler produces its PromptResult and BEFORE the result is returned to the MCP client. They can prepend/append messages to inject compliance headers, tenant context, RBAC constraints, or any global state that should wrap every prompt.

Enterprise use case: The CISO requires every LLM interaction to include tenant isolation rules. Register one interceptor — it applies to all 50 prompts.

Multiple interceptors are supported. They execute in registration order.

Parameters

ParameterTypeDescription
interceptorPromptInterceptorFn<TContext>Callback receiving (ctx, builder, promptMeta)

Returns

void

Example

typescript
promptRegistry.useInterceptor(async (ctx, builder, meta) => {
    builder.prependSystem(
        `[ENTERPRISE COMPLIANCE LAYER]\n` +
        `User Role: ${ctx.user.role} (Tenant ID: ${ctx.tenant.id})\n` +
        `Server Time: ${new Date().toISOString()}`
    );
});