actionmcp 0.201.3 → 0.203.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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +51 -0
  3. data/app/controllers/action_mcp/application_controller.rb +21 -36
  4. data/app/jobs/action_mcp/tool_execution_job.rb +57 -27
  5. data/app/models/action_mcp/session/task.rb +2 -1
  6. data/app/models/action_mcp/session.rb +1 -233
  7. data/lib/action_mcp/callbacks.rb +22 -115
  8. data/lib/action_mcp/capability.rb +44 -0
  9. data/lib/action_mcp/configuration.rb +26 -14
  10. data/lib/action_mcp/content/audio.rb +3 -21
  11. data/lib/action_mcp/content/base.rb +7 -0
  12. data/lib/action_mcp/content/binary.rb +30 -0
  13. data/lib/action_mcp/content/image.rb +3 -21
  14. data/lib/action_mcp/content/validation.rb +37 -38
  15. data/lib/action_mcp/content.rb +0 -33
  16. data/lib/action_mcp/custom_methods.rb +61 -0
  17. data/lib/action_mcp/dev_reloader.rb +19 -0
  18. data/lib/action_mcp/lifecycle_callbacks.rb +28 -0
  19. data/lib/action_mcp/log_subscriber.rb +15 -21
  20. data/lib/action_mcp/output_schema_builder.rb +18 -31
  21. data/lib/action_mcp/prompt.rb +8 -59
  22. data/lib/action_mcp/request_meta.rb +11 -0
  23. data/lib/action_mcp/resource_callbacks.rb +22 -149
  24. data/lib/action_mcp/resource_response.rb +3 -7
  25. data/lib/action_mcp/resource_template.rb +1 -0
  26. data/lib/action_mcp/schema_context.rb +50 -0
  27. data/lib/action_mcp/server/base_session.rb +7 -173
  28. data/lib/action_mcp/server/handlers/dispatching.rb +38 -0
  29. data/lib/action_mcp/server/handlers/prompt_handler.rb +6 -12
  30. data/lib/action_mcp/server/handlers/resource_handler.rb +6 -23
  31. data/lib/action_mcp/server/handlers/task_handler.rb +14 -31
  32. data/lib/action_mcp/server/handlers/tool_handler.rb +4 -11
  33. data/lib/action_mcp/server/json_rpc_handler.rb +17 -1
  34. data/lib/action_mcp/server/prompts.rb +8 -17
  35. data/lib/action_mcp/server/resources.rb +4 -28
  36. data/lib/action_mcp/server/result_response.rb +19 -0
  37. data/lib/action_mcp/server/sampling_request.rb +26 -43
  38. data/lib/action_mcp/server/session_registries.rb +127 -0
  39. data/lib/action_mcp/server/tools.rb +23 -33
  40. data/lib/action_mcp/server/transport_handler.rb +0 -6
  41. data/lib/action_mcp/tagged_stream_logging.rb +9 -5
  42. data/lib/action_mcp/tool.rb +67 -71
  43. data/lib/action_mcp/version.rb +1 -1
  44. data/lib/action_mcp.rb +4 -0
  45. data/lib/tasks/action_mcp_tasks.rake +22 -44
  46. metadata +11 -3
  47. data/lib/action_mcp/server/handlers/router.rb +0 -33
@@ -4,6 +4,8 @@ module ActionMCP
4
4
  module Server
5
5
  # Base session object that mimics ActiveRecord Session with common functionality
6
6
  class BaseSession
7
+ include SessionRegistries
8
+
7
9
  attr_accessor :id, :status, :initialized, :role, :messages_count,
8
10
  :protocol_version, :client_info,
9
11
  :client_capabilities, :server_info, :server_capabilities,
@@ -22,9 +24,7 @@ module ActionMCP
22
24
  @consents = {}
23
25
  @session_data = {}
24
26
 
25
- attributes.each do |key, value|
26
- send("#{key}=", value) if respond_to?("#{key}=")
27
- end
27
+ assign_known_attributes(attributes)
28
28
  end
29
29
 
30
30
  # ActiveRecord-like interface
@@ -48,9 +48,7 @@ module ActionMCP
48
48
  end
49
49
 
50
50
  def update(attributes)
51
- attributes.each do |key, value|
52
- send("#{key}=", value) if respond_to?("#{key}=")
53
- end
51
+ assign_known_attributes(attributes)
54
52
  save
