Elysia MCP Adapterelysia-mcp-adapter
API Reference

Plugin

Configure the MCP endpoint, route discovery, transport, headers, and response marshaling.

The package exposes two Elysia plugins. Use mcp() for the normal application setup. Use withMcpMethods() only when a feature plugin must register standalone primitives before the application mounts the MCP endpoint.

mcp

function mcp(options?: McpPluginOptions): Elysia
import { mcp } from '@mwillbanks/elysia-mcp-adapter'
import { Elysia } from 'elysia'

const app = new Elysia().use(
  mcp({
    server: {
      name: 'billing-api',
      version: '1.0.0'
    },
    path: '/mcp',
    allowedRoutes: '*'
  })
)

mcp() installs .mcpTool(), .mcpResource(), and .mcpPrompt(), discovers eligible routes, and mounts the JSON-RPC transport.

Prop

Type

Server metadata

Prop

Type

Response marshaling

Prop

Type

Tool annotations

Annotations tell MCP clients about behavioral properties. They do not replace application authorization.

Prop

Type

Shared metadata and icons

Prop

Type

Prop

Type

withMcpMethods

function withMcpMethods(): Elysia
new Elysia()
  .use(withMcpMethods())
  .mcpTool('health.read', () => ({ ok: true }))
  .use(mcp())

The plugin augments the Elysia instance without mounting /mcp. A later mcp() call reuses those explicit registrations and adds the endpoint.

Naming helpers

The package also exports:

function sanitizeMcpName(value: string): string
function defaultOperationNameResolver(operation: McpRouteOperation): string

sanitizeMcpName() converts an arbitrary name into the MCP-compatible form. defaultOperationNameResolver() prefers detail.operationId, then derives a stable name from the HTTP method and path.

See Configuration for production defaults and Route-backed Tools for the per-route contract.

On this page