Module: AdminSuite::Mcp
- Defined in:
- lib/admin_suite/mcp.rb,
lib/admin_suite/mcp/serializer.rb,
lib/admin_suite/mcp/authorization.rb,
lib/admin_suite/mcp/tools/aggregate.rb,
lib/admin_suite/mcp/tools/get_record.rb,
lib/admin_suite/mcp/tools/list_records.rb,
lib/admin_suite/mcp/tools/describe_resources.rb
Defined Under Namespace
Modules: Authorization, Serializer, Tools
Constant Summary collapse
- TOOLS =
[ AdminSuite::Mcp::Tools::DescribeResources, AdminSuite::Mcp::Tools::ListRecords, AdminSuite::Mcp::Tools::GetRecord, AdminSuite::Mcp::Tools::Aggregate ].freeze
Class Method Summary collapse
- .instrument(tool:, resource: nil, actor: nil, action: :read, request: nil, filters: nil, q: nil) ⇒ Object
-
.server_for(actor:, request: nil) ⇒ Object
A fresh server is built for each request, so its advertised tool list is derived from the current fail-closed authorization posture rather than cached across actors or requests.
Class Method Details
.instrument(tool:, resource: nil, actor: nil, action: :read, request: nil, filters: nil, q: nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/admin_suite/mcp.rb', line 26 def self.instrument(tool:, resource: nil, actor: nil, action: :read, request: nil, filters: nil, q: nil) payload = { tool: tool, resource: resource, actor_type: actor&.class&.name, actor_id: actor.respond_to?(:id) ? actor.id.to_s : nil, request_id: request&.request_id, action: action, filters: filters, q: q, allowed: false, error: true, result_count: nil } started = Process.clock_gettime(Process::CLOCK_MONOTONIC) ActiveSupport::Notifications.instrument("admin_suite.mcp.tool_call", payload) do response, count, allowed = yield payload[:allowed] = allowed payload[:result_count] = count payload[:error] = response.error? response ensure payload[:duration_ms] = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - started) * 1000).round(2) end end |
.server_for(actor:, request: nil) ⇒ Object
A fresh server is built for each request, so its advertised tool list is derived from the current fail-closed authorization posture rather than cached across actors or requests.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/admin_suite/mcp.rb', line 15 def self.server_for(actor:, request: nil) tools = AdminSuite.config..nil? || Auth.normalize_actor(actor).nil? ? [] : TOOLS ::MCP::Server.new( name: "admin_suite", version: AdminSuite::VERSION, tools: tools, server_context: { actor: actor, request: request } ) end |