---
title: Tool Generator
slug: nx-plugin/generators/tool
icon: wrench
description: Generate a @Tool class
keywords: ['frontmcp', 'mcp', 'model context protocol', 'nx', 'monorepo', 'generator', 'scaffold', 'code generation', 'tool', 'typescript']
---

Generates a `@Tool` class extending `ToolContext` with stub input/output schemas.

## Usage

```bash
nx g @frontmcp/nx:tool fetch-contacts --project crm
```

## Options

| Option      | Type     | Default | Description                                  |
| ----------- | -------- | ------- | -------------------------------------------- |
| `name`      | `string` | —       | **Required.** The name of the tool           |
| `project`   | `string` | —       | **Required.** The project to add the tool to |
| `directory` | `string` | —       | Subdirectory within `src/tools/`             |

## Generated File

```
src/tools/fetch-contacts.tool.ts
```

```ts
import { Tool, ToolContext, ToolInputOf, ToolOutputOf, z } from '@frontmcp/sdk';

// Hoist only the schemas — the rest of the @Tool config (name, description,
// annotations, throttling, …) stays inside @Tool({…}) where it naturally
// lives. Changing a schema field automatically updates the derived TS types.
const inputSchema = {
  value: z.string().describe('TODO: replace with actual input'),
};

const outputSchema = {
  result: z.string().describe('TODO: replace with actual output'),
};

export type FetchContactsInput = ToolInputOf<{ inputSchema: typeof inputSchema }>;
export type FetchContactsOutput = ToolOutputOf<{ outputSchema: typeof outputSchema }>;

@Tool({
  name: 'fetch-contacts',
  description: 'TODO: describe what this tool does',
  inputSchema,
  outputSchema,
})
export default class FetchContactsTool extends ToolContext {
  async execute(input: FetchContactsInput): Promise<FetchContactsOutput> {
    // TODO: implement
    return { result: input.value };
  }
}
```

## Example

```bash
# Add to a specific subdirectory
nx g @frontmcp/nx:tool send-email --project crm --directory notifications
# Creates: src/tools/notifications/send-email.tool.ts
```

After generating, update the app to register the tool:

```ts
import FetchContactsTool from './tools/fetch-contacts.tool';

@App({
  id: 'crm',
  tools: [FetchContactsTool],
})
class CrmApp {}
```
