Skip to main content

Overview

scope.providers is typed ProviderRegistryInterface, which declares get(), getScope(), getProviders(), getRegistries() and buildViews(). The other methods on this page belong to the exported ProviderRegistry class, which the scope’s registry is at runtime: narrow with instanceof ProviderRegistry to call them.

Methods

get()

Get a GLOBAL-scoped (singleton) provider.
Example:

getScoped()

Get a provider from given views (for session/request scoped providers).
Example:

resolve()

Lightweight synchronous resolver for app-scoped DI. A registered token must be a GLOBAL provider that is already instantiated; a class that is not registered is constructed, and its synchronous init() called.
Example:

resolveBootstrapDep()

Resolve a GLOBAL-scoped provider during the bootstrap phase, from this registry or a parent registry. It returns an instance that already exists and never instantiates one: it throws PluginDependencyError when the provider is not GLOBAL-scoped, is not instantiated yet, or is not found, so instantiate the provider before a bootstrap caller resolves it.

getProviders()

Get all provider entries.

buildViews()

Build provider views for different scopes. Async — instantiates context-scoped providers per request.
The tools:call-tool, resources:read-resource and prompts:get-prompt flows build an entry’s views with the scope’s views as contextProviders and the scope registry as contextSource. As a result, a tool resolves the providers of the plugins its own app installed, even when another app on the same server installs the same plugin with different options. Example:

addRegistry()

Add a registry by type.

getRegistries()

Get registries by type.

getHooksRegistry()

Get the hooks registry.

getScopeRegistry()

Get the scope registry.

mergeFromRegistry()

Merge providers from another registry. With visibleBelow, the merged providers resolve for this registry’s own lookups and for visibleBelow’s subtree; other registries below this one resolve them as if they were not merged.

getProviderInfo()

Get a provider’s definition and its instance (undefined for a CONTEXT-scoped provider, built per request), in the shape mergeFromRegistry() takes. Throws ProviderNotRegisteredError when this registry does not define the token.

injectProvider()

Inject a provider value directly.
Example:

addDynamicProviders()

Add providers dynamically at runtime. Async — instantiates global-scoped providers immediately.

Session Management

cleanupSession()

Clean up a specific session’s provider cache.

cleanupExpiredSessions()

Clean up expired sessions from cache. Returns the number of sessions removed.

startSessionCleanup()

Start background session cleanup timer.

stopSessionCleanup()

Stop background session cleanup timer.

getSessionCacheStats()

Get session cache statistics.

isSessionCacheEnabled()

Check if session caching is enabled.

dispose()

Dispose registry and clean up all resources.

Server/Scope Access

getActiveScope()

Get the active scope.

getActiveServer()

Get the active server.

Provider Scopes

A provider uses one of two ProviderScope values:
ProviderScope.SESSION and ProviderScope.REQUEST are deprecated: the registry treats both as CONTEXT.

Provider Views

Provider views represent the hierarchy of available providers:

Indexes

Session Caching

The registry implements LRU eviction and TTL-based session caching:

Provider Definition

A provider is a ProviderType: a class decorated with @Provider, or an object with a provide token, a name and one of useClass, useValue or useFactory. A factory provider adds inject, a function returning the tokens of its dependencies, when it has any. Every form takes an optional scope (ProviderScope.GLOBAL by default), description and id. The providers of @FrontMcp, @App, @Plugin and @Agent accept a @Provider class, a useValue holding an instance of one, or a factory provider with a name, and refuse the other forms. A plugin’s dynamicProviders() can return any of them. Example: