mcp-rails 0.4.11 → 0.4.12

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: b6e405c23ef4fae7964591eb567ee9f383b436f3d602cd02b2f2d088ba5c256a
4
- data.tar.gz: 55ee2b62e45a44c2b6f9a1a9b172414c8bfbb5c98db5e0b68132594df81b9f87
3
+ metadata.gz: a8a69e5d343d51948184b2847ae711ff9d5fc96eeb41339561fd5da19c9ae9f5
4
+ data.tar.gz: '009b85d51fe302f557ac3787cfad6e0d5bb13a83f4a37e4cc21d2cd3bb536ad8'
5
5
  SHA512:
6
- metadata.gz: 88491aab2b61efd838a5e32ee9da92eebef4c642fd294200a125071d853916d3e97dcf2d983ef373321ca9cee2a10ab010b1fa945fb8438a19185dcb13e4ef94
7
- data.tar.gz: 03aa0d2516a2144794fc9b6c6328734a45f23debc92ef6b19ee926db2a13b942262dbc2cc9902a883dd8facc6dd9512d6fba7e9065f712568fa1903231aebe26
6
+ metadata.gz: 854cdcb2c9f80a52f19457972d1e7c81c5aee32b5a287c1b7966b3a6362a6c91844de7cc7c8d01fa8284549e8b897b95b08ef29fa757d194fc7f247967e16c7b
7
+ data.tar.gz: 4a56a7f83558d0e5d80c9eda6df306526baa9eac9ffabe271b3a390075b5361d53f778c0a90b892a5df68a786341dc2cb2aa19873fda3fbc5d3e7e4de9746832
@@ -1,5 +1,5 @@
1
1
  module Mcp
2
2
  module Rails
3
- VERSION = "0.4.11"
3
+ VERSION = "0.4.12"
4
4
  end
5
5
  end
@@ -0,0 +1,101 @@
1
+ module MCP
2
+ module Rails
3
+ module TestHelper
4
+ def self.included(base)
5
+ base.setup do
6
+ @temp_dir = Dir.mktmpdir nil, ::Rails.root.join("tmp")
7
+ @key_path = File.join(@temp_dir, "bypass_key.txt")
8
+ @output_dir = @temp_dir
9
+
10
+ @old_mcp_configuration = MCP::Rails.configuration
11
+
12
+ @new_mcp_configuration = MCP::Rails::Configuration.new
13
+ @old_mcp_configuration.engine_configurations.each do |name, config|
14
+ @new_mcp_configuration.register_engine name, env_vars: config.env_vars
15
+ end
16
+ @new_mcp_configuration.bypass_key_path = @key_path
17
+ @new_mcp_configuration.output_directory = @output_dir
18
+ MCP::Rails.configuration = @new_mcp_configuration
19
+
20
+ @generator = MCP::Rails::ServerGenerator
21
+ @server_files = @generator.generate_files(@new_mcp_configuration)
22
+ end
23
+
24
+ base.teardown do
25
+ FileUtils.remove_entry @temp_dir
26
+ MCP::Rails.configuration = @old_mcp_configuration
27
+ end
28
+ end
29
+
30
+ def mcp_servers
31
+ @mcp_servers = @server_files.map do |file|
32
+ require file
33
+ at_exit { MCP.instance_variable_set(:@server, nil) }
34
+ initialize_server(MCP.server)
35
+ MCP.server
36
+ end
37
+ end
38
+
39
+ def mcp_server(name: "mcp-server")
40
+ mcp_servers.find { |server| server.name == name }
41
+ end
42
+
43
+ def mcp_tool_list(server)
44
+ request = {
45
+ jsonrpc: MCP::Constants::JSON_RPC_VERSION,
46
+ method: MCP::Constants::RequestMethods::TOOLS_LIST,
47
+ id: 1
48
+ }
49
+
50
+ send_request(server, request)
51
+ end
52
+
53
+ def mcp_tool_call(server, name, arguments = {})
54
+ request = {
55
+ jsonrpc: MCP::Constants::JSON_RPC_VERSION,
56
+ id: 1,
57
+ method: MCP::Constants::RequestMethods::TOOLS_CALL,
58
+ params: {
59
+ name: name,
60
+ arguments: arguments.merge({ test_context: self })
61
+ }
62
+ }
63
+ send_request(server, request)
64
+ end
65
+
66
+ def mcp_response_body
67
+ JSON.parse(response.body).dig("data")
68
+ end
69
+
70
+ private
71
+
72
+ def send_request(server, request)
73
+ response = server.send(:handle_request, request)
74
+ raise "Request failed: #{response}" unless response.dig(:result, :isError) == false
75
+ response
76
+ end
77
+
78
+ def initialize_server(server)
79
+ init_request = {
80
+ jsonrpc: MCP::Constants::JSON_RPC_VERSION,
81
+ method: "initialize",
82
+ params: {
83
+ protocolVersion: MCP::Constants::PROTOCOL_VERSION,
84
+ capabilities: {}
85
+ },
86
+ id: 1
87
+ }
88
+ initialize_response = server.send(:handle_request, init_request)
89
+
90
+ init_notification = {
91
+ jsonrpc: MCP::Constants::JSON_RPC_VERSION,
92
+ method: "notifications/initialized",
93
+ id: 2
94
+ }
95
+ server.send(:handle_request, init_notification)
96
+
97
+ initialize_response
98
+ end
99
+ end
100
+ end
101
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mcp-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.11
4
+ version: 0.4.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tonksthebear
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-14 00:00:00.000000000 Z
10
+ date: 2025-03-15 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: mcp-rb
@@ -99,6 +99,7 @@ files:
99
99
  - lib/mcp/rails/server_generator/route_collector.rb
100
100
  - lib/mcp/rails/server_generator/server_writer.rb
101
101
  - lib/mcp/rails/version.rb
102
+ - test/support/mcp/rails/test_helper.rb
102
103
  homepage: https://github.com/Tonksthebear/mcp-rails
103
104
  licenses:
104
105
  - MIT
@@ -120,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
121
  - !ruby/object:Gem::Version
121
122
  version: '0'
122
123
  requirements: []
123
- rubygems_version: 3.6.4
124
+ rubygems_version: 3.6.2
124
125
  specification_version: 4
125
126
  summary: MCP Integration for Rails
126
127
  test_files: []