Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.agentfront.dev/llms.txt

Use this file to discover all available pages before exploring further.

FrontMCP includes a built-in dependency injection system. Define services with @Provider, inject them into tools, resources, prompts, and agents with this.get().

Defining Providers

Create a provider with a name and (optional) scope:
import { Provider, ProviderScope } from '@frontmcp/sdk';

@Provider({
  name: 'ConfigProvider',
  scope: ProviderScope.GLOBAL,
})
export class ConfigProvider {
  readonly apiKey = process.env.API_KEY!;
  readonly baseUrl = process.env.BASE_URL!;
}
To inject by interface, register with a token (a class, abstract class, or symbol). The class itself is the most common token:
import { App } from '@frontmcp/sdk';

abstract class ConfigService {
  abstract readonly apiKey: string;
}

class EnvConfigService extends ConfigService {
  readonly apiKey = process.env.API_KEY!;
}

@App({
  name: 'app',
  providers: [{ provide: ConfigService, useClass: EnvConfigService }],
})
class MyApp {}

Provider Scopes

ScopeLifetimeUse Case
globalOne instance per server (default)Configuration, database connections
contextOne instance per execution contextPer-request state, logging, caches
'session' and 'request' are kept as deprecated aliases of 'context'.

Injecting Providers

Use this.get() or this.tryGet() inside any context class:
@Tool({
  name: 'fetch-data',
  inputSchema: { url: z.string() },
})
class FetchDataTool extends ToolContext {
  async execute({ url }: { url: string }) {
    const config = this.get(ConfigService);   // Throws if not found
    const cache = this.tryGet(CacheService);  // Returns undefined if not found

    const response = await this.fetch(url, {
      headers: { Authorization: `Bearer ${config.apiKey}` },
    });

    return response.json();
  }
}

Registering Providers

Register providers at the server or app level:
// Server-level — available to all apps
@FrontMcp({
  info: { name: 'Server', version: '1.0.0' },
  apps: [MyApp],
  providers: [ConfigProvider, DatabaseProvider],
})
class Server {}

// App-level — available only within this app
@App({
  id: 'crm',
  name: 'CRM',
  tools: [CreateLeadTool],
  providers: [CrmServiceProvider],
})
class CrmApp {}
Server-level providers are shared across all apps. App-level providers are isolated to their app.

Learn More

Providers Guide

Full guide to defining, scoping, and composing providers

@Provider Reference

Complete decorator API reference