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,
execute_mcp_tool,
execute_mcp_prompt,
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_client_session_data_includes, #assert_client_session_deleted, #assert_client_session_loaded, #assert_client_session_not_deleted, #assert_client_session_not_loaded, #assert_client_session_not_saved, #assert_client_session_not_updated, #assert_client_session_operation_count, #assert_client_session_saved, #assert_client_session_updated, #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 ───────────────────────────────────────────────



65
66
67
68
69
# File 'lib/action_mcp/test_helper.rb', line 65

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



38
39
40
41
# File 'lib/action_mcp/test_helper.rb', line 38

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



80
81
82
83
84
# File 'lib/action_mcp/test_helper.rb', line 80

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_tool_findable(name, msg = nil) ⇒ Object Also known as: assert_tool_findable

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



32
33
34
35
# File 'lib/action_mcp/test_helper.rb', line 32

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 ─────────────────────────────────────────────────



73
74
75
76
77
# File 'lib/action_mcp/test_helper.rb', line 73

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



57
58
59
60
61
# File 'lib/action_mcp/test_helper.rb', line 57

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) ────────────────────────────────



45
46
47
48
49
# File 'lib/action_mcp/test_helper.rb', line 45

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



52
53
54
# File 'lib/action_mcp/test_helper.rb', line 52

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