# Mount FrontMCP in a web framework

> Serve FrontMCP from a Next.js, Hono, Nuxt or SvelteKit application by forwarding the original web request.

Source: https://frontmcp.dev/reference/deployment/web-frameworks

[Checked against FrontMCP 1.15.2](https://frontmcp.dev/versions#how-pages-are-checked) on December 4, 2026

If your web application already serves HTTP, forward its MCP requests to [`FrontMcpInstance.createFetchHandler()`](https://frontmcp.dev/reference/sdk/create-fetch-handler). The framework owns the listener and routes. FrontMCP receives the original web `Request` and returns a `Response`.

```ts
import { FrontMcpInstance } from "@frontmcp/sdk";

const handle = await FrontMcpInstance.createFetchHandler(config);
const response = await handle(request);
```



---

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

## Reference

<a id="paths-and-sessions"></a>

### Paths and sessions

| Request | Route to mount |
| --- | --- |
| MCP at `/mcp` | Pass the original URL and set `http.entryPath: "/mcp"`. |
| A web-standard `http.routes` endpoint | Forward the full path, such as `/mcp/status`, and use it in the route config. |
| Protected resource metadata for `/mcp` | Also forward `/.well-known/oauth-protected-resource/mcp` when using auth. |
| Local or remote OAuth | Forward the root `/oauth` and `/.well-known` routes FrontMCP serves, including OAuth metadata and callbacks. |
| Health probes | Forward `/healthz` and `/readyz`, or put `health.healthzPath` and `health.readyzPath` under the mounted prefix. |

A stateless fetch handler serves requests independently. Clients on older Streamable HTTP revisions get no `Mcp-Session-Id` and cannot open a standalone GET stream. Set [`MCP_SESSION_SECRET`](https://frontmcp.dev/reference/sdk/create-fetch-handler#production-secrets) in production if those clients connect. If they need sessions, use the [Node host](https://frontmcp.dev/reference/deployment/node) or [a Worker with Durable Object sessions](https://frontmcp.dev/reference/deployment/edge).

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

## Usage

<a id="sharing-one-handler-across-routes"></a>

### Sharing one handler across routes

> **Note**
>
> Use the route files below in the named frameworks. The Playground shows the same request forwarding without starting a framework listener.

```ts mcp.ts active
import { app, FrontMcpInstance, tool, type FetchHandlerCtx, type WebFetchHandler } from "@frontmcp/sdk";

export const status = tool({ name: "status", description: "Read service status", inputSchema: {} })(
  () => ({ status: "ok" }),
);

let handler: Promise<WebFetchHandler> | undefined;

export async function handleMcpRequest(request: Request, context?: FetchHandlerCtx): Promise<Response> {
  handler ??= FrontMcpInstance.createFetchHandler({
    info: { name: "reports", version: "1.0.0" },
    apps: [app({ name: "Reports", tools: [status] })],
    http: {
      entryPath: "/mcp",
      routes: [{ method: "GET", path: "/mcp/status", fetch: () => Response.json({ status: "ok" }) }],
    },
  }).catch((error: unknown) => {
    handler = undefined;
    throw error;
  });
  return (await handler)(request, context);
}
```

```ts mcp.test.ts
import { expect, test } from "@frontmcp/testing";
import { handleMcpRequest } from "./mcp";

test("the full URL reaches the FrontMCP route", async () => {
  const response = await handleMcpRequest(new Request("https://reports.example.com/mcp/status"));
  expect(response.status).toBe(200);
  expect(await response.json()).toEqual({ status: "ok" });
});
```

Build the handler on the first request so the framework can load the route file at build time without starting FrontMCP. Forward the request before other middleware reads its body. Pass plain configuration to the factory. Importing a class decorated with `@FrontMcp` can start a separate listener.

<a id="nextjs-app-router"></a>

### Next.js App Router

In `app/mcp/[[...path]]/route.ts`, use the optional catch-all to match both `/mcp` and paths below it. Keep the Node runtime. Export `OPTIONS` to let FrontMCP answer configured CORS preflights.

```ts
import { handleMcpRequest } from "@/lib/mcp";

export const GET = (request: Request) => handleMcpRequest(request);
export const POST = GET;
export const DELETE = GET;
export const OPTIONS = GET;
```

With auth, export `GET` and `OPTIONS` from the same handler in `app/.well-known/oauth-protected-resource/mcp/route.ts`.

<a id="hono"></a>

### Hono

```ts
import { Hono } from "hono";
import { handleMcpRequest } from "./mcp";

const app = new Hono();
app.all("/mcp/*", (ctx) => handleMcpRequest(ctx.req.raw));
app.all("/.well-known/oauth-protected-resource/mcp", (ctx) => handleMcpRequest(ctx.req.raw));
export default app;
```

On Workers, pass `ctx.executionCtx` as the second argument of `handleMcpRequest()` so FrontMCP can keep streamed responses alive. The Node adapter provides no Worker execution context.

<a id="nuxt-with-nitro-and-h3-1x"></a>

### Nuxt with Nitro and h3 1.x

Define the handler in `server/utils/mcp-handler.ts` and export it as the default from `server/routes/mcp/index.ts` and `server/routes/mcp/[...].ts`. The catch-all serves subpaths. With auth, export it from `server/routes/.well-known/oauth-protected-resource/mcp.ts` too.

```ts
import { defineEventHandler, toWebRequest } from "h3";
import { handleMcpRequest } from "./mcp";

export const mcpEventHandler = defineEventHandler((event) => handleMcpRequest(toWebRequest(event)));
```

<a id="sveltekit"></a>

### SvelteKit

Use `src/routes/mcp/[...path]/+server.ts`. The rest parameter also matches `/mcp`. Keep this route free of a `+page` so an HTML navigation can reach the handler. With auth, define the same `fallback` in `src/routes/.well-known/oauth-protected-resource/mcp/+server.ts`.

```ts
import { handleMcpRequest } from "$lib/server/mcp";
import type { RequestHandler } from "./$types";

export const fallback: RequestHandler = ({ request }) => handleMcpRequest(request);
```

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

## Troubleshooting

<a id="errornot-foundentrypathsmcp"></a>

### `{"error":"Not Found","entryPaths":["/mcp"]}`

Compare the path in the request URL with `http.entryPath` and the configured custom routes. Preserve `/mcp` in the URL when the framework forwards the request.
