actionmcp 0.2.0 → 0.2.4
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 +133 -30
- data/Rakefile +0 -2
- data/app/controllers/action_mcp/application_controller.rb +13 -0
- data/app/controllers/action_mcp/messages_controller.rb +51 -0
- data/app/controllers/action_mcp/sse_controller.rb +151 -0
- data/config/routes.rb +4 -0
- data/exe/actionmcp_cli +221 -0
- data/lib/action_mcp/capability.rb +52 -0
- data/lib/action_mcp/client.rb +243 -1
- data/lib/action_mcp/configuration.rb +50 -1
- data/lib/action_mcp/content/audio.rb +9 -0
- data/lib/action_mcp/content/image.rb +9 -0
- data/lib/action_mcp/content/resource.rb +13 -0
- data/lib/action_mcp/content/text.rb +7 -0
- data/lib/action_mcp/content.rb +11 -6
- data/lib/action_mcp/engine.rb +34 -0
- data/lib/action_mcp/gem_version.rb +2 -2
- data/lib/action_mcp/integer_array.rb +6 -0
- data/lib/action_mcp/json_rpc/json_rpc_error.rb +21 -0
- data/lib/action_mcp/json_rpc/notification.rb +8 -0
- data/lib/action_mcp/json_rpc/request.rb +14 -0
- data/lib/action_mcp/json_rpc/response.rb +32 -1
- data/lib/action_mcp/json_rpc.rb +1 -6
- data/lib/action_mcp/json_rpc_handler.rb +106 -0
- data/lib/action_mcp/logging.rb +19 -0
- data/lib/action_mcp/prompt.rb +30 -46
- data/lib/action_mcp/prompts_registry.rb +13 -1
- data/lib/action_mcp/registry_base.rb +47 -28
- data/lib/action_mcp/renderable.rb +26 -0
- data/lib/action_mcp/resource.rb +3 -1
- data/lib/action_mcp/server.rb +4 -1
- data/lib/action_mcp/string_array.rb +5 -0
- data/lib/action_mcp/tool.rb +16 -53
- data/lib/action_mcp/tools_registry.rb +14 -1
- data/lib/action_mcp/transport/capabilities.rb +21 -0
- data/lib/action_mcp/transport/messaging.rb +20 -0
- data/lib/action_mcp/transport/prompts.rb +19 -0
- data/lib/action_mcp/transport/sse_client.rb +309 -0
- data/lib/action_mcp/transport/stdio_client.rb +117 -0
- data/lib/action_mcp/transport/tools.rb +20 -0
- data/lib/action_mcp/transport/transport_base.rb +125 -0
- data/lib/action_mcp/transport.rb +1 -235
- data/lib/action_mcp/transport_handler.rb +54 -0
- data/lib/action_mcp/version.rb +4 -5
- data/lib/action_mcp.rb +36 -33
- data/lib/generators/action_mcp/prompt/templates/prompt.rb.erb +3 -1
- data/lib/generators/action_mcp/tool/templates/tool.rb.erb +5 -1
- data/lib/tasks/action_mcp_tasks.rake +28 -5
- metadata +66 -9
- data/exe/action_mcp_stdio +0 -0
- data/lib/action_mcp/railtie.rb +0 -27
- data/lib/action_mcp/resources_bank.rb +0 -94
@@ -1,94 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActionMCP
|
4
|
-
module ResourcesBank
|
5
|
-
@resources = {} # { uri => content_object }
|
6
|
-
@templates = {} # { uri => template_object }
|
7
|
-
@watchers = {} # { source_uri => watcher }
|
8
|
-
|
9
|
-
class << self
|
10
|
-
# Basic resource registration.
|
11
|
-
def register_resource(uri, content)
|
12
|
-
@resources[uri] = content
|
13
|
-
end
|
14
|
-
|
15
|
-
def all_resources
|
16
|
-
@resources.values
|
17
|
-
end
|
18
|
-
|
19
|
-
def read(uri)
|
20
|
-
@resources[uri]
|
21
|
-
end
|
22
|
-
|
23
|
-
def register_template(uri, template)
|
24
|
-
@templates[uri] = template
|
25
|
-
end
|
26
|
-
|
27
|
-
def all_templates
|
28
|
-
@templates.values
|
29
|
-
end
|
30
|
-
|
31
|
-
# Registers a source (file or directory) for resources.
|
32
|
-
#
|
33
|
-
# @param source_uri [String] An identifier for this source.
|
34
|
-
# @param path [String] Filesystem path to the source.
|
35
|
-
# @param watch [Boolean] Whether to watch the source for changes.
|
36
|
-
def register_source(source_uri, path, watch: false)
|
37
|
-
reload_source(source_uri, path) # Initial load
|
38
|
-
|
39
|
-
return unless watch
|
40
|
-
|
41
|
-
require "active_support/evented_file_update_checker"
|
42
|
-
# Watch all files under the given path (recursive)
|
43
|
-
file_paths = Dir.glob("#{path}/**/*")
|
44
|
-
watcher = ActiveSupport::EventedFileUpdateChecker.new(file_paths) do |modified, added, removed|
|
45
|
-
Rails.logger.info("Files changed in #{path} - Modified: #{modified.inspect}, Added: #{added.inspect}, Removed: #{removed.inspect}")
|
46
|
-
# Reload resources for this source when changes occur.
|
47
|
-
reload_source(source_uri, path)
|
48
|
-
end
|
49
|
-
@watchers[source_uri] = { path: path, watcher: watcher }
|
50
|
-
end
|
51
|
-
|
52
|
-
# Unregisters a source and stops watching it.
|
53
|
-
#
|
54
|
-
# @param source_uri [String] The identifier for the source.
|
55
|
-
def unregister_source(source_uri)
|
56
|
-
@watchers.delete(source_uri)
|
57
|
-
# Optionally, remove any resources associated with this source.
|
58
|
-
@resources.reject! { |uri, _| uri.start_with?("#{source_uri}://") }
|
59
|
-
end
|
60
|
-
|
61
|
-
# Reloads (or loads) all resources from the given directory.
|
62
|
-
#
|
63
|
-
# @param source_uri [String] The identifier for the source.
|
64
|
-
# @param path [String] Filesystem path to the source.
|
65
|
-
def reload_source(source_uri, path)
|
66
|
-
Rails.logger.info("Reloading resources from #{path} for #{source_uri}")
|
67
|
-
Dir.glob("#{path}/**/*").each do |file|
|
68
|
-
next unless File.file?(file)
|
69
|
-
|
70
|
-
# Create a resource URI from the source and file path.
|
71
|
-
relative_path = file.sub(%r{\A#{Regexp.escape(path)}/?}, "")
|
72
|
-
resource_uri = "#{source_uri}://#{relative_path}"
|
73
|
-
# For this example, we assume text files.
|
74
|
-
begin
|
75
|
-
text = File.read(file)
|
76
|
-
content = ActionMCP::Content::Text.new(text)
|
77
|
-
register_resource(resource_uri, content)
|
78
|
-
Rails.logger.info("Registered resource: #{resource_uri}")
|
79
|
-
rescue StandardError => e
|
80
|
-
Rails.logger.error("Error reading file #{file}: #{e.message}")
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# This method should be called periodically (e.g. via a background thread)
|
86
|
-
# to check if any watched files have changed.
|
87
|
-
def run_watchers
|
88
|
-
@watchers.each_value do |data|
|
89
|
-
data[:watcher].execute_if_updated
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|