actionmcp 0.201.3 → 0.202.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +40 -0
- data/app/controllers/action_mcp/application_controller.rb +21 -36
- data/app/jobs/action_mcp/tool_execution_job.rb +2 -16
- data/app/models/action_mcp/session.rb +1 -233
- data/lib/action_mcp/callbacks.rb +22 -115
- data/lib/action_mcp/capability.rb +44 -0
- data/lib/action_mcp/configuration.rb +26 -14
- data/lib/action_mcp/content/audio.rb +3 -21
- data/lib/action_mcp/content/base.rb +7 -0
- data/lib/action_mcp/content/binary.rb +30 -0
- data/lib/action_mcp/content/image.rb +3 -21
- data/lib/action_mcp/content/validation.rb +37 -38
- data/lib/action_mcp/content.rb +0 -33
- data/lib/action_mcp/custom_methods.rb +61 -0
- data/lib/action_mcp/dev_reloader.rb +19 -0
- data/lib/action_mcp/lifecycle_callbacks.rb +28 -0
- data/lib/action_mcp/log_subscriber.rb +15 -21
- data/lib/action_mcp/output_schema_builder.rb +18 -31
- data/lib/action_mcp/prompt.rb +8 -59
- data/lib/action_mcp/request_meta.rb +11 -0
- data/lib/action_mcp/resource_callbacks.rb +22 -149
- data/lib/action_mcp/resource_response.rb +3 -7
- data/lib/action_mcp/resource_template.rb +1 -0
- data/lib/action_mcp/server/base_session.rb +7 -173
- data/lib/action_mcp/server/handlers/dispatching.rb +38 -0
- data/lib/action_mcp/server/handlers/prompt_handler.rb +6 -12
- data/lib/action_mcp/server/handlers/resource_handler.rb +6 -23
- data/lib/action_mcp/server/handlers/task_handler.rb +14 -31
- data/lib/action_mcp/server/handlers/tool_handler.rb +4 -11
- data/lib/action_mcp/server/json_rpc_handler.rb +17 -1
- data/lib/action_mcp/server/prompts.rb +8 -17
- data/lib/action_mcp/server/resources.rb +4 -28
- data/lib/action_mcp/server/result_response.rb +19 -0
- data/lib/action_mcp/server/sampling_request.rb +26 -43
- data/lib/action_mcp/server/session_registries.rb +127 -0
- data/lib/action_mcp/server/tools.rb +5 -26
- data/lib/action_mcp/tagged_stream_logging.rb +9 -5
- data/lib/action_mcp/tool.rb +24 -60
- data/lib/action_mcp/version.rb +1 -1
- data/lib/tasks/action_mcp_tasks.rake +22 -44
- metadata +10 -3
- data/lib/action_mcp/server/handlers/router.rb +0 -33
data/lib/action_mcp/tool.rb
CHANGED
|
@@ -15,6 +15,10 @@ module ActionMCP
|
|
|
15
15
|
include ActionMCP::CurrentHelpers
|
|
16
16
|
extend ActionMCP::SchemaHelpers
|
|
17
17
|
|
|
18
|
+
# JSON Schema keywords the collection DSL places on the array itself;
|
|
19
|
+
# the rest describe each item.
|
|
20
|
+
COLLECTION_ARRAY_KEYWORDS = %i[minItems maxItems uniqueItems].freeze
|
|
21
|
+
|
|
18
22
|
# --------------------------------------------------------------------------
|
|
19
23
|
# Class Attributes for Tool Metadata and Schema
|
|
20
24
|
# --------------------------------------------------------------------------
|
|
@@ -26,7 +30,6 @@ module ActionMCP
|
|
|
26
30
|
class_attribute :_required_properties, instance_accessor: false, default: []
|
|
27
31
|
class_attribute :_annotations, instance_accessor: false, default: {}
|
|
28
32
|
class_attribute :_output_schema, instance_accessor: false, default: nil
|
|
29
|
-
class_attribute :_meta, instance_accessor: false, default: {}
|
|
30
33
|
class_attribute :_requires_consent, instance_accessor: false, default: false
|
|
31
34
|
class_attribute :_output_schema_builder, instance_accessor: false, default: nil
|
|
32
35
|
class_attribute :_additional_properties, instance_accessor: false, default: false
|
|
@@ -47,47 +50,18 @@ module ActionMCP
|
|
|
47
50
|
# @param name [String, nil] Optional. The name to set for the tool.
|
|
48
51
|
# @return [String] The current tool name.
|
|
49
52
|
def self.tool_name(name = nil)
|
|
50
|
-
|
|
51
|
-
self._capability_name = name
|
|
52
|
-
re_register_if_needed
|
|
53
|
-
name
|
|
54
|
-
else
|
|
55
|
-
_capability_name || default_tool_name
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
# Re-registers the tool if it was already registered under a different name
|
|
60
|
-
# @return [void]
|
|
61
|
-
def self.re_register_if_needed
|
|
62
|
-
return if abstract?
|
|
63
|
-
return unless _registered_name # Not yet registered
|
|
64
|
-
|
|
65
|
-
new_name = capability_name
|
|
66
|
-
return if _registered_name == new_name # No change
|
|
67
|
-
|
|
68
|
-
ActionMCP::ToolsRegistry.re_register(self, _registered_name)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
private_class_method :re_register_if_needed
|
|
72
|
-
|
|
73
|
-
# Returns a default tool name based on the class name.
|
|
74
|
-
#
|
|
75
|
-
# @return [String] The default tool name.
|
|
76
|
-
def self.default_tool_name
|
|
77
|
-
return "" if name.nil?
|
|
78
|
-
|
|
79
|
-
name.underscore.gsub("/", "__").sub(/_tool$/, "")
|
|
53
|
+
name ? assign_capability_name(name) : capability_name
|
|
80
54
|
end
|
|
81
55
|
|
|
82
56
|
class << self
|
|
83
|
-
alias default_capability_name
|
|
57
|
+
alias default_tool_name default_capability_name
|
|
84
58
|
|
|
85
59
|
def type
|
|
86
60
|
:tool
|
|
87
61
|
end
|
|
88
62
|
|
|
89
|
-
def
|
|
90
|
-
ActionMCP::ToolsRegistry
|
|
63
|
+
def registry
|
|
64
|
+
ActionMCP::ToolsRegistry
|
|
91
65
|
end
|
|
92
66
|
|
|
93
67
|
# Hook called when a class inherits from Tool
|
|
@@ -183,16 +157,6 @@ module ActionMCP
|
|
|
183
157
|
_output_schema
|
|
184
158
|
end
|
|
185
159
|
|
|
186
|
-
# Sets or retrieves the _meta field
|
|
187
|
-
def meta(data = nil)
|
|
188
|
-
if data
|
|
189
|
-
raise ArgumentError, "_meta must be a hash" unless data.is_a?(Hash)
|
|
190
|
-
|
|
191
|
-
self._meta = _meta.merge(data)
|
|
192
|
-
else
|
|
193
|
-
_meta
|
|
194
|
-
end
|
|
195
|
-
end
|
|
196
160
|
|
|
197
161
|
# Declares the UI resource this tool renders. Merges a `ui:` entry into
|
|
198
162
|
# `_meta` so the tool listing advertises the dashboard.
|
|
@@ -445,8 +409,14 @@ module ActionMCP
|
|
|
445
409
|
# @param description [String, nil] Optional description for the collection.
|
|
446
410
|
# @param required [Boolean] Whether the collection is required (default: false).
|
|
447
411
|
# @param default [Array, nil] The default value for the collection.
|
|
412
|
+
# @param opts [Hash] Additional JSON Schema keywords. Array keywords
|
|
413
|
+
# (minItems, maxItems, uniqueItems) apply to the array; every other
|
|
414
|
+
# keyword (enum, format, minimum, pattern, ...) applies to each item.
|
|
448
415
|
# @return [void]
|
|
449
|
-
|
|
416
|
+
#
|
|
417
|
+
# @example
|
|
418
|
+
# collection :fruits, type: "string", enum: %w[apple banana], minItems: 1, uniqueItems: true
|
|
419
|
+
def self.collection(prop_name, type:, description: nil, required: false, default: [], **opts)
|
|
450
420
|
raise ArgumentError, "Type is required for a collection" if type.nil?
|
|
451
421
|
|
|
452
422
|
if _property_aliases.key?(prop_name.to_s)
|
|
@@ -455,8 +425,12 @@ module ActionMCP
|
|
|
455
425
|
|
|
456
426
|
invalidate_schema_cache
|
|
457
427
|
|
|
458
|
-
|
|
428
|
+
array_opts = opts.slice(*COLLECTION_ARRAY_KEYWORDS)
|
|
429
|
+
item_opts = opts.except(*COLLECTION_ARRAY_KEYWORDS)
|
|
430
|
+
|
|
431
|
+
collection_definition = { type: "array", items: { type: type, **item_opts } }
|
|
459
432
|
collection_definition[:description] = description if description && !description.empty?
|
|
433
|
+
collection_definition.merge!(array_opts)
|
|
460
434
|
|
|
461
435
|
self._schema_properties = _schema_properties.merge(prop_name.to_s => collection_definition)
|
|
462
436
|
new_required = _required_properties.dup
|
|
@@ -600,21 +574,11 @@ module ActionMCP
|
|
|
600
574
|
@response
|
|
601
575
|
end
|
|
602
576
|
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
response_info = if defined?(@response) && @response
|
|
607
|
-
"response: #{@response.contents.size} content(s), isError: #{@response.is_error}"
|
|
608
|
-
else
|
|
609
|
-
"response: nil"
|
|
610
|
-
end
|
|
611
|
-
|
|
612
|
-
errors_info = errors.any? ? ", errors: #{errors.full_messages}" : ""
|
|
613
|
-
|
|
614
|
-
"#<#{self.class.name} #{attributes_hash.map do |k, v|
|
|
615
|
-
"#{k}: #{v.inspect}"
|
|
616
|
-
end.join(', ')}, #{response_info}#{errors_info}>"
|
|
577
|
+
# Describes the collected response for #inspect.
|
|
578
|
+
def response_summary
|
|
579
|
+
"#{@response.contents.size} content(s), isError: #{@response.is_error}"
|
|
617
580
|
end
|
|
581
|
+
private :response_summary
|
|
618
582
|
|
|
619
583
|
# Override render to collect Content objects and support structured content
|
|
620
584
|
def render(structured: nil, **args)
|
data/lib/action_mcp/version.rb
CHANGED
|
@@ -1,61 +1,43 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
namespace :action_mcp do
|
|
4
|
-
#
|
|
5
|
-
|
|
6
|
-
task list_tools: :environment do
|
|
7
|
-
# Ensure Rails eager loads all classes
|
|
4
|
+
# Prints one registry's non-abstract entries under a coloured heading.
|
|
5
|
+
print_registry = lambda do |title, color, registry, &details|
|
|
8
6
|
Rails.application.eager_load!
|
|
9
7
|
|
|
10
|
-
puts "\e[
|
|
11
|
-
puts "\e[
|
|
12
|
-
|
|
13
|
-
if
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
puts "\e[#{color}m#{title}\e[0m"
|
|
9
|
+
puts "\e[#{color}m#{'-' * (title.length - 1)}\e[0m"
|
|
10
|
+
entries = registry.non_abstract.sort_by(&:name)
|
|
11
|
+
if entries.any?
|
|
12
|
+
entries.each do |entry|
|
|
13
|
+
line = "\e[#{color}m#{entry.name}:\e[0m #{entry.description}"
|
|
14
|
+
line += " : #{details.call(entry)}" if details
|
|
15
|
+
puts line
|
|
16
16
|
end
|
|
17
17
|
else
|
|
18
|
-
puts " No
|
|
18
|
+
puts " No #{title.split.last.downcase} registered"
|
|
19
19
|
end
|
|
20
20
|
puts "\n"
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
# bin/rails action_mcp:list_tools
|
|
24
|
+
desc "List all tools with their names and descriptions"
|
|
25
|
+
task list_tools: :environment do
|
|
26
|
+
print_registry.call("ACTION MCP TOOLS", 34, ActionMCP::ToolsRegistry)
|
|
27
|
+
end
|
|
28
|
+
|
|
23
29
|
# bin/rails action_mcp:list_prompts
|
|
24
30
|
desc "List all prompts with their names and descriptions"
|
|
25
31
|
task list_prompts: :environment do
|
|
26
|
-
|
|
27
|
-
Rails.application.eager_load!
|
|
28
|
-
|
|
29
|
-
puts "\e[32mACTION MCP PROMPTS\e[0m" # Green
|
|
30
|
-
puts "\e[32m-----------------\e[0m" # Green
|
|
31
|
-
prompts = ActionMCP::PromptsRegistry.non_abstract.sort_by(&:name)
|
|
32
|
-
if prompts.any?
|
|
33
|
-
prompts.each do |prompt|
|
|
34
|
-
puts "\e[32m#{prompt.name}:\e[0m #{prompt.description}" # Green name
|
|
35
|
-
end
|
|
36
|
-
else
|
|
37
|
-
puts " No prompts registered"
|
|
38
|
-
end
|
|
39
|
-
puts "\n"
|
|
32
|
+
print_registry.call("ACTION MCP PROMPTS", 32, ActionMCP::PromptsRegistry)
|
|
40
33
|
end
|
|
41
34
|
|
|
42
35
|
# bin/rails action_mcp:list_resources
|
|
43
36
|
desc "List all resources with their names and descriptions"
|
|
44
37
|
task list_resources: :environment do
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
puts "\e[33mACTION MCP RESOURCES\e[0m" # Yellow
|
|
49
|
-
puts "\e[33m--------------------\e[0m" # Yellow
|
|
50
|
-
resources = ActionMCP::ResourceTemplatesRegistry.non_abstract.sort_by(&:name)
|
|
51
|
-
if resources.any?
|
|
52
|
-
resources.each do |resource|
|
|
53
|
-
puts "\e[33m#{resource.name}:\e[0m #{resource.description} : #{resource.klass.uri_template}" # Yellow name
|
|
54
|
-
end
|
|
55
|
-
else
|
|
56
|
-
puts " No resources registered"
|
|
38
|
+
print_registry.call("ACTION MCP RESOURCES", 33, ActionMCP::ResourceTemplatesRegistry) do |resource|
|
|
39
|
+
resource.klass.uri_template
|
|
57
40
|
end
|
|
58
|
-
puts "\n"
|
|
59
41
|
end
|
|
60
42
|
|
|
61
43
|
# bin/rails action_mcp:list_widgets
|
|
@@ -198,9 +180,7 @@ namespace :action_mcp do
|
|
|
198
180
|
# Show Capabilities
|
|
199
181
|
puts "\n\e[36mActive Capabilities:\e[0m" # Cyan
|
|
200
182
|
capabilities = ActionMCP.configuration.capabilities
|
|
201
|
-
capabilities.each
|
|
202
|
-
puts " #{cap_name}: #{cap_config.inspect}"
|
|
203
|
-
end
|
|
183
|
+
capabilities.each { |name, config| puts " #{name}: #{config.inspect}" }
|
|
204
184
|
end
|
|
205
185
|
|
|
206
186
|
puts "\n"
|
|
@@ -273,9 +253,7 @@ namespace :action_mcp do
|
|
|
273
253
|
puts "\n\e[36mEnabled Capabilities:\e[0m"
|
|
274
254
|
capabilities = config.capabilities
|
|
275
255
|
if capabilities.any?
|
|
276
|
-
capabilities.each
|
|
277
|
-
puts " #{cap_name}: #{cap_config.inspect}"
|
|
278
|
-
end
|
|
256
|
+
capabilities.each { |name, config| puts " #{name}: #{config.inspect}" }
|
|
279
257
|
else
|
|
280
258
|
puts " None"
|
|
281
259
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: actionmcp
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.202.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Abdelkader Boudih
|
|
@@ -196,6 +196,7 @@ files:
|
|
|
196
196
|
- lib/action_mcp/content.rb
|
|
197
197
|
- lib/action_mcp/content/audio.rb
|
|
198
198
|
- lib/action_mcp/content/base.rb
|
|
199
|
+
- lib/action_mcp/content/binary.rb
|
|
199
200
|
- lib/action_mcp/content/image.rb
|
|
200
201
|
- lib/action_mcp/content/resource.rb
|
|
201
202
|
- lib/action_mcp/content/resource_link.rb
|
|
@@ -203,7 +204,9 @@ files:
|
|
|
203
204
|
- lib/action_mcp/content/validation.rb
|
|
204
205
|
- lib/action_mcp/current.rb
|
|
205
206
|
- lib/action_mcp/current_helpers.rb
|
|
207
|
+
- lib/action_mcp/custom_methods.rb
|
|
206
208
|
- lib/action_mcp/dev/runner.rb
|
|
209
|
+
- lib/action_mcp/dev_reloader.rb
|
|
207
210
|
- lib/action_mcp/engine.rb
|
|
208
211
|
- lib/action_mcp/filtered_logger.rb
|
|
209
212
|
- lib/action_mcp/gateway.rb
|
|
@@ -219,6 +222,7 @@ files:
|
|
|
219
222
|
- lib/action_mcp/instrumentation/resource_instrumentation.rb
|
|
220
223
|
- lib/action_mcp/integer_array.rb
|
|
221
224
|
- lib/action_mcp/json_rpc_handler_base.rb
|
|
225
|
+
- lib/action_mcp/lifecycle_callbacks.rb
|
|
222
226
|
- lib/action_mcp/log_subscriber.rb
|
|
223
227
|
- lib/action_mcp/logging.rb
|
|
224
228
|
- lib/action_mcp/logging/level.rb
|
|
@@ -235,6 +239,7 @@ files:
|
|
|
235
239
|
- lib/action_mcp/protocol_validator.rb
|
|
236
240
|
- lib/action_mcp/registry_base.rb
|
|
237
241
|
- lib/action_mcp/renderable.rb
|
|
242
|
+
- lib/action_mcp/request_meta.rb
|
|
238
243
|
- lib/action_mcp/resource.rb
|
|
239
244
|
- lib/action_mcp/resource_callbacks.rb
|
|
240
245
|
- lib/action_mcp/resource_response.rb
|
|
@@ -254,10 +259,10 @@ files:
|
|
|
254
259
|
- lib/action_mcp/server/elicitation_request.rb
|
|
255
260
|
- lib/action_mcp/server/error_aware.rb
|
|
256
261
|
- lib/action_mcp/server/error_handling.rb
|
|
262
|
+
- lib/action_mcp/server/handlers/dispatching.rb
|
|
257
263
|
- lib/action_mcp/server/handlers/logging_handler.rb
|
|
258
264
|
- lib/action_mcp/server/handlers/prompt_handler.rb
|
|
259
265
|
- lib/action_mcp/server/handlers/resource_handler.rb
|
|
260
|
-
- lib/action_mcp/server/handlers/router.rb
|
|
261
266
|
- lib/action_mcp/server/handlers/task_handler.rb
|
|
262
267
|
- lib/action_mcp/server/handlers/tool_handler.rb
|
|
263
268
|
- lib/action_mcp/server/json_rpc_handler.rb
|
|
@@ -267,9 +272,11 @@ files:
|
|
|
267
272
|
- lib/action_mcp/server/registry_management.rb
|
|
268
273
|
- lib/action_mcp/server/resources.rb
|
|
269
274
|
- lib/action_mcp/server/response_collector.rb
|
|
275
|
+
- lib/action_mcp/server/result_response.rb
|
|
270
276
|
- lib/action_mcp/server/roots.rb
|
|
271
277
|
- lib/action_mcp/server/sampling.rb
|
|
272
278
|
- lib/action_mcp/server/sampling_request.rb
|
|
279
|
+
- lib/action_mcp/server/session_registries.rb
|
|
273
280
|
- lib/action_mcp/server/session_store.rb
|
|
274
281
|
- lib/action_mcp/server/session_store_factory.rb
|
|
275
282
|
- lib/action_mcp/server/tasks.rb
|
|
@@ -337,7 +344,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
337
344
|
- !ruby/object:Gem::Version
|
|
338
345
|
version: '0'
|
|
339
346
|
requirements: []
|
|
340
|
-
rubygems_version: 4.0.
|
|
347
|
+
rubygems_version: 4.0.20
|
|
341
348
|
specification_version: 4
|
|
342
349
|
summary: Lightweight Model Context Protocol (MCP) server toolkit for Ruby/Rails
|
|
343
350
|
test_files: []
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActionMCP
|
|
4
|
-
module Server
|
|
5
|
-
module Handlers
|
|
6
|
-
class Router
|
|
7
|
-
def initialize(handler)
|
|
8
|
-
@handler = handler
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def route(rpc_method, id, params)
|
|
12
|
-
case rpc_method
|
|
13
|
-
when "initialize"
|
|
14
|
-
@handler.handle_initialize(id, params)
|
|
15
|
-
when %r{^prompts/}
|
|
16
|
-
@handler.process_prompts(rpc_method, id, params)
|
|
17
|
-
when %r{^resources/}
|
|
18
|
-
@handler.process_resources(rpc_method, id, params)
|
|
19
|
-
when %r{^tools/}
|
|
20
|
-
@handler.process_tools(rpc_method, id, params)
|
|
21
|
-
when %r{^tasks/}
|
|
22
|
-
@handler.process_tasks(rpc_method, id, params)
|
|
23
|
-
when "completion/complete"
|
|
24
|
-
@handler.process_completion_complete(id, params)
|
|
25
|
-
else
|
|
26
|
-
raise ActionMCP::Server::JSON_RPC::JsonRpcError.new(:method_not_found,
|
|
27
|
-
message: "Method not found: #{rpc_method}")
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|