Class: MCP::Client::HTTP
- Inherits:
-
Object
- Object
- MCP::Client::HTTP
- Defined in:
- lib/mcp/client/http.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url:, headers: {}) ⇒ HTTP
constructor
A new instance of HTTP.
- #send_request(request:) ⇒ Object
Constructor Details
#initialize(url:, headers: {}) ⇒ HTTP
Returns a new instance of HTTP.
8 9 10 11 |
# File 'lib/mcp/client/http.rb', line 8 def initialize(url:, headers: {}) @url = url @headers = headers end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/mcp/client/http.rb', line 6 def url @url end |
Instance Method Details
#send_request(request:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mcp/client/http.rb', line 13 def send_request(request:) method = request[:method] || request["method"] params = request[:params] || request["params"] client.post("", request).body rescue Faraday::BadRequestError => e raise RequestHandlerError.new( "The #{method} request is invalid", { method:, params: }, error_type: :bad_request, original_error: e, ) rescue Faraday:: => e raise RequestHandlerError.new( "You are unauthorized to make #{method} requests", { method:, params: }, error_type: :unauthorized, original_error: e, ) rescue Faraday::ForbiddenError => e raise RequestHandlerError.new( "You are forbidden to make #{method} requests", { method:, params: }, error_type: :forbidden, original_error: e, ) rescue Faraday::ResourceNotFound => e raise RequestHandlerError.new( "The #{method} request is not found", { method:, params: }, error_type: :not_found, original_error: e, ) rescue Faraday::UnprocessableEntityError => e raise RequestHandlerError.new( "The #{method} request is unprocessable", { method:, params: }, error_type: :unprocessable_entity, original_error: e, ) rescue Faraday::Error => e # Catch-all raise RequestHandlerError.new( "Internal error handling #{method} request", { method:, params: }, error_type: :internal_error, original_error: e, ) end |