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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a031f1969028d88d34f7f19bc18777fee99067dee692ce73754bbb001477f14
|
4
|
+
data.tar.gz: 35c84b344020e97ce87d9c7e033220138732c29bd7d7cee0634e4f9c7f38cc13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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
|
-
|
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
|
-
|
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
|
data/lib/action_mcp/version.rb
CHANGED