Class: McpToolkit::Authority::Tools::Base
- Inherits:
-
Object
- Object
- McpToolkit::Authority::Tools::Base
- 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
Class Attribute Summary collapse
-
._description ⇒ Object
readonly
Returns the value of attribute _description.
-
._input_schema ⇒ Object
readonly
Returns the value of attribute _input_schema.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
-
.definition(name_prefix: "", config: nil) ⇒ Object
The static tool definition returned by the provider's
tool_definitions(part oftools/list). - .description(text = nil) ⇒ Object
-
.description_text(_config) ⇒ Object
Hook for a tool whose description depends on host configuration (Tools::List swaps its bare-value grammar per config.bare_filter_value_semantics).
- .input_schema(schema = nil) ⇒ Object
- .tool_name(name = nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(config:) ⇒ Base
constructor
A new instance of Base.
-
#required_permissions_scope ⇒ Object
The dispatcher's central scope gate reads this; nil = no STATIC scope.
Constructor Details
#initialize(config:) ⇒ Base
Returns a new instance of Base.
71 72 73 |
# File 'lib/mcp_toolkit/authority/tools/base.rb', line 71 def initialize(config:) @config = config end |
Class Attribute Details
._description ⇒ Object (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_schema ⇒ Object (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
#config ⇒ Object (readonly)
Returns the value of attribute config.
69 70 71 |
# File 'lib/mcp_toolkit/authority/tools/base.rb', line 69 def config @config end |
Class Method Details
.definition(name_prefix: "", config: nil) ⇒ Object
The static tool definition returned by the provider's tool_definitions
(part of tools/list). Generic and context-independent. name_prefix is
the host's config.generic_tool_name_prefix: it prefixes the advertised
name AND is threaded through every sibling-tool reference in the
description / input schema (see McpToolkit::ToolReferenceRewriter).
config lets a tool adapt its prose to host configuration (see
.description_text) — served docs must describe the behavior the host
actually configured.
53 54 55 56 57 58 59 |
# File 'lib/mcp_toolkit/authority/tools/base.rb', line 53 def definition(name_prefix: "", config: nil) { name: "#{name_prefix}#{tool_name}", description: McpToolkit::ToolReferenceRewriter.rewrite(description_text(config), name_prefix), inputSchema: McpToolkit::ToolReferenceRewriter.rewrite(input_schema, name_prefix) } 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 |
.description_text(_config) ⇒ Object
Hook for a tool whose description depends on host configuration (Tools::List swaps its bare-value grammar per config.bare_filter_value_semantics). Default: the static description.
64 65 66 |
# File 'lib/mcp_toolkit/authority/tools/base.rb', line 64 def description_text(_config) _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_scope ⇒ Object
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).
78 79 80 |
# File 'lib/mcp_toolkit/authority/tools/base.rb', line 78 def nil end |