@frontmcp/host-express

Covers FrontMCP 1.15.2 as of

Use @frontmcp/host-express when your server needs Express middleware or request and response APIs such as req.ip and res.sendFile(). A server whose routes only need web Request and Response objects can use the built-in host.

import { expressHost, type ExpressHostAdapterOptions } from "@frontmcp/host-express";

const hostFactory = expressHost();
Show all 6 sectionsHide all 6 sections

Reference

expressHost(overrides?)

ParameterTypeDefaultDescription
overridesExpressHostAdapterOptionsnoneHost options to override after FrontMCP resolves CORS, security, body limits and timeouts. This type aliases the SDK's HostAdapterOptions.

Returns a factory for http.hostFactory. The package also exports ExpressHostAdapter, UserContentListener and DEFAULT_EXPRESS_BODY_LIMIT. Its host's getHandler() returns the Express app.

Caveats

The package takes Express 4.18 or later in the 4.x line, or Express 5.

With future.builtInHost: true and no hostFactory, FrontMCP selects this host when the package is installed. An explicit hostFactory controls the choice in either mode.

Usage

Selecting Express explicitly

npm install @frontmcp/host-express@1.15.2 express cors
main.ts
import { expressHost } from "@frontmcp/host-express";
import { FrontMcp } from "@frontmcp/sdk";
import { Reports } from "./reports";

@FrontMcp({
  info: { name: "reports", version: "1.0.0" },
  apps: [Reports],
  http: { hostFactory: expressHost() },
})
export default class ReportsServer {}

Troubleshooting

HttpHostFeatureError

If the error names an Express member, verify that the server selects expressHost(). If you only need to return an HTTP response, a web-standard route works across hosts.

Report a docs issue · Report a security concern privately