> ## 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.

# Provider Generator

> Generate a @Provider class for dependency injection

Generates a `@Provider` class with a Symbol token and configurable scope for the DI container.

## Usage

```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
nx g @frontmcp/nx:provider database --project crm
nx g @frontmcp/nx:provider database --project crm --scope singleton
```

## Options

| Option | Type | Default | Description |
| - | - | - | - |
| `name` | `string` | — | **Required.** The name of the provider |
| `project` | `string` | — | **Required.** The project to add the provider to |
| `scope` | `singleton` \| `request` \| `context` | `singleton` | The provider scope |
| `directory` | `string` | — | Subdirectory within `src/providers/` |

## Generated Code

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
import { Provider, ProviderScope } from '@frontmcp/sdk';

// Register with `providers: [DatabaseProvider]` on an @App or @FrontMcp,
// then resolve it inside a tool with `this.get(DatabaseProvider)`.
@Provider({
  name: 'DatabaseProvider',
  scope: ProviderScope.GLOBAL,
})
export class DatabaseProvider {
  // TODO: implement provider logic
}
```

`--scope singleton` generates `ProviderScope.GLOBAL`; `--scope request` and `--scope context` generate `ProviderScope.CONTEXT`.

The provider class is its own injection token: register the class and resolve it by the same class. There is no separate token constant to import.

## Usage in Tools

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
import { Tool, ToolContext, z } from '@frontmcp/sdk';

import { DatabaseProvider } from '../providers/database.provider';

@Tool({ name: 'query-db', inputSchema: { sql: z.string() } })
class QueryDbTool extends ToolContext {
  async execute({ sql }: { sql: string }) {
    const db = this.get(DatabaseProvider);
    return db.query(sql);
  }
}
```

Add `providers: [DatabaseProvider]` to the `@App` or `@FrontMcp` decorator so the container can build it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.