Skip to content

Class: ResourceRegistry<TContext>

Defined in: packages/core/src/resource/ResourceRegistry.ts:43

Type Parameters

Type ParameterDefault type
TContextvoid

Constructors

Constructor

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

Returns

ResourceRegistry<TContext>

Accessors

hasSubscribableResources

Get Signature

ts
get hasSubscribableResources(): boolean;

Defined in: packages/core/src/resource/ResourceRegistry.ts:213

Whether any registered resource supports subscriptions.

Returns

boolean


size

Get Signature

ts
get size(): number;

Defined in: packages/core/src/resource/ResourceRegistry.ts:210

Number of registered resources.

Returns

number


subscriptions

Get Signature

ts
get subscriptions(): SubscriptionManager;

Defined in: packages/core/src/resource/ResourceRegistry.ts:221

Get the subscription manager (for testing and advanced wiring).

Returns

SubscriptionManager

Methods

clear()

ts
clear(): void;

Defined in: packages/core/src/resource/ResourceRegistry.ts:226

Remove all registered resources and cancel pending timers.

Returns

void


has()

ts
has(name): boolean;

Defined in: packages/core/src/resource/ResourceRegistry.ts:207

Check if a resource with the given name is registered.

Parameters

ParameterType
namestring

Returns

boolean


listResources()

ts
listResources(): McpResourceDef[];

Defined in: packages/core/src/resource/ResourceRegistry.ts:82

Get all registered MCP Resource definitions for resources/list.

Returns compiled resource metadata including URIs, descriptions, MIME types, and annotations.

Returns

McpResourceDef[]


notifyChanged()

ts
notifyChanged(): void;

Defined in: packages/core/src/resource/ResourceRegistry.ts:190

Notify all connected clients that the resource catalog has changed.

Sends notifications/resources/list_changed. Debounced: multiple calls within 100ms are coalesced into one notification.

Returns

void


notifyUpdated()

ts
notifyUpdated(uri): Promise<void>;

Defined in: packages/core/src/resource/ResourceRegistry.ts:158

Emit a resource update notification to subscribed clients.

Only emits if the URI is subscribed. Uses the subscription manager's notification sink (wired by ServerAttachment).

Parameters

ParameterTypeDescription
uristringThe URI of the resource that changed

Returns

Promise<void>


readResource()

ts
readResource(uri, ctx): Promise<{
  contents: {
     blob?: string;
     mimeType?: string;
     text?: string;
     uri: string;
  }[];
}>;

Defined in: packages/core/src/resource/ResourceRegistry.ts:100

Read a resource by URI for resources/read.

Matches the requested URI against registered resource URI templates. Returns the resource content or throws if no matching resource is found.

Parameters

ParameterTypeDescription
uristringThe URI requested by the client
ctxTContextApplication context (from contextFactory)

Returns

Promise<{ contents: { blob?: string; mimeType?: string; text?: string; uri: string; }[]; }>

MCP-compatible resource read result


register()

ts
register(builder): void;

Defined in: packages/core/src/resource/ResourceRegistry.ts:57

Register a single resource builder.

Parameters

ParameterTypeDescription
builderResourceBuilder<TContext>A resource builder (from defineResource())

Returns

void

Throws

If a resource with the same name is already registered


registerAll()

ts
registerAll(...builders): void;

Defined in: packages/core/src/resource/ResourceRegistry.ts:68

Register multiple resource builders at once.

Parameters

ParameterType
...buildersResourceBuilder<TContext>[]

Returns

void


subscribe()

ts
subscribe(uri): boolean;

Defined in: packages/core/src/resource/ResourceRegistry.ts:132

Subscribe to push notifications for a resource URI.

Only succeeds if the resource is marked as subscribable.

Parameters

ParameterTypeDescription
uristringThe resource URI to subscribe to

Returns

boolean

true if subscription was accepted, false if resource is not subscribable


unsubscribe()

ts
unsubscribe(uri): void;

Defined in: packages/core/src/resource/ResourceRegistry.ts:146

Unsubscribe from push notifications for a resource URI.

Parameters

ParameterTypeDescription
uristringThe resource URI to unsubscribe from

Returns

void