Class: PromptRegistry<TContext>
Defined in: packages/core/src/prompt/PromptRegistry.ts:111
Type Parameters
| Type Parameter | Default type |
|---|---|
TContext | void |
Constructors
Constructor
new PromptRegistry<TContext>(): PromptRegistry<TContext>;Returns
PromptRegistry<TContext>
Accessors
size
Get Signature
get size(): number;Defined in: packages/core/src/prompt/PromptRegistry.ts:484
Number of registered prompts.
Returns
number
Methods
clear()
clear(): void;Defined in: packages/core/src/prompt/PromptRegistry.ts:481
Remove all registered prompts.
Returns
void
configurePagination()
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
| Parameter | Type | Description |
|---|---|---|
options | PromptPaginationOptions | Pagination configuration (pageSize, modes, secrets) |
Returns
void
getAllPrompts()
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
Deprecated
Use listPrompts({ filter }) instead for pagination support.
getPrompts()
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
| Parameter | Type |
|---|---|
filter | PromptFilter |
Returns
Deprecated
Use listPrompts({ filter }) instead for pagination support.
has()
has(name): boolean;Defined in: packages/core/src/prompt/PromptRegistry.ts:478
Check if a prompt with the given name is registered.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
boolean
listPrompts()
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
| Parameter | Type | Description |
|---|---|---|
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()
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
// 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()
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
| Parameter | Type | Description |
|---|---|---|
builder | PromptBuilder<TContext> | A prompt builder (from definePrompt()) |
Returns
void
Throws
If a prompt with the same name is already registered
registerAll()
registerAll(...builders): void;Defined in: packages/core/src/prompt/PromptRegistry.ts:181
Register multiple prompt builders at once.
Parameters
| Parameter | Type |
|---|---|
...builders | PromptBuilder<TContext>[] |
Returns
void
routeGet()
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
| Parameter | Type | Description |
|---|---|---|
ctx | TContext | Application context (from contextFactory) |
name | string | Prompt name from the incoming MCP request |
args | Record<string, string> | Raw string arguments from the MCP client |
Returns
Promise<PromptResult>
The hydrated prompt result
setDefaultHydrationTimeout()
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
| Parameter | Type | Description |
|---|---|---|
ms | number | Maximum hydration time in milliseconds (must be > 0) |
Returns
void
Example
const promptRegistry = new PromptRegistry<AppContext>();
promptRegistry.setDefaultHydrationTimeout(5000); // 5s global safety netuseInterceptor()
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
| Parameter | Type | Description |
|---|---|---|
interceptor | PromptInterceptorFn<TContext> | Callback receiving (ctx, builder, promptMeta) |
Returns
void
Example
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()}`
);
});