55
53
  end
56
54
 
@@ -77,14 +75,6 @@ module ActionMCP
77
75
  save
78
76
  end
79
77
 
80
- def initialize!
81
- return false unless status == "initializing" && !initialized?
82
-
83
- self.initialized = true
84
- self.status = "initialized"
85
- save
86
- end
87
-
88
78
  def close!
89
79
  self.status = "closed"
90
80
  self.ended_at = Time.current
@@ -185,111 +175,6 @@ module ActionMCP
185
175
  @subscriptions.any? { |subscription| subscription[:uri] == uri }
186
176
  end
187
177
 
188
- # Progress notification
189
- def send_progress_notification(progressToken:, progress:, total: nil, message: nil)
190
- handler = ActionMCP::Server::TransportHandler.new(self)
191
- handler.send_progress_notification(
192
- progressToken: progressToken,
193
- progress: progress,
194
- total: total,
195
- message: message
196
- )
197
- end
198
-
199
- # Registry management methods
200
- def register_tool(tool_class_or_name)
201
- tool_name = normalize_name(tool_class_or_name, :tool)
202
- return false unless tool_exists?(tool_name)
203
-
204
- self.tool_registry ||= []
205
- unless self.tool_registry.include?(tool_name)
206
- self.tool_registry << tool_name
207
- save!
208
- send_tools_list_changed_notification
209
- end
210
- true
211
- end
212
-
213
- def unregister_tool(tool_class_or_name)
214
- tool_name = normalize_name(tool_class_or_name, :tool)
215
- self.tool_registry ||= []
216
-
217
- return unless self.tool_registry.delete(tool_name)
218
-
219
- save!
220
- send_tools_list_changed_notification
221
- end
222
-
223
- def register_prompt(prompt_class_or_name)
224
- prompt_name = normalize_name(prompt_class_or_name, :prompt)
225
- return false unless prompt_exists?(prompt_name)
226
-
227
- self.prompt_registry ||= []
228
- unless self.prompt_registry.include?(prompt_name)
229
- self.prompt_registry << prompt_name
230
- save!
231
- send_prompts_list_changed_notification
232
- end
233
- true
234
- end
235
-
236
- def unregister_prompt(prompt_class_or_name)
237
- prompt_name = normalize_name(prompt_class_or_name, :prompt)
238
- self.prompt_registry ||= []
239
-
240
- return unless self.prompt_registry.delete(prompt_name)
241
-
242
- save!
243
- send_prompts_list_changed_notification
244
- end
245
-
246
- def register_resource_template(template_class_or_name)
247
- template_name = normalize_name(template_class_or_name, :resource_template)
248
- return false unless resource_template_exists?(template_name)
249
-
250
- self.resource_registry ||= []
251
- unless self.resource_registry.include?(template_name)
252
- self.resource_registry << template_name
253
- save!
254
- send_resources_list_changed_notification
255
- end
256
- true
257
- end
258
-
259
- def unregister_resource_template(template_class_or_name)
260
- template_name = normalize_name(template_class_or_name, :resource_template)
261
- self.resource_registry ||= []
262
-
263
- return unless self.resource_registry.delete(template_name)
264
-
265
- save!
266
- send_resources_list_changed_notification
267
- end
268
-
269
- def registered_tools
270
- (self.tool_registry || []).filter_map do |tool_name|
271
- ActionMCP::ToolsRegistry.find(tool_name)
272
- rescue StandardError
273
- nil
274
- end
275
- end
276
-
277
- def registered_prompts
278
- (self.prompt_registry || []).filter_map do |prompt_name|
279
- ActionMCP::PromptsRegistry.find(prompt_name)
280
- rescue StandardError
281
- nil
282
- end
283
- end
284
-
285
- def registered_resource_templates
286
- (self.resource_registry || []).filter_map do |template_name|
287
- ActionMCP::ResourceTemplatesRegistry.find(template_name)
288
- rescue StandardError
289
- nil
290
- end
291
- end
292
-
293
178
  # Consent management methods
294
179
  def consent_granted_for?(key)
295
180
  consents_hash = consents.is_a?(String) ? JSON.parse(consents) : consents
@@ -402,63 +287,12 @@ module ActionMCP
402
287
  capabilities ? capabilities.deep_dup : {}
403
288
  end
404
289
 
