Skip to main content

Interface: McpRouterOptions

Defined in: index.ts:155

Options for configuring the MCP router

Properties

apiBaseUrl?

optional apiBaseUrl?: string

Defined in: index.ts:177

Base URL prepended to relative paths passed to apiCall (paths starting with /). Tool handlers can then call apiCall('GET', '/resource') without specifying a host.

Example

'http://localhost:3000/api/v1'

getApiHeaders?

optional getApiHeaders?: (ctx) => Record<string, string>

Defined in: index.ts:203

Called once per incoming MCP HTTP request. Return a plain object whose key-value pairs will be merged into the headers of every apiCall made within that request's tool handlers.

Use this to forward any header from the MCP request — Bearer tokens, API keys, tenant IDs, trace headers, etc. — without coupling tool handlers to a specific authentication scheme.

Parameters

ParameterType
ctxContext

Returns

Record<string, string>

Examples

getApiHeaders: (ctx) => ({ Authorization: ctx.headers.authorization ?? '' })
getApiHeaders: (ctx) => ({ 'x-api-key': ctx.headers['x-api-key'] as string })
getApiHeaders: () => ({ 'x-internal-key': process.env.INTERNAL_API_KEY! })

path?

optional path?: string

Defined in: index.ts:160

The HTTP path where the MCP server will be mounted

Default

'/mcp'

sessionIdGenerator?

optional sessionIdGenerator?: () => string

Defined in: index.ts:168

Optional session ID generator for stateful MCP servers. When provided, a single shared transport is created and sessions are tracked. When undefined (default), the server operates in stateless mode where each HTTP request uses its own transport instance.

Returns

string