Exception: MCP::Client::ServerRequestError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/mcp/client.rb

Overview

Raised inside a server-to-client request handler (registered via on_server_request, e.g. on_sampling) to answer the request with a specific JSON-RPC error code instead of the default internal error. Mirrors the TypeScript SDK's McpError and the Python SDK's ErrorData return: for example, the sampling spec answers a rejected request with code -1. https://modelcontextprotocol.io/specification/2025-11-25/client/sampling

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, code:) ⇒ ServerRequestError

Returns a new instance of ServerRequestError.



42
43
44
45
# File 'lib/mcp/client.rb', line 42

def initialize(message, code:)
  super(message)
  @code = code
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



40
41
42
# File 'lib/mcp/client.rb', line 40

def code
  @code
end