actionmcp 0.7.2 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bea2e23118051ba1a05eb00dfb44395841068fe6358b341e01a1951f7064a259
4
- data.tar.gz: e1ff02d641a4684c0369fa252139edeb8bf1dae41193deeca122832bcb0ac318
3
+ metadata.gz: 7a031f1969028d88d34f7f19bc18777fee99067dee692ce73754bbb001477f14
4
+ data.tar.gz: 35c84b344020e97ce87d9c7e033220138732c29bd7d7cee0634e4f9c7f38cc13
5
5
  SHA512:
6
- metadata.gz: '097b59b77ef2028887ef159f211a314a9a9fa83edb7ff26f50d62fc56a834bf5df96e7781c5cd715d511ee957736f242971f76baac3d8b1fffd213f6373afe5c'
7
- data.tar.gz: 13582b839164819da648df7e319df9e8aac565f2792bee75c44d23d1fd7af531e01d6c7a8e82f63d46fc9cd68f7d42fe10622748202a6ca10dc99ff332d8d7a5
6
+ metadata.gz: 953dd645cb4006c027ca2643aa8274a5011db73910159f4a0a3d5c60e80df82deae14f37ec41de869e863e7b4a8e1440579863bc33daa21185dc169abc4ddcbe
7
+ data.tar.gz: 22f1e9622b4330afb13bc1fd943142904f8fcbd07df734e571707c428b2d11c343775900221a33a74df354cae4a47fa36bd13e97d3809aa930b4ad2af40b66b5
@@ -21,6 +21,9 @@ module ActionMCP
21
21
  end
22
22
 
23
23
  def handle_post_message(params, response)
24
+ if params[:method] == "initialize"
25
+ mcp_session.initialize!
26
+ end
24
27
  json_rpc_handler.call(params)
25
28
 
26
29
  response.status = :accepted
@@ -31,7 +34,7 @@ module ActionMCP
31
34
  end
32
35
 
33
36
  def mcp_session
34
- Session.find(params[:session_id])
37
+ @mcp_session ||= Session.find_or_create_by(id: params[:session_id])
35
38
  end
36
39
 
37
40
  def clean_params
@@ -20,12 +20,21 @@ module ActionMCP
20
20
 
21
21
  # Start listener and process messages via the transport
22
22
  listener = SSEListener.new(mcp_session)
23
+ message_received = false
23
24
  if listener.start do |message|
24
25
  # Send with proper SSE formatting
25
26
  sse.write(message)
27
+ message_received = true
28
+ end
29
+ sleep 1
30
+ # Heartbeat loop
31
+ unless message_received
32
+ Rails.logger.warn "No message received within 1 second, closing connection for session: #{session_id}"
33
+ error = JsonRpc::Response.new(id: SecureRandom.uuid_v7, error: JsonRpc::JsonRpcError.new(:server_error, message: "No message received within 1 second").to_h).to_h
34
+ sse.write(error)
35
+ return
26
36
  end
27
37
 
28
- # Heartbeat loop
29
38
  until response.stream.closed?
30
39
  sleep HEARTBEAT_INTERVAL
31
40
  # mcp_session.send_ping!
@@ -39,8 +48,8 @@ module ActionMCP
39
48
  rescue => e
40
49
  Rails.logger.error "SSE: Unexpected error: #{e.class} - #{e.message}\n#{e.backtrace.join("\n")}"
41
50
  ensure
42
- listener.stop
43
51
  response.stream.close
52
+ listener.stop
44
53
  Rails.logger.debug "SSE: Connection closed for session: #{session_id}"
45
54
  end
46
55
  end
@@ -59,12 +68,16 @@ module ActionMCP
59
68
  end
60
69
 
61
70
  def mcp_session
62
- @mcp_session ||= Session.create
71
+ @mcp_session ||= Session.new
63
72
  end
64
73
 
65
74
  def session_id
66
75
  @session_id ||= mcp_session.id
67
76
  end
77
+
78
+ def cache_key
79
+ "action_mcp:session:#{session_id}"
80
+ end
68
81
  end
69
82
 
70
83
  class SSEListener
@@ -100,7 +113,7 @@ module ActionMCP
100
113
  }
101
114
 
102
115
  # Subscribe using the ActionCable adapter
103
- success = adapter.subscribe(session_key, message_callback, success_callback)
116
+ adapter.subscribe(session_key, message_callback, success_callback)
104
117
 
105
118
  # Give some time for the subscription to be established
106
119
  sleep 0.5
@@ -110,8 +123,9 @@ module ActionMCP
110
123
 
111
124
  def stop
112
125
  @stopped = true
113
-
114
- @session.close!
126
+ if (mcp_session = Session.find_by(id: session_key))
127
+ mcp_session.close
128
+ end
115
129
  Rails.logger.debug "Unsubscribed from: #{session_key}"
116
130
  end
117
131
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative "gem_version"
4
4
  module ActionMCP
5
- VERSION = "0.7.2"
5
+ VERSION = "0.8.0"
6
6
 
7
7
  class << self
8
8
  alias version gem_version
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.7.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih