actionmcp 0.102.0 → 0.104.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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +46 -3
  3. data/app/models/action_mcp/session.rb +6 -5
  4. data/lib/action_mcp/configuration.rb +44 -8
  5. data/lib/action_mcp/server/base_session.rb +5 -1
  6. data/lib/action_mcp/test_helper/session_store_assertions.rb +0 -70
  7. data/lib/action_mcp/version.rb +1 -1
  8. data/lib/action_mcp.rb +0 -1
  9. data/lib/generators/action_mcp/identifier/templates/identifier.rb.erb +4 -4
  10. data/lib/generators/action_mcp/install/templates/mcp.yml +11 -1
  11. data/lib/generators/action_mcp/tool/templates/tool.rb.erb +2 -2
  12. metadata +1 -26
  13. data/lib/action_mcp/client/active_record_session_store.rb +0 -57
  14. data/lib/action_mcp/client/base.rb +0 -225
  15. data/lib/action_mcp/client/blueprint.rb +0 -163
  16. data/lib/action_mcp/client/catalog.rb +0 -164
  17. data/lib/action_mcp/client/collection.rb +0 -168
  18. data/lib/action_mcp/client/elicitation.rb +0 -34
  19. data/lib/action_mcp/client/json_rpc_handler.rb +0 -202
  20. data/lib/action_mcp/client/logging.rb +0 -19
  21. data/lib/action_mcp/client/messaging.rb +0 -28
  22. data/lib/action_mcp/client/prompt_book.rb +0 -117
  23. data/lib/action_mcp/client/prompts.rb +0 -47
  24. data/lib/action_mcp/client/request_timeouts.rb +0 -74
  25. data/lib/action_mcp/client/resources.rb +0 -100
  26. data/lib/action_mcp/client/roots.rb +0 -13
  27. data/lib/action_mcp/client/server.rb +0 -60
  28. data/lib/action_mcp/client/session_store.rb +0 -39
  29. data/lib/action_mcp/client/session_store_factory.rb +0 -27
  30. data/lib/action_mcp/client/streamable_client.rb +0 -264
  31. data/lib/action_mcp/client/streamable_http_transport.rb +0 -306
  32. data/lib/action_mcp/client/test_session_store.rb +0 -84
  33. data/lib/action_mcp/client/toolbox.rb +0 -199
  34. data/lib/action_mcp/client/tools.rb +0 -47
  35. data/lib/action_mcp/client/transport.rb +0 -137
  36. data/lib/action_mcp/client/volatile_session_store.rb +0 -38
  37. data/lib/action_mcp/client.rb +0 -71
