Class: McpToolkit::Authority::Tools::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mcp_toolkit/authority/tools/base.rb

Overview

Shared base for the four GENERIC, Registry-backed authority tools (McpToolkit::Authority::Tools::Resources,ResourceSchema,Get,List) served through McpToolkit::Authority::RegistryToolProvider on the hand-rolled authority dispatch path.

Unlike the satellite tools (McpToolkit::Tools::*, which subclass the SDK's MCP::Tool, self-authenticate, and return an MCP::Tool::Response), these are plain objects satisfying the dispatcher's duck-typed tool contract:

tool.required_permissions_scope  -> nil   (see below — no STATIC scope)
tool.call(context:, **arguments) -> Hash  (the dispatcher wraps it into
                                         { content: [{ type: "text", ... }] })

The scope a caller needs is DYNAMIC — it depends on which resource argument was passed — so these tools declare no static scope and instead enforce the resolved resource's required_scope_for INSIDE #call (see #ensure_scope!). The context (McpToolkit::Authority::Context) supplies the resolved account, the principal, and the derived superuser flag.

The tools reuse the existing executors / schema builder UNCHANGED; this base only holds the resolution + gating every one of them repeats: resolve the resource descriptor, gate a superuser-only resource, gate the per-resource scope, and (for get/list) require a selected account.

Direct Known Subclasses

Get, List, ResourceSchema, Resources

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config:) ⇒ Base

Returns a new instance of Base.



54
55
56
# File 'lib/mcp_toolkit/authority/tools/base.rb', line 54

def initialize(config:)
  @config = config
end

Class Attribute Details

._descriptionObject (readonly)

Returns the value of attribute _description.



28
29
30
# File 'lib/mcp_toolkit/authority/tools/base.rb', line 28

def _description
  @_description
end

._input_schemaObject (readonly)

Returns the value of attribute _input_schema.



28
29
30
# File 'lib/mcp_toolkit/authority/tools/base.rb', line 28

def _input_schema
  @_input_schema
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



52
53
54
# File 'lib/mcp_toolkit/authority/tools/base.rb', line 52

def config
  @config
end

Class Method Details

.definitionObject

The static tool definition returned by the provider's tool_definitions (part of tools/list). Generic and context-independent.



47
48
49
# File 'lib/mcp_toolkit/authority/tools/base.rb', line 47

def definition
  { name: tool_name, description: _description, inputSchema: input_schema }
end

.description(text = nil) ⇒ Object



35
36
37
38
# File 'lib/mcp_toolkit/authority/tools/base.rb', line 35

def description(text = nil)
  @_description = text if text
  @_description
end

.input_schema(schema = nil) ⇒ Object



40
41
42
43
# File 'lib/mcp_toolkit/authority/tools/base.rb', line 40

def input_schema(schema = nil)
  @_input_schema = schema if schema
  @_input_schema || { type: "object", properties: {} }
end

.tool_name(name = nil) ⇒ Object



30
31
32
33
# File 'lib/mcp_toolkit/authority/tools/base.rb', line 30

def tool_name(name = nil)
  @_tool_name = name.to_s if name
  @_tool_name
end

Instance Method Details

#required_permissions_scopeObject

The dispatcher's central scope gate reads this; nil = no STATIC scope. The real, per-resource scope is enforced dynamically in #ensure_scope! (the scope depends on the resource argument, unknown until #call).



61
62
63
# File 'lib/mcp_toolkit/authority/tools/base.rb', line 61

def required_permissions_scope
  nil
end