Class: McpToolkit::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/mcp_toolkit/engine.rb

Overview

Mountable Rails engine that draws the MCP transport routes plus the authority introspection route (defined in the engine's config/routes.rb so they survive Rails' route reloads) against the gem-provided McpToolkit::ServerController / McpToolkit::TokensController. A satellite OR an authority mounts it in one line:

# config/routes.rb
mount McpToolkit::Engine => "/mcp"

The mounted McpToolkit::ServerController is role-aware (built lazily from config.auth_role): an authority host gets the hand-rolled dispatcher path, a satellite gets the SDK-backed one — see engine_controllers.rb. This yields exactly the endpoints a hand-rolled host declared:

POST   /mcp                     -> create     (JSON-RPC requests/responses)
GET    /mcp                     -> stream     (405; no server-initiated SSE)
DELETE /mcp                     -> destroy    (terminate the session)
GET    /mcp/health              -> health     (unauthenticated probe)
POST   /mcp/tokens/introspect   -> introspect (authority token introspection;
                                             drawn ONLY when auth_role is
                                             :authority — a satellite that
                                             mounts the engine gets no such
                                             route)

Loaded ONLY when Rails::Engine is available (see lib/mcp_toolkit.rb); the gem's non-Rails consumers and its own unit suite never reference it.