Module: ActionMCP::TestHelper

Includes:
ProgressNotificationAssertions, SessionStoreAssertions, ActiveSupport::Testing::Assertions
Defined in:
lib/action_mcp/test_helper.rb,
lib/action_mcp/test_helper/session_store_assertions.rb,
lib/action_mcp/test_helper/progress_notification_assertions.rb

Overview


ActionMCP::TestHelper

Include in any ‘ActiveSupport::TestCase`:

include ActionMCP::TestHelper

and you get assert_mcp_tool_findable,

assert_mcp_prompt_findable,
assert_mcp_resource_template_findable,
execute_mcp_tool,
execute_mcp_tool_with_error,
execute_mcp_prompt,
resolve_mcp_resource,
resolve_mcp_resource_with_error,
assert_mcp_error_code,
assert_mcp_tool_output,
assert_mcp_prompt_output.

Short alias names (without the prefix) remain for this gem’s own suite but are not documented for public use.


Defined Under Namespace

Modules: ProgressNotificationAssertions, SessionStoreAssertions

Instance Method Summary collapse

Methods included from ProgressNotificationAssertions

#assert_no_progress_notification_sent, #assert_progress_notification_count, #assert_progress_notification_includes, #assert_progress_notification_sent, #assert_progress_notification_valid, #assert_progress_sequence_valid, #progress_session_store

Methods included from SessionStoreAssertions

#assert_session_created, #assert_session_deleted, #assert_session_loaded, #assert_session_not_created, #assert_session_not_deleted, #assert_session_not_loaded, #assert_session_not_saved, #assert_session_operation_count, #assert_session_saved

Instance Method Details

#assert_mcp_error_code(code, response, msg = nil) ⇒ Object Also known as: assert_error_code

──── Negative‑path helper ───────────────────────────────────────────────



100
101
102
103
104
# File 'lib/action_mcp/test_helper.rb', line 100

def assert_mcp_error_code(code, response, msg = nil)
  assert response.error?, msg || "Expected response to be an error"
  assert_equal code, response.to_h[:code],
               msg || "Expected error code #{code}, got #{response.to_h[:code]}"
end

#assert_mcp_prompt_findable(name, msg = nil) ⇒ Object Also known as: assert_prompt_findable



48
49
50
51
# File 'lib/action_mcp/test_helper.rb', line 48

def assert_mcp_prompt_findable(name, msg = nil)
  assert ActionMCP::PromptsRegistry.prompts.key?(name),
         msg || "Prompt #{name.inspect} not found in PromptsRegistry"
end

#assert_mcp_prompt_output(expected, response, msg = nil) ⇒ Object Also known as: assert_prompt_output



115
116
117
118
119
# File 'lib/action_mcp/test_helper.rb', line 115

def assert_mcp_prompt_output(expected, response, msg = nil)
  assert response.success?, msg || "Expected a successful prompt response"
  assert_equal expected, response.messages,
               msg || "Prompt output did not match expected"
end

#assert_mcp_resource_template_findable(name, msg = nil) ⇒ Object Also known as: assert_resource_template_findable

──── Registry assertions ────────────────────────────────────────────────



36
37
38
39
# File 'lib/action_mcp/test_helper.rb', line 36

def assert_mcp_resource_template_findable(name, msg = nil)
  assert ActionMCP::ResourceTemplatesRegistry.resource_templates.key?(name),
         msg || "Resource template #{name.inspect} not found in ResourceTemplatesRegistry"
end

#assert_mcp_tool_findable(name, msg = nil) ⇒ Object Also known as: assert_tool_findable



42
43
44
45
# File 'lib/action_mcp/test_helper.rb', line 42

def assert_mcp_tool_findable(name, msg = nil)
  assert ActionMCP::ToolsRegistry.tools.key?(name),
         msg || "Tool #{name.inspect} not found in ToolsRegistry"
end

#assert_mcp_tool_output(expected, response, msg = nil) ⇒ Object Also known as: assert_tool_output

──── Output assertions ─────────────────────────────────────────────────



108
109
110
111
112
# File 'lib/action_mcp/test_helper.rb', line 108

def assert_mcp_tool_output(expected, response, msg = nil)
  assert response.success?, msg || "Expected a successful tool response"
  assert_equal expected, response.contents.map(&:to_h),
               msg || "Tool output did not match expected"
end

#execute_mcp_prompt(name, args = {}) ⇒ Object Also known as: execute_prompt



67
68
69
70
71
# File 'lib/action_mcp/test_helper.rb', line 67

def execute_mcp_prompt(name, args = {})
  resp = ActionMCP::PromptsRegistry.prompt_call(name, args)
  assert !resp.is_error, "Prompt #{name.inspect} returned error: #{resp.to_h[:message]}"
  resp
end

#execute_mcp_tool(name, args = {}) ⇒ Object Also known as: execute_tool

──── Execution helpers (happy‑path only) ────────────────────────────────



55
56
57
58
59
# File 'lib/action_mcp/test_helper.rb', line 55

def execute_mcp_tool(name, args = {})
  resp = ActionMCP::ToolsRegistry.tool_call(name, args)
  assert !resp.is_error, "Tool #{name.inspect} returned error: #{resp.to_h[:message]}"
  resp
end

#execute_mcp_tool_with_error(name, args = {}) ⇒ Object Also known as: execute_tool_with_error



62
63
64
# File 'lib/action_mcp/test_helper.rb', line 62

def execute_mcp_tool_with_error(name, args = {})
  ActionMCP::ToolsRegistry.tool_call(name, args)
end

#resolve_mcp_resource(uri) ⇒ Object Also known as: resolve_resource



74
75
76
77
78
79
80
81
82
# File 'lib/action_mcp/test_helper.rb', line 74

def resolve_mcp_resource(uri)
  template_class = ActionMCP::ResourceTemplatesRegistry.find_template_for_uri(uri)
  assert template_class, "No resource template found matching URI #{uri.inspect}"
  template = template_class.process(uri)
  assert template, "Failed to process URI #{uri.inspect} with template #{template_class.name}"
  resp = template.call
  assert !resp.is_error, "Resource #{uri.inspect} returned error: #{resp.to_h[:message]}"
  resp
end

#resolve_mcp_resource_with_error(uri) ⇒ Object Also known as: resolve_resource_with_error



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/action_mcp/test_helper.rb', line 85

def resolve_mcp_resource_with_error(uri)
  template_class = ActionMCP::ResourceTemplatesRegistry.find_template_for_uri(uri)
  unless template_class
    return ActionMCP::ResourceResponse.new.tap { |r| r.mark_as_not_found!(uri) }
  end

  unless template_class.respond_to?(:readable_uri?) && template_class.readable_uri?(uri)
    return ActionMCP::ResourceResponse.new.tap { |r| r.mark_as_not_found!(uri) }
  end
  template = template_class.process(uri)
  template.call
end