# Run FrontMCP inside NestJS

> Mount FrontMCP on a NestJS application's Express or Fastify server and pass Nest providers to its tools.

Source: https://frontmcp.dev/reference/deployment/nestjs

[Covers FrontMCP 1.15.2](https://frontmcp.dev/versions#how-pages-are-checked) as of December 4, 2026

`@frontmcp/nestjs` mounts a FrontMCP server beside your Nest controllers. Nest keeps the HTTP listener. FrontMCP receives the MCP and OAuth requests ahead of Nest's body parser so it can read their request bodies itself.

```ts
import { FrontMcpModule } from "@frontmcp/nestjs";

FrontMcpModule.forRoot({ server, paths });
FrontMcpModule.forRootAsync({ imports, inject, useFactory });
```



---

<a id="reference"></a>

## Reference

<a id="frontmcpmoduleforrootoptions"></a>

### `FrontMcpModule.forRoot(options)`

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `server` | `FrontMcpConfigInput` | required | The config you would pass to `@FrontMcp`, with an MCP endpoint such as `http.entryPath: "/mcp"`. |
| `paths` | `string[]` | MCP entry path, `/.well-known`, `/oauth`, and the literal prefix of each `http.routes` path | Which path prefixes Nest passes to FrontMCP. A prefix matches itself and its subpaths. Supply the full list when overriding it. |

<a id="frontmcpmoduleforrootasyncoptions"></a>

### `FrontMcpModule.forRootAsync(options)`

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `imports` | `ModuleMetadata["imports"]` | none | Nest modules that export dependencies of the factory. |
| `inject` | `FactoryProvider["inject"]` | none | Nest provider tokens passed as factory arguments. |
| `useFactory` | `(...args: any[]) => FrontMcpModuleOptions \| Promise<FrontMcpModuleOptions>` | required | Builds the same options as `forRoot()`, from Nest providers. |

Both methods return a Nest `DynamicModule` and export the listener under the `FRONTMCP_REQUEST_LISTENER` injection token. `app.close()` calls the listener's `close()` before Nest closes HTTP. The package exports `frontMcpPaths(server, paths?)` to resolve the prefixes and `createFrontMcpMiddleware(listener, prefixes)` to make the middleware that forwards matching requests and calls `next()` for other requests.

<a id="caveats"></a>

#### Caveats

Use Nest 11 or 12 on its Express or Fastify platform. FrontMCP runs its own [auth](https://frontmcp.dev/reference/auth), [authority rules](https://frontmcp.dev/reference/auth/authorities) and [hooks](https://frontmcp.dev/reference/sdk/hooks) for the requests it receives. Nest controller guards, pipes and interceptors continue to apply on the Nest routes they decorate.

The default prefixes leave `/health`, `/healthz`, `/readyz` and `/metrics` outside this mount when the MCP endpoint is at `/mcp`. Add the paths you want FrontMCP to serve to the full `paths` override.

<a id="usage"></a>

## Usage

<a id="mounting-at-mcp"></a>

### Mounting at `/mcp`

> **Note**
>
> The Nest module needs a Nest HTTP application on Node. Run this example in your Nest project.

```bash
npm install @frontmcp/nestjs@1.15.2 @frontmcp/sdk@1.15.2
```

```ts app.module.ts
import { Module } from "@nestjs/common";
import { FrontMcpModule } from "@frontmcp/nestjs";
import { OrdersApp } from "./orders.app";

@Module({
  imports: [
    FrontMcpModule.forRoot({
      server: {
        info: { name: "orders", version: "1.0.0" },
        apps: [OrdersApp],
        http: { entryPath: "/mcp" },
      },
    }),
  ],
})
export class AppModule {}
```

Start the application with `NestFactory.create(AppModule)` and `app.listen(3000)`. Point the MCP client at `http://localhost:3000/mcp`.

<a id="sharing-a-nest-service-with-tools"></a>

### Sharing a Nest service with tools

Move your tool schema and handler into a FrontMCP [tool](https://frontmcp.dev/reference/sdk/tool) and register it on a FrontMCP [app](https://frontmcp.dev/reference/sdk/app). The same approach applies when moving from `@nestjs/mcp` or `@rekog/mcp-nest`. Keep the Nest service that implements the operation. Pass its instance as a value provider, then call it from the tool with `this.get(OrdersService)`.

```ts app.module.ts
FrontMcpModule.forRootAsync({
  imports: [OrdersModule],
  inject: [OrdersService],
  useFactory: (orders: OrdersService) => ({
    server: {
      info: { name: "orders", version: "1.0.0" },
      apps: [OrdersApp],
      http: { entryPath: "/mcp" },
      providers: [{ provide: OrdersService, useValue: orders }],
    },
  }),
});
```

If the old tool relied on a Nest guard or pipe, apply the equivalent check in FrontMCP's auth policy, input schema or hooks before moving its endpoint.

<a id="troubleshooting"></a>

## Troubleshooting

<a id="frontmcpnestjs-a-frontmcp-path-of--would-take-every-request-of-the-nest-application"></a>

### `@frontmcp/nestjs: a FrontMCP path of "/" would take every request of the Nest application.`

Use an explicit `http.entryPath` such as `"/mcp"`. Start each custom route with a literal segment, or set `paths` to the prefixes FrontMCP should serve.

<a id="frontmcpmodule-serves-http-create-the-application-with-nestfactorycreate"></a>

### `FrontMcpModule serves HTTP: create the application with NestFactory.create().`

Create an HTTP application with `NestFactory.create()` so the module has an HTTP adapter to mount on.
