Module: ActionModelContext::Server

Extended by:
ActiveSupport::Concern
Defined in:
lib/action_model_context/server.rb

Overview

Controller concern that serves MCP over the SDK's Streamable HTTP transport, stateless with JSON responses. It discovers the primitives through ApplicationTool, ApplicationResource and ApplicationPrompt.

Examples:

class McpController < ApplicationController
  include ActionModelContext::Server
  before_action :authenticate_user!

  private

  def mcp_context = { user: current_user }
end

Instance Method Summary collapse

Instance Method Details

#mcp_access_token ⇒ MCP::Server::OAuth::AccessToken?

Gives the token verified through config.action_model_context.oauth.token_verifier.

Returns:

  • (MCP::Server::OAuth::AccessToken, nil) —

    nil when no token was verified

#mcp_context ⇒ Object

Gives every primitive its context for the request: override this private method in the controller.

Returns:

  • (Object) —

    an empty hash by default

#mcp_server_options ⇒ Hash

Gives the keyword arguments of MCP::Server.new: override this private method in the controller.

Returns:

  • (Hash) —

    the underscored module name of the app as name: by default

#mcp_transport_options ⇒ Hash

Gives the keyword arguments of MCP::Server::Transports::StreamableHTTPTransport.new: override this private method in the controller. stateless, enable_json_response and serve_subscriptions_listen stay pinned.

Returns:

  • (Hash) —

    empty by default

#request_mcp_authentication ⇒ void

This method returns an undefined value.

Answers the SDK's 401 challenge. Call this private method when the app itself rejects a request.

Examples:

before_action { request_mcp_authentication unless user_signed_in? }