Providers are dependency-injected singletons (or scoped singletons) that your apps, tools, adapters, and plugins can use — e.g., config, DB pools, Redis clients, KMS, HTTP clients. They’re declared withDocumentation Index
Fetch the complete documentation index at: https://docs.agentfront.dev/llms.txt
Use this file to discover all available pages before exploring further.
@Provider() and registered at server or app scope. Resolution is hierarchical: tool → app → server.
Provider metadata, records, and DI helpers remain available through
@frontmcp/sdk as type-only exports, so your existing @frontmcp/di imports keep working while bundlers drop unused types. Enums such as ProviderScope and ProviderKind still expose their runtime values, so you can configure scopes the same way you always have.Define a provider
Scopes
- GLOBAL (default): one instance per process/worker. Ideal for clients, pools, caches.
- CONTEXT: one instance per request. Use for per-request state, tracing, or user-specific data.
Legacy scopes
SESSION and REQUEST are deprecated and automatically normalized to CONTEXT.Register providers
Server-level providers (available to all apps):Using providers from tools/plugins
FrontMCP resolves providers for your executors and hooks. Keep your tool logic pure; read side-effects (DB, queues, secrets) via providers.- Prefer GLOBAL for shared clients.
- Use CONTEXT for request-scoped state or user-bound data.
Provider injection/consumption follows your runtime’s DI rules. In general: register providers at the minimal scope
and let the framework resolve them for tools and hooks at execution time.
FrontMcpContext
Every HTTP request creates aFrontMcpContext that flows through the entire execution chain via AsyncLocalStorage. Access it via the FRONTMCP_CONTEXT token or the context getter.
In Tools/Resources/Prompts
In CONTEXT-Scoped Providers
CONTEXT-scoped providers can access the current context via factory injection:FrontMcpContext API
| Property | Type | Description |
|---|---|---|
requestId | string | Unique request identifier (UUID v4) |
traceContext | TraceContext | W3C Trace Context (traceId, parentId, traceFlags) |
sessionId | string | MCP session identifier |
authInfo | Partial<AuthInfo> | Authentication information |
scopeId | string | Current scope identifier |
timestamp | number | Request start timestamp |
metadata | RequestMetadata | Headers, user-agent, client IP |
transport | TransportAccessor | undefined | Transport for elicit requests |
| Method | Description |
|---|---|
mark(name) | Record timing mark |
elapsed(from?, to?) | Get elapsed time between marks |
set(key, value) | Store context-scoped data |
get(key) | Retrieve context-scoped data |
getLogger(parent) | Get child logger with context |
fetch(input, init?) | Context-aware fetch with auto-injection |
Context-Aware Fetch
Usectx.fetch() to automatically inject headers into outgoing requests:
Transport Access (Elicit)
Access the transport for interactive prompts:CONTEXT-Scoped Providers
CONTEXT-scoped providers are created fresh for each request. They’re ideal for per-request state, user-specific data, or request-scoped caching.Accessing Session ID
The session ID is available directly from the context:Example: Context-Scoped Redis Provider
Multi-Pod Deployment Considerations
When running behind a load balancer:- Each request builds its own provider instances
- Transport state (MCP protocol) is shared via Redis (if configured)
- For cross-pod session data, use Redis or another distributed store