---
id: guide.mcp-embedding
title: Embed MCP in a Node application
summary: Mount a read-only MCP handler in your existing Node host.
type: how-to
area: discovery
subarea: discovery-mcp
canonical: /publish/embed-mcp
---

# Embed MCP in a Node application

> Documentation index: [llms.min.txt](https://www.shoalrun.com/llms.min.txt) · Document manifest: [documents.json](https://www.shoalrun.com/documents.json)

Navigation section: [Docs](https://www.shoalrun.com/.well-known/shoalrun/navigation/docs-50f26fe22670.txt) (ID: docs). [All sections and pages](https://www.shoalrun.com/llms.min.txt)

Breadcrumbs: [Docs](https://www.shoalrun.com/what-is-shoalrun.md) > Search, chat, and agent access > MCP > Embed MCP in a Node application

**Updated: 2026-11-15.**

**Available since: 1.3.0.**

Use the supported server entry point when your Node application should own the HTTP listener and authentication. The handler consumes an extracted discovery bundle; it doesn't compile source or start a service. This hosting path needs a separate discovery export even though the backend also uses Node. When Shoalrun's built-in Node server or generated Vercel function hosts MCP, its build already includes that data and no separate export is required.

## Before you begin

You need Node.js 22.12 or newer, Shoalrun, and a [discovery bundle](https://www.shoalrun.com/publish/discovery-bundles.md) for the intended content selection. Your framework must be able to pass a standard `Request` to a route and send the returned `Response`.

1. ### Open a handler for one bundle

   Import the server-only entry point in your backend:

   ```ts
   import { createMcpHandler } from '@shoalrun/cli/mcp/server';

   const handleMcp = await createMcpHandler({
     directory: './releases/example/discovery',
     path: '/mcp',
     allowedHosts: ['docs.example.com'],
     allowedOrigins: ['https://app.example.com'],
   });
   ```

   Replace the directory and hostnames with your deployment values. `directory` and `allowedHosts` are required. The path defaults to `/mcp`; origins default to an empty list. The handler binds to the bundle's publication and revision.

2. ### Route authorized requests to the handler

   After your host has routed and authorized an incoming request, call:

   ```ts
   const response = await handleMcp(request);
   ```

   Send that response through your framework's normal route integration. The host provides the listener, TLS, authentication, traffic controls, and shutdown behavior. Allowed-host and origin checks aren't user authentication. Bind each handler to the selected bundle it should serve.

   The MCP route supports POST requests and OPTIONS preflight. It doesn't provide a persistent session or standalone event stream. Responses use `Cache-Control: no-store`.

3. ### Check the endpoint

   Connect your MCP client to `https://docs.example.com/mcp`. Confirm it discovers `get_publications`, `search_docs`, `get_page`, `get_outline`, and `get_section`. Search for a known page and follow its returned read instruction.

   Run the [adapter conformance checker](https://www.shoalrun.com/publish/python-serving.md) against that endpoint and its exact bundle. Requesting another publication or an unknown page must fail rather than reading another build.

## Update the deployment

Publish a complete bundle in a new immutable directory, open a replacement handler, and switch traffic after verification. Each read checks actual bytes against the opened inventory. Changed bytes fail instead of being served under the old revision. This API doesn't maintain a revision archive for you.

The existing `shoalrun serve` and generated Vercel endpoint remain alternatives when you don't need an embedded route. See [connect an MCP client](https://www.shoalrun.com/publish/mcp.md) for those hosting paths.

## HTML, Markdown, and agents

The handler returns read-only discovery and Markdown through MCP. It doesn't serve the HTML website or apply its theme. Agents receive the selected bundle's content and publication scope. Use the separate Content REST handler when your application needs exported HTML fragments.

## Related reading

### Read first

- [Discovery bundle contract](https://www.shoalrun.com/publish/discovery-bundles.md) — Export a scoped bundle before opening its handler.

### Reference while working

- [Connect an MCP client](https://www.shoalrun.com/publish/mcp.md) — Use the built-in Node or Vercel hosting path instead.
