explicit 0.2.18 → 0.2.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 336334a1c2bd5bdde4580b2b3712618a7edacf3edfec03d1f96c44f704b09c3a
4
- data.tar.gz: d756447ce81a13fb7bb7d722bdf7b89221bd556d16ea79bbe2dd39af3bda5e05
3
+ metadata.gz: 2be9f58389c8a9d5478bf8c0604b89ce308d90ad44e1f053ed9ad6565dd85ecb
4
+ data.tar.gz: cb2aa01a9ae758d3247db1f5379456f4c9711a4153fd965bb1baf9bf459f0518
5
5
  SHA512:
6
- metadata.gz: e574720e293d3bd0b1ed92a0a19dd83a8b1aa4fea48a2e2b3c1d5cffc2ead2a8d87bebabd5815a6d9752b4dee11a70f37a32f438f0c635e8b7f04015802d597d
7
- data.tar.gz: d8c7391dd7b6f0a769d885984a2bb823784d7423540e6b07a4e2136d4ac2fe50e42ecc42b120bc3f687244755bc12539278d5f73f21e0c85e8f01325c973606c
6
+ metadata.gz: c726fe0a4e25152e827c478628562c7af69e263af082229af8b6de361a1144f44bb8799f7ed3b78a95899594fe18867e1f3bdaca882c722a54f393477f6985de
7
+ data.tar.gz: 564654b46d1681986dbbf4c8cfd1da706606c9290332230a507ad5cac21a5d845b9f96a92b0fcb0012205d8721fc59a77810962ccd4641c8c951e5d0543a919c
@@ -3,7 +3,7 @@
3
3
  require "rack/utils"
4
4
 
5
5
  module Explicit::MCPServer
6
- Request = ::Data.define(:id, :method, :params, :host, :headers) do
6
+ Request = ::Data.define(:id, :method, :params, :host, :headers, :rack_env) do
7
7
  def self.from_rack_env(env)
8
8
  headers = env.each_with_object({}) do |(key, value), hash|
9
9
  if key.start_with?("HTTP_") && key != "HTTP_HOST"
@@ -19,7 +19,8 @@ module Explicit::MCPServer
19
19
  method: body["method"],
20
20
  params: body["params"],
21
21
  host: env["HTTP_HOST"],
22
- headers:
22
+ headers:,
23
+ rack_env: env
23
24
  )
24
25
  rescue ::JSON::ParserError
25
26
  new(
@@ -27,7 +28,8 @@ module Explicit::MCPServer
27
28
  method: nil,
28
29
  params: nil,
29
30
  host: env["HTTP_HOST"],
30
- headers: headers
31
+ headers:,
32
+ rack_env: env
31
33
  )
32
34
  end
33
35
 
@@ -53,8 +53,6 @@ class Explicit::MCPServer::Router
53
53
  return request.error({ code: -32602, message: "tool not found" })
54
54
  end
55
55
 
56
- session = ::ActionDispatch::Integration::Session.new(::Rails.application)
57
- session.host = request.host
58
56
  route = tool.request.routes.first
59
57
 
60
58
  path = [
@@ -62,23 +60,40 @@ class Explicit::MCPServer::Router
62
60
  route.replace_path_params(arguments)
63
61
  ].compact_blank.join
64
62
 
65
- path, params =
63
+ body_content, querystring =
66
64
  if route.accepts_request_body?
67
- [path, arguments]
65
+ [arguments.to_json, ""]
68
66
  else
69
- ["#{path}?#{arguments.to_query}", nil]
67
+ ["", arguments.to_query]
70
68
  end
71
69
 
72
- session.process(route.method, path, params:, headers: request.headers)
70
+ rack_input = ::StringIO.new(body_content)
71
+ rack_input.rewind
72
+
73
+ env = request.rack_env.merge({
74
+ "REQUEST_METHOD" => route.method.to_s.upcase,
75
+ "PATH_INFO" => path,
76
+ "rack.input" => rack_input,
77
+ "CONTENT_TYPE" => "application/json",
78
+ "CONTENT_LENGTH" => body_content.bytesize.to_s,
79
+ "QUERY_STRING" => querystring
80
+ })
81
+
82
+ request.headers.each do |key, value|
83
+ env["HTTP_#{key.upcase.tr('-', '_')}"] = value
84
+ end
85
+
86
+ status, headers, body = Rails.application.call(env)
87
+ response = ::ActionDispatch::Response.new(status, headers, body)
73
88
 
74
89
  request.result({
75
90
  content: [
76
91
  {
77
92
  type: "text",
78
- text: session.response.body
93
+ text: response.body
79
94
  }
80
95
  ],
81
- isError: session.response.status < 200 || session.response.status > 299
96
+ isError: response.status < 200 || response.status > 299
82
97
  })
83
98
  end
84
99
  end
@@ -6,9 +6,7 @@ module Explicit::MCPServer
6
6
  def new(&block)
7
7
  engine = ::Class.new(::Rails::Engine)
8
8
 
9
- builder = Builder.new.tap do |builder|
10
- builder.instance_eval(&block)
11
- end
9
+ builder = Builder.new.tap { _1.instance_eval(&block) }
12
10
 
13
11
  if builder.get_name.blank?
14
12
  raise <<~TEXT
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Explicit
4
- VERSION = "0.2.18"
4
+ VERSION = "0.2.19"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: explicit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.18
4
+ version: 0.2.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luiz Vasconcellos