Module: ModelContextProtocol::RSpec::Helpers

Defined in:
lib/model_context_protocol/rspec/helpers.rb

Instance Method Summary collapse

Instance Method Details

#call_mcp_prompt(prompt_class, arguments = {}, context = {}) ⇒ Object

Calls an MCP prompt class with the given arguments and context.

Examples:

response = call_mcp_prompt(MyPrompt, { tone: "friendly" })
expect(response).to be_valid_mcp_prompt_response

Parameters:

  • prompt_class (Class)

    The prompt class to call (must inherit from ModelContextProtocol::Server::Prompt)

  • arguments (Hash) (defaults to: {})

    Arguments to pass to the prompt

  • context (Hash) (defaults to: {})

    Optional context to pass to the prompt

Returns:

  • (Object)

    The response from the prompt



36
37
38
# File 'lib/model_context_protocol/rspec/helpers.rb', line 36

def call_mcp_prompt(prompt_class, arguments = {}, context = {})
  prompt_class.call(arguments, null_logger, null_logger, context)
end

#call_mcp_resource(resource_class, context = {}) ⇒ Object

Calls an MCP resource class with the given context.

Examples:

response = call_mcp_resource(MyResource)
expect(response).to be_valid_mcp_resource_response

Parameters:

  • resource_class (Class)

    The resource class to call (must inherit from ModelContextProtocol::Server::Resource)

  • context (Hash) (defaults to: {})

    Optional context to pass to the resource

Returns:

  • (Object)

    The response from the resource



49
50
51
# File 'lib/model_context_protocol/rspec/helpers.rb', line 49

def call_mcp_resource(resource_class, context = {})
  resource_class.call(null_logger, null_logger, context)
end

#call_mcp_tool(tool_class, arguments = {}, context = {}) ⇒ Object

Calls an MCP tool class with the given arguments and context.

Examples:

response = call_mcp_tool(MyTool, { number: "5" })
expect(response).to be_valid_mcp_tool_response

Parameters:

  • tool_class (Class)

    The tool class to call (must inherit from ModelContextProtocol::Server::Tool)

  • arguments (Hash) (defaults to: {})

    Arguments to pass to the tool

  • context (Hash) (defaults to: {})

    Optional context to pass to the tool

Returns:

  • (Object)

    The response from the tool



22
23
24
# File 'lib/model_context_protocol/rspec/helpers.rb', line 22

def call_mcp_tool(tool_class, arguments = {}, context = {})
  tool_class.call(arguments, null_logger, null_logger, context)
end

#null_loggerLogger

Creates a null logger for testing purposes. Memoized per example so all helper calls in a single test share the same logger.

Returns:

  • (Logger)

    a logger that discards all output



8
9
10
# File 'lib/model_context_protocol/rspec/helpers.rb', line 8

def null_logger
  @null_logger ||= Logger.new(File::NULL)
end