Elysia MCP Adapterelysia-mcp-adapter
Core Concepts

Standalone Primitives

Register MCP-only tools without creating HTTP routes.

Standalone primitives are useful when behavior belongs to the MCP surface but not to your public HTTP API.

Tools

new Elysia()
  .use(mcp({ allowedRoutes: [] }))
  .mcpTool(
    'math.add',
    ({ a, b }: { a: number; b: number }) => ({ sum: a + b }),
    {
      title: 'Add numbers',
      description: 'Add two finite numbers.',
      inputSchema: {
        type: 'object',
        properties: {
          a: { type: 'number' },
          b: { type: 'number' }
        },
        required: ['a', 'b'],
        additionalProperties: false
      },
      outputSchema: {
        type: 'object',
        properties: { sum: { type: 'number' } },
        required: ['sum']
      },
      annotations: {
        readOnlyHint: true,
        idempotentHint: true
      }
    }
  )

Handlers may return a plain JSON-compatible value or a complete MCP tool result with content, structuredContent, isError, and _meta.

Install methods before the endpoint

withMcpMethods() installs the fluent registration methods without exposing /mcp yet:

import { mcp, withMcpMethods } from '@mwillbanks/elysia-mcp-adapter'

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

This can help compose feature plugins before the application decides where and how to expose MCP.

See the exact method signatures and generated option tables in Standalone Primitives API.

On this page