405
- def normalize_name(class_or_name, type)
406
- case class_or_name
407
- when String
408
- class_or_name
409
- when Class
410
- case type
411
- when :tool
412
- class_or_name.tool_name
413
- when :prompt
414
- class_or_name.prompt_name
415
- when :resource_template
416
- class_or_name.capability_name
417
- end
418
- else
419
- raise ArgumentError, "Expected String or Class, got #{class_or_name.class}"
290
+ def assign_known_attributes(attributes)
291
+ attributes.each do |key, value|
292
+ send("#{key}=", value) if respond_to?("#{key}=")
420
293
  end
421
294
  end
422
295
 
423
- def tool_exists?(tool_name)
424
- ActionMCP::ToolsRegistry.find(tool_name)
425
- true
426
- rescue ActionMCP::RegistryBase::NotFound
427
- false
428
- end
429
-
430
- def prompt_exists?(prompt_name)
431
- ActionMCP::PromptsRegistry.find(prompt_name)
432
- true
433
- rescue ActionMCP::RegistryBase::NotFound
434
- false
435
- end
436
-
437
- def resource_template_exists?(template_name)
438
- ActionMCP::ResourceTemplatesRegistry.find(template_name)
439
- true
440
- rescue ActionMCP::RegistryBase::NotFound
441
- false
442
- end
443
-
444
- def send_tools_list_changed_notification
445
- return unless server_capabilities.dig("tools", "listChanged")
446
-
447
- write(JSON_RPC::Notification.new(method: "notifications/tools/list_changed"))
448
- end
449
-
450
- def send_prompts_list_changed_notification
451
- return unless server_capabilities.dig("prompts", "listChanged")
452
-
453
- write(JSON_RPC::Notification.new(method: "notifications/prompts/list_changed"))
454
- end
455
-
456
- def send_resources_list_changed_notification
457
- return unless server_capabilities.dig("resources", "listChanged")
458
-
459
- write(JSON_RPC::Notification.new(method: "notifications/resources/list_changed"))
460
- end
461
-
462
296
  # Collection classes
463
297
  class MessageCollection < Array
464
298
  def create!(attributes)
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionMCP
4
+ module Server
5
+ module Handlers
6
+ # Shared plumbing for the method-family handlers (prompts/, resources/, tools/, tasks/).
7
+ module Dispatching
8
+ private
9
+
10
+ def require_params_object!(params, label)
11
+ return if params.is_a?(Hash)
12
+
13
+ raise JSON_RPC::JsonRpcError.new(:invalid_params, message: "#{label} params must be an object")
14
+ end
15
+
16
+ def dispatch_rpc(handlers, family, rpc_method, id, params)
17
+ handler = handlers[rpc_method]
18
+ unless handler
19
+ Rails.logger.warn("Unknown #{family} method: #{rpc_method}")
20
+ raise JSON_RPC::JsonRpcError.new(:method_not_found, message: "Unknown #{family} method: #{rpc_method}")
21
+ end
22
+
23
+ send(handler, id, params)
24
+ end
25
+
26
+ def negotiated_capabilities(key)
27
+ capabilities = (transport.session.server_capabilities || {}).with_indifferent_access
28
+ value = capabilities[key]
29
+ value.with_indifferent_access if value.is_a?(Hash)
30
+ end
31
+
32
+ def method_not_available!(message)
33
+ raise JSON_RPC::JsonRpcError.new(:method_not_found, message: message)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -5,22 +5,15 @@ module ActionMCP
5
5
  module Handlers
6
6
  module PromptHandler
7
7
  include ErrorAware
8
+ include Dispatching
8
9
 
9
10
  def process_prompts(rpc_method, id, params)
10
11
  params ||= {}
11
12
 
12
13
  with_error_handling(id) do
13
- unless params.is_a?(Hash)
14
- raise JSON_RPC::JsonRpcError.new(:invalid_params, message: "Prompt params must be an object")
15
- end
16
-
17
- handler = prompt_method_handlers[rpc_method]
18
- if handler
19
- send(handler, id, params)
20
- else
21
- Rails.logger.warn("Unknown prompts method: #{rpc_method}")
22
- raise JSON_RPC::JsonRpcError.new(:method_not_found, message: "Unknown prompts method: #{rpc_method}")
23
- end
14
+ require_params_object!(params, "Prompt")
15
+
16
+ dispatch_rpc(prompt_method_handlers, "prompts", rpc_method, id, params)
24
17
  end
