Exception: MCP::Server::ResourceNotFoundError
- Inherits:
-
RequestHandlerError
- Object
- StandardError
- RequestHandlerError
- MCP::Server::ResourceNotFoundError
- Defined in:
- lib/mcp/server.rb
Overview
Raised when a requested resource URI does not exist. Per SEP-2164, resource-not-found errors use the standard JSON-RPC Invalid Params code (-32602) with the requested URI in the error ‘data` member. Raise this from a `resources_read_handler` block for unknown URIs:
server.resources_read_handler do |params|
raise MCP::Server::ResourceNotFoundError.new(params[:uri], params) unless known?(params[:uri])
do_something(params[:uri])
end
github.com/modelcontextprotocol/modelcontextprotocol/pull/2164
Instance Attribute Summary
Attributes inherited from RequestHandlerError
#error_code, #error_data, #error_type, #original_error
Instance Method Summary collapse
-
#initialize(uri, request = nil) ⇒ ResourceNotFoundError
constructor
A new instance of ResourceNotFoundError.
Constructor Details
#initialize(uri, request = nil) ⇒ ResourceNotFoundError
Returns a new instance of ResourceNotFoundError.
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/mcp/server.rb', line 73 def initialize(uri, request = nil) # The explicit `error_code` keeps the descriptive message in the JSON-RPC # error response; `error_type: :invalid_params` alone would replace it # with the generic "Invalid params" string. super( "Resource not found: #{uri}", request, error_type: :invalid_params, error_code: JsonRpcHandler::ErrorCode::INVALID_PARAMS, error_data: { uri: uri }, ) end |