Class: ActionAgent::Api::McpController

Inherits:
BaseController show all
Defined in:
app/controllers/action_agent/api/mcp_controller.rb

Overview

Exposes the dashboard's agents as an authenticated MCP (Model Context Protocol) service over Streamable HTTP JSON-RPC — agents present themselves as Resource Agents backed by their ActiveRecord state:

  • tools/list & tools/call: each agent is a callable tool (run_) that executes a synchronous generation run.
  • resources/list & resources/read: each agent is an agent:// resource whose content is its live scorecard (config + stats + memory summary from the solid_agent datasets).

Authentication/authorization: Bearer (Settings -> API Keys). The key scopes everything to its account — its members' agents and its run quotas.

Connect from an MCP client with:

{ "type": "http", "url": "https://activeagents.ai/mcp",
"headers": { "Authorization": "Bearer aa_..." } }

Defined Under Namespace

Classes: McpError

Constant Summary collapse

PROTOCOL_VERSION =
"2025-03-26"
JSONRPC_METHOD_NOT_FOUND =
-32601
JSONRPC_INVALID_PARAMS =
-32602
JSONRPC_SERVER_ERROR =
-32000

Instance Method Summary collapse

Methods inherited from ActionAgent::ApplicationController

allow_unauthenticated_access

Instance Method Details

#createObject

POST /mcp



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/action_agent/api/mcp_controller.rb', line 33

def create
  request_id = params[:id]

  # JSON-RPC notifications get no response body.
  return head :accepted if request_id.nil? && params[:method].to_s.start_with?("notifications/")

  result = case params[:method]
  when "initialize" then initialize_result
  when "ping" then {}
  when "tools/list" then tools_list
  when "tools/call" then tools_call
  when "resources/list" then resources_list
  when "resources/read" then resources_read
  else
    return render_error(request_id, JSONRPC_METHOD_NOT_FOUND, "Method not found: #{params[:method]}")
  end

  render json: { jsonrpc: "2.0", id: request_id, result: result }
rescue McpError => e
  render_error(request_id, e.code, e.message)
rescue StandardError => e
  Rails.logger.error("[Api::McpController] #{e.class}: #{e.message}")
  render_error(request_id, JSONRPC_SERVER_ERROR, "Internal error")
end