25
18
  end
26
19
 
@@ -43,7 +36,8 @@ module ActionMCP
43
36
  raise JSON_RPC::JsonRpcError.new(:invalid_params, message: "Prompt argument values must be strings")
44
37
  end
45
38
 
46
- transport.send_prompts_get(id, name, arguments)
39
+ _meta = params["_meta"] || params[:_meta] || {}
40
+ transport.send_prompts_get(id, name, arguments, _meta)
47
41
  end
48
42
 
49
43
  def handle_prompts_list(id, params)
@@ -7,33 +7,22 @@ module ActionMCP
7
7
  module Handlers
8
8
  module ResourceHandler
9
9
  include ErrorAware
10
+ include Dispatching
10
11
 
11
12
  def process_resources(rpc_method, id, params)
12
13
  params ||= {}
13
14
 
14
15
  with_error_handling(id) do
15
- unless params.is_a?(Hash)
16
- raise JSON_RPC::JsonRpcError.new(:invalid_params, message: "Resource params must be an object")
17
- end
16
+ require_params_object!(params, "Resource")
18
17
 
19
- capabilities = negotiated_resource_capabilities
20
- unless capabilities
21
- raise JSON_RPC::JsonRpcError.new(:method_not_found,
22
- message: "Resources are not available for this session")
23
- end
18
+ capabilities = negotiated_capabilities(:resources)
19
+ method_not_available!("Resources are not available for this session") unless capabilities
24
20
 
25
21
  if subscription_method?(rpc_method) && capabilities[:subscribe] != true
26
- raise JSON_RPC::JsonRpcError.new(:method_not_found,
27
- message: "Resource subscriptions are not available for this session")
22
+ method_not_available!("Resource subscriptions are not available for this session")
28
23
  end
29
24
 
30
- handler = resource_method_handlers[rpc_method]
31
- if handler
32
- send(handler, id, params)
33
- else
34
- Rails.logger.warn("Unknown resources method: #{rpc_method}")
35
- raise JSON_RPC::JsonRpcError.new(:method_not_found, message: "Unknown resources method: #{rpc_method}")
36
- end
25
+ dispatch_rpc(resource_method_handlers, "resources", rpc_method, id, params)
37
26
  end
38
27
  end
39
28
 
@@ -49,12 +38,6 @@ module ActionMCP
49
38
  }
50
39
  end
51
40
 
52
- def negotiated_resource_capabilities
53
- capabilities = (transport.session.server_capabilities || {}).with_indifferent_access
54
- resource_capabilities = capabilities[:resources]
55
- resource_capabilities.with_indifferent_access if resource_capabilities.is_a?(Hash)
56
- end
57
-
58
41
  def subscription_method?(rpc_method)
59
42
  rpc_method == JsonRpcHandlerBase::Methods::RESOURCES_SUBSCRIBE ||
60
43
  rpc_method == JsonRpcHandlerBase::Methods::RESOURCES_UNSUBSCRIBE
@@ -7,43 +7,32 @@ module ActionMCP
7
7
  # Tasks provide durable state machines for tracking async request execution
8
8
  module TaskHandler
9
9
  include ErrorAware
10
+ include Dispatching
11
+
12
+ GATED_TASK_METHODS = {
13
+ JsonRpcHandlerBase::Methods::TASKS_LIST => [ :list, "Task listing" ],
14
+ JsonRpcHandlerBase::Methods::TASKS_CANCEL => [ :cancel, "Task cancellation" ]
15
+ }.freeze
10
16
 
11
17
  def process_tasks(rpc_method, id, params)
12
18
  params ||= {}
13
19
 
14
20
  with_error_handling(id) do
15
- unless params.is_a?(Hash)
16
- raise JSON_RPC::JsonRpcError.new(:invalid_params, message: "Task params must be an object")
17
- end
21
+ require_params_object!(params, "Task")
18
22
 
19
23
  unless transport.session.protocol_version == "2025-11-25"
20
- raise JSON_RPC::JsonRpcError.new(:method_not_found,
21
- message: "Tasks are only available in MCP 2025-11-25")
22
- end
23
-
24
- task_capabilities = negotiated_task_capabilities
25
- unless task_capabilities
26
- raise JSON_RPC::JsonRpcError.new(:method_not_found,
27
- message: "Tasks are not available for this session")
24
+ method_not_available!("Tasks are only available in MCP 2025-11-25")
28
25
  end