@@ -1,137 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActionMCP
4
- module Client
5
- # Base transport interface for MCP client connections
6
- module Transport
7
- # Called when transport should establish connection
8
- def connect
9
- raise NotImplementedError, "#{self.class} must implement #connect"
10
- end
11
-
12
- # Called when transport should close connection
13
- def disconnect
14
- raise NotImplementedError, "#{self.class} must implement #disconnect"
15
- end
16
-
17
- # Send a message through the transport
18
- def send_message(message)
19
- raise NotImplementedError, "#{self.class} must implement #send_message"
20
- end
21
-
22
- # Check if transport is ready to send/receive
23
- def ready?
24
- raise NotImplementedError, "#{self.class} must implement #ready?"
25
- end
26
-
27
- # Check if transport is connected
28
- def connected?
29
- raise NotImplementedError, "#{self.class} must implement #connected?"
30
- end
31
-
32
- # Set callback for received messages
33
- def on_message(&block)
34
- @message_callback = block
35
- end
36
-
37
- # Set callback for errors
38
- def on_error(&block)
39
- @error_callback = block
40
- end
41
-
42
- # Set callback for connection events
43
- def on_connect(&block)
44
- @connect_callback = block
45
- end
46
-
47
- # Set callback for disconnection events
48
- def on_disconnect(&block)
49
- @disconnect_callback = block
50
- end
51
-
52
- protected
53
-
54
- def handle_message(message)
55
- @message_callback&.call(message)
56
- end
57
-
58
- def handle_error(error)
59
- @error_callback&.call(error)
60
- end
61
-
62
- def handle_connect
63
- @connect_callback&.call
64
- end
65
-
66
- def handle_disconnect
67
- @disconnect_callback&.call
68
- end
69
- end
70
-
71
- # Base class for transport implementations
72
- class TransportBase
73
- include Transport
74
-
75
- attr_reader :url, :options, :session_store
76
-
77
- def initialize(url, session_store:, logger: ActionMCP.logger, **options)
78
- @url = url
79
- @session_store = session_store
80
- @logger = logger
81
- @options = options
82
- @connected = false
83
- @ready = false
84
- end
85
-
86
- def connected?
87
- @connected
88
- end
89
-
90
- def ready?
91
- @ready
92
- end
93
-
94
- protected
95
-
96
- def set_connected(state)
97
- @connected = state
98
- state ? handle_connect : handle_disconnect
99
- end
100
-
101
- def set_ready(state)
102
- @ready = state
103
- end
104
-
105
- # Logging methods for transport classes
106
- def log_debug(message)
107
- @logger.debug("[ActionMCP::#{self.class.name.split('::').last}] #{message}")
108
- end
109
-
110
- def log_info(message)
111
- @logger.info("[ActionMCP::#{self.class.name.split('::').last}] #{message}")
112
- end
113
-
114
- def log_error(message)
115
- @logger.error("[ActionMCP::#{self.class.name.split('::').last}] #{message}")
116
- end
117
-
118
- private
119
-
120
- def handle_connect
121
- @connect_callback&.call
122
- end
123
-
124
- def handle_disconnect
125
- @disconnect_callback&.call
126
- end
127
-
128
- def handle_error(error)
129
- @error_callback&.call(error)
130
- end
131
-
132
- def handle_message(message)
133
- @message_callback&.call(message)
134
- end
135
- end
136
- end
137
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActionMCP
4
- module Client
5
- # Volatile session store for development (data lost on restart)
6
- class VolatileSessionStore
7
- include SessionStore
8
-
9
- def initialize
10
- @sessions = Concurrent::Hash.new
11
- end
12
-
13
- def load_session(session_id)
14
- @sessions[session_id]
15
- end
16
-
17
- def save_session(session_id, session_data)
18
- @sessions[session_id] = session_data.dup
19
- end
20
-
21
- def delete_session(session_id)
22
- @sessions.delete(session_id)
23
- end
24
-
25
- def session_exists?(session_id)
26
- @sessions.key?(session_id)
27
- end
28
-
29
- def clear_all
30
- @sessions.clear
31
- end
32
-
33
- def session_count
34
- @sessions.size
35
- end
36
- end
37
- end
38
- end
@@ -1,71 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "client/transport"
4
- require_relative "client/session_store"
5
- require_relative "client/streamable_http_transport"
6
-
7
- module ActionMCP
8
- # Creates a client appropriate for the given endpoint.
9
- #
10
- # @param endpoint [String] The endpoint to connect to (URL).
11
- # @param transport [Symbol] The transport type to use (:streamable_http, :sse for legacy)
12
- # @param session_store [Symbol] The session store type (:memory, :active_record)
13
- # @param session_id [String] Optional session ID for resuming connections
14
- # @param protocol_version [String] The MCP protocol version to use (defaults to ActionMCP::DEFAULT_PROTOCOL_VERSION)
15
- # @param logger [Logger] The logger to use. Default is Logger.new($stdout).
16
- # @param options [Hash] Additional options to pass to the client constructor.
17
- #
18
- # @return [Client::Base] An instance of the appropriate client.
19
- #
20
- # @example Basic usage
21
- # client = ActionMCP.create_client("http://127.0.0.1:3001/action_mcp")
22
- # client.connect
23
- #
24
- # @example With specific transport and session store
25
- # client = ActionMCP.create_client(
26
- # "http://127.0.0.1:3001/action_mcp",
27
- # transport: :streamable_http,
28
- # session_store: :active_record,
29
- # session_id: "existing-session-123"
30
- # )
31
- #
32
- # @example Memory-based for development
33
- # client = ActionMCP.create_client(
34
- # "http://127.0.0.1:3001/action_mcp",
35
- # session_store: :memory
36
- # )
37
- #
38
- def self.create_client(endpoint, transport: :streamable_http, session_store: nil, session_id: nil,
39
- protocol_version: nil, logger: Logger.new($stdout), **options)
40
- unless endpoint =~ %r{\Ahttps?://}
41
- raise ArgumentError, "Only HTTP(S) endpoints are supported. STDIO and other transports are not supported."
42
- end
43
-
44
- # Create session store
45
- store = Client::SessionStoreFactory.create(session_store, **options)
46
-
47
- # Create transport
48
- transport_instance = create_transport(transport, endpoint, session_store: store, session_id: session_id,
49
- protocol_version: protocol_version, logger: logger, **options)
50
-
51
- logger.info("Creating #{transport} client for endpoint: #{endpoint}")
52
- # Pass session_id and protocol_version to the client
53
- Client::Base.new(transport: transport_instance, logger: logger, session_id: session_id,
54
- protocol_version: protocol_version, **options)
55
- end
56
-
57
- private_class_method def self.create_transport(type, endpoint, **options)
58
- case type.to_sym
59
- when :streamable_http
60
- Client::StreamableHttpTransport.new(endpoint, **options)
61
- when :sse
62
- # Legacy SSE transport (wrapped for compatibility)
63
- Client::StreamableClient.new(endpoint, **options)
64
- else
65
- raise ArgumentError, "Unknown transport type: #{type}"
66
- end
67
- end
68
-
69
- module Client
70
- end
71
- end