Skip to content

@forinda/kickjs-mcp

Expose controller routes as Model Context Protocol tools for Claude Code, Claude Desktop, Cursor and other MCP clients. The MCP guide covers transports, auth patterns and the Inspector.

Installation

pnpm add @forinda/kickjs-mcp @modelcontextprotocol/sdk

Exports

ExportDescription
McpAdapterAdapter factory: discovers tools and serves the MCP endpoint
@McpTool(opts)Expose a controller method as a tool
getMcpToolMetaRead @McpTool options for a method
isMcpToolWhether a method carries @McpTool
MCP_TOOL_METADATAMetadata key @McpTool writes
MCP_ADAPTERDI token for the adapter instance (McpAdapterInstance)

Types: McpAdapterInstance, McpAdapterOptions, McpTransport, McpExposureMode, McpAuthOptions, McpToolOptions, McpToolDefinition, McpToolExample, McpToolProvider, McpCustomTool, McpToolContext.

McpAdapterInstance

Resolve with container.resolve(MCP_ADAPTER).

MethodDescription
registerProvider(p)Mount a McpToolProvider — tools that aren't routes; clients get tools/list_changed
unregisterProvider(name)Unmount a provider; returns false when none has that name
getTools()The route tools discovered at startup

McpAdapter options

OptionTypeDefaultDescription
namestringrequiredServer name shown to clients
versionstring'0.0.0'Server version shown to clients
descriptionstringServer description
mode'explicit' | 'auto''explicit'explicit: only @McpTool (and exposeWhen) routes; auto: every route passing the filters
transport'http' | 'stdio' | 'sse''http'Streamable HTTP, stdio, or sse (deprecated alias of http)
basePathstring'/_mcp'Endpoint mount path ({basePath}/messages)
includeHTTP method[]Auto mode: methods to expose
excludestring[]Auto mode: route paths to skip, matched against the full path ('/admin/*' skips /api/v1/admin/…)
authMcpAuthOptionsChecked on every MCP request; 401 on failure
allowedOriginsstring[][]Browser origins allowed to call the endpoint; other Origin headers get 403
forwardHeadersstring[]authorization, cookie, x-request-id, traceparent, tracestateHeaders copied from the MCP request onto tool calls
exposeWhenRouteFlagTestRoutes carrying these route flags become tools; an object flag value supplies tool options
hideWhenRouteFlagTestRoutes carrying these route flags are never tools

@McpTool options

OptionTypeDescription
descriptionstringRequired. What the tool does, for the model
namestringTool name (default Controller.method)
inputSchemaany schemaReplace the query/body input; path parameters are still added
outputSchemaany schemaDocumentation only
examplesMcpToolExample[]Usage examples
hiddenbooleanNever expose this route, even in auto mode

Behaviour

  • Tool input combines path parameters (required) with the route's params, query and body schemas from any supported schema library.

  • Tool calls run through the app's request pipeline in-process (AdapterContext.fetch) — middleware, validation, guards and contributors apply, and no listening server is needed (createHandler() works).

  • Sessions: each client gets its own session (mcp-session-id); unknown sessions get 404.

  • Runtimes: the endpoint works on Express, Fastify, h3 and h3 v2.

  • Custom tool providers: see the guide for the interfaces and a local example.

Released under the MIT License. Built with TypeScript — runs on Express, Fastify, or h3.