29
26
 
30
- if rpc_method == JsonRpcHandlerBase::Methods::TASKS_LIST && !task_capabilities.key?(:list)
31
- raise JSON_RPC::JsonRpcError.new(:method_not_found,
32
- message: "Task listing is not available for this session")
33
- end
27
+ task_capabilities = negotiated_capabilities(:tasks)
28
+ method_not_available!("Tasks are not available for this session") unless task_capabilities
34
29
 
35
- if rpc_method == JsonRpcHandlerBase::Methods::TASKS_CANCEL && !task_capabilities.key?(:cancel)
36
- raise JSON_RPC::JsonRpcError.new(:method_not_found,
37
- message: "Task cancellation is not available for this session")
30
+ capability, feature = GATED_TASK_METHODS[rpc_method]
31
+ if capability && !task_capabilities.key?(capability)
32
+ method_not_available!("#{feature} is not available for this session")
38
33
  end
39
34
 
40
- handler = task_method_handlers[rpc_method]
41
- if handler
42
- send(handler, id, params)
43
- else
44
- Rails.logger.warn("Unknown tasks method: #{rpc_method}")
45
- raise JSON_RPC::JsonRpcError.new(:method_not_found, message: "Unknown tasks method: #{rpc_method}")
46
- end
35
+ dispatch_rpc(task_method_handlers, "tasks", rpc_method, id, params)
47
36
  end
48
37
  end
49
38
 
@@ -58,12 +47,6 @@ module ActionMCP
58
47
  }
59
48
  end
60
49
 
61
- def negotiated_task_capabilities
62
- capabilities = (transport.session.server_capabilities || {}).with_indifferent_access
63
- task_capabilities = capabilities[:tasks]
64
- task_capabilities.with_indifferent_access if task_capabilities.is_a?(Hash)
65
- end
66
-
67
50
  def handle_tasks_get(id, params)
68
51
  task_id = validate_required_param(params, "taskId", "Task ID is required")
69
52
  task = find_task_or_error(id, task_id)
@@ -5,22 +5,15 @@ module ActionMCP
5
5
  module Handlers
6
6
  module ToolHandler
7
7
  include ErrorAware
8
+ include Dispatching
8
9
 
9
10
  def process_tools(rpc_method, id, params)
10
11
  params ||= {}
11
12
 
12
13
  with_error_handling(id) do
13
- unless params.is_a?(Hash)
14
- raise JSON_RPC::JsonRpcError.new(:invalid_params, message: "Tool params must be an object")
15
- end
16
-
17
- handler = tool_method_handlers[rpc_method]
18
- if handler
19
- send(handler, id, params)
20
- else
21
- Rails.logger.warn("Unknown tools method: #{rpc_method}")
22
- raise JSON_RPC::JsonRpcError.new(:method_not_found, message: "Unknown tools method: #{rpc_method}")
23
- end
14
+ require_params_object!(params, "Tool")
15
+
16
+ dispatch_rpc(tool_method_handlers, "tools", rpc_method, id, params)
24
17
  end
25
18
  end
26
19
 
@@ -62,10 +62,26 @@ module ActionMCP
62
62
  when Methods::LOGGING_SET_LEVEL
63
63
  handle_logging_set_level(id, params)
64
64
  else
65
- raise JSON_RPC::JsonRpcError.new(:method_not_found, message: "Method not found: #{rpc_method}")
65
+ process_custom_method(rpc_method, id, params)
66
66
  end
67
67
  end
68
68
 
69
+ def process_custom_method(rpc_method, id, params)
70
+ handler = ActionMCP.configuration.custom_methods[rpc_method]
71
+ raise JSON_RPC::JsonRpcError.new(:method_not_found, message: "Method not found: #{rpc_method}") unless handler
72
+
73
+ result = begin
74
+ handler.call(params || {}, transport.session)
75
+ rescue JSON_RPC::JsonRpcError
76
+ raise
77
+ rescue StandardError => e
78
+ Rails.error.report(e, handled: true, severity: :error, context: { rpc_method: rpc_method })
79
+ raise JSON_RPC::JsonRpcError.new(:internal_error, message: "Error while handling #{rpc_method}")
80
+ end
81
+
82
+ transport.send_jsonrpc_response(id, result: result)
83
+ end
84
+
69
85
  def handle_initialize(id, params)
70
86
  transport.send_capabilities(id, params)
71
87
  end
@@ -3,6 +3,8 @@
3
3
  module ActionMCP
4
4
  module Server
5
5
  module Prompts
6
+ include ResultResponse
7
+
6
8
  def send_prompts_list(request_id, params = {})
7
9
  page, next_cursor = paginate(session.registered_prompts, cursor: params["cursor"])
8
10
 
@@ -14,29 +16,18 @@ module ActionMCP
14
16
  send_jsonrpc_error(request_id, :invalid_params, e.message)
15
17
  end
16
18
 
17
- def send_prompts_get(request_id, prompt_name, params)
19
+ def send_prompts_get(request_id, prompt_name, params, _meta = {})
18
20
  # Find prompt in session's registry
19
21
  prompt_class = session.registered_prompts.find { |p| p.prompt_name == prompt_name }
20
22
 
21
23
  if prompt_class
22
24
  # Create prompt and set execution context
23
25
  prompt = prompt_class.new(params)
24
- prompt.with_context({ session: session })
25
-
26
- # Wrap prompt execution with Rails reloader for development
27
- result = if Rails.env.development? && defined?(Rails.application.reloader)
28
- Rails.application.reloader.wrap do
29
- prompt.call
30
- end
31
- else
32
- prompt.call
33
- end
34
-
35
- if result.is_error
36
- send_jsonrpc_response(request_id, error: result.to_h)
37
- else
38
- send_jsonrpc_response(request_id, result: result.to_h)
39
- end
26
+ prompt.with_context({ session: session, request: { params: { name: prompt_name, _meta: _meta } } })
27
+
28
+ result = DevReloader.wrap { prompt.call }
29
+
30
+ send_result_response(request_id, result)
40
31
  else
41
32
  send_jsonrpc_error(request_id, :invalid_params, "Prompt '#{prompt_name}' not available in this session")
42
33
  end
@@ -48,15 +48,7 @@ module ActionMCP
48
48
  uri = params["uri"]
49
49
  template = find_registered_template_for_uri(uri)
50
50
 
51
- unless template
52
- error = {
53
- code: -32_002,
54
- message: "Resource not found",
55
- data: { uri: uri }
56
- }
57
- send_jsonrpc_response(id, error: error)
58
- return
59
- end
51
+ return send_jsonrpc_response(id, error: resource_not_found_error(uri)) unless template
60
52
 
61
53
  # Check if resource requires consent and if consent is granted
62
54
  if template.respond_to?(:requires_consent?) && template.requires_consent? && !session.consent_granted_for?("resource:#{template.name}")
@@ -68,30 +60,14 @@ module ActionMCP
68
60
  return
69
61
  end
70
62
 
71
- unless template.readable_uri?(uri)
72
- error = {
73
- code: -32_002,
74
- message: "Resource not found",
75
- data: { uri: uri }
76
- }
77
- send_jsonrpc_response(id, error: error)
78
- return
79
- end
63
+ return send_jsonrpc_response(id, error: resource_not_found_error(uri)) unless template.readable_uri?(uri)
80
64
 
81
65
  begin
82
66
  # Create template instance and set execution context
83
67
  record = template.process(uri)
84
- unless record
85
- error = {
86
- code: -32_002,
87
- message: "Resource not found",
88
- data: { uri: uri }
89
- }
90
- send_jsonrpc_response(id, error: error)
91
- return
92
- end
68
+ return send_jsonrpc_response(id, error: resource_not_found_error(uri)) unless record
93
69
 
94
- record.with_context({ session: session })
70
+ record.with_context({ session: session, request: { params: { uri: uri, _meta: params["_meta"] || {} } } })
95
71
 
96
72
  response = record.call
97
73
 
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionMCP
4
+ module Server
5
+ # Sends a prompt or tool result as a JSON-RPC error when it is a protocol error,
6
+ # otherwise as the request result.
7
+ module ResultResponse
8
+ private
9
+
10
+ def send_result_response(request_id, result)
11
+ if result.is_error
12
+ send_jsonrpc_response(request_id, error: result.to_h)
13
+ else
14
+ send_jsonrpc_response(request_id, result: result.to_h)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end