actionmcp 0.13.0 → 0.14.0
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 +4 -4
- data/README.md +9 -18
- data/lib/action_mcp/test_helper.rb +22 -9
- data/lib/action_mcp/tools_registry.rb +1 -1
- data/lib/action_mcp/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a853f65451f67bb2da8d67e317ed0554d832ecb0660b8adbe9d002c949792d43
|
4
|
+
data.tar.gz: 23212ca96b1538d71ed309a2e1f6b3e5143917ff117827b46306d4384ca0b0f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4701665f0d8912fe33213d17e0e3d69ff01cc3adac1d69d9d461963c366fca879d09b9be06a2bdfb6579e8bdbcb842eb349bcde45f53316162a58be382f62cb
|
7
|
+
data.tar.gz: 59dfe42ba51f7bae693bbcee84833961eb3f1ea1312e046d105760328a2459842968d85e67289a411c57ddbc9d0bad54aef59ea54e37053fa5bb26360b3c4384
|
data/README.md
CHANGED
@@ -120,7 +120,7 @@ class AnalyzeCodePrompt < ApplicationMCPPrompt
|
|
120
120
|
# Add validations
|
121
121
|
validates :language, inclusion: { in: %w[Ruby C Cobol FORTRAN] }
|
122
122
|
|
123
|
-
def
|
123
|
+
def perform
|
124
124
|
# Implement your prompt logic here
|
125
125
|
render(text: "Analyzing #{language} code: #{code}")
|
126
126
|
end
|
@@ -145,7 +145,7 @@ class CalculateSumTool < ApplicationMCPTool
|
|
145
145
|
property :a, type: "number", description: "First number", required: true
|
146
146
|
property :b, type: "number", description: "Second number", required: true
|
147
147
|
|
148
|
-
def
|
148
|
+
def perform
|
149
149
|
render(text: a + b)
|
150
150
|
end
|
151
151
|
end
|
@@ -176,13 +176,8 @@ analyze_prompt = AnalyzeCodePrompt.new(language: "Ruby", code: "def hello; puts
|
|
176
176
|
# Optionally update attributes later:
|
177
177
|
analyze_prompt.code = "def goodbye; puts 'Goodbye!'; end"
|
178
178
|
|
179
|
-
|
180
|
-
|
181
|
-
result = analyze_prompt.call # => #<ActionMCP::Content::Text:0x00000001239398c8 @text="The code you provided is written in Ruby and looks great!", @type="text">
|
182
|
-
puts result.to_h # => {type: "text", text: "The code you provided is written in Ruby and looks great!"}
|
183
|
-
else
|
184
|
-
puts analyze_prompt.errors.full_messages
|
185
|
-
end
|
179
|
+
result = analyze_prompt.call #=> #<ActionMCP::PromptResponse messages: [{role: "user", content: {type: "text", text: "The code you provided is written in Ruby and looks great!"}}]>
|
180
|
+
puts result.to_h #=> {messages: [{role: "user", content: {type: "text", text: "The code you provided is written in Ruby and looks great!"}}]}
|
186
181
|
```
|
187
182
|
|
188
183
|
### Example for a Tool
|
@@ -195,12 +190,8 @@ sum_tool.a = 15
|
|
195
190
|
sum_tool.b = 20
|
196
191
|
|
197
192
|
# Validate the tool before calling it
|
198
|
-
|
199
|
-
|
200
|
-
puts result.to_h # => {type: "text", text: "35.0"}
|
201
|
-
else
|
202
|
-
puts sum_tool.errors.full_messages
|
203
|
-
end
|
193
|
+
result = sum_tool.call # => #<ActionMCP::ToolResponse content: [#<ActionMCP::Content::Text:0x000000012bb50f78 @type="text", @text="35.0">], isError: false>
|
194
|
+
puts result.to_h # => {content: [{type: "text", text: "35.0"}]}
|
204
195
|
```
|
205
196
|
|
206
197
|
These examples show that both prompts and tools follow a consistent pattern for initialization, validation, and execution, making it easy to integrate them into your application logic.
|
@@ -251,7 +242,7 @@ class ToolTest < ActiveSupport::TestCase
|
|
251
242
|
|
252
243
|
test "AnalyzeCodePrompt returns the correct analysis" do
|
253
244
|
assert_prompt_findable("analyze_code")
|
254
|
-
result =
|
245
|
+
result = execute_prompt("analyze_code", language: "Ruby", code: "def hello; puts 'Hello, world!'; end")
|
255
246
|
assert_equal "Analyzing Ruby code: def hello; puts 'Hello, world!'; end", assert_prompt_output(result)
|
256
247
|
end
|
257
248
|
end
|
@@ -263,8 +254,8 @@ The `TestHelper` module provides the following methods:
|
|
263
254
|
* `assert_prompt_findable(prompt_name)`: Asserts that a prompt is findable in the `PromptsRegistry`.
|
264
255
|
* `execute_tool(tool_name, args = {})`: Executes a tool with the given name and arguments.
|
265
256
|
* `execute_prompt(prompt_name, args = {})`: Executes a prompt with the given name and arguments.
|
266
|
-
* `assert_tool_output(
|
267
|
-
* `assert_prompt_output(result)`: Asserts that the output of a prompt is equal to the expected output.
|
257
|
+
* `assert_tool_output(expected_output, result)`: Asserts that the output of a tool is equal to the expected output.
|
258
|
+
* `assert_prompt_output(expected_output, result)`: Asserts that the output of a prompt is equal to the expected output.
|
268
259
|
|
269
260
|
To use the `TestHelper`, you need to require it in your `test_helper.rb` file:
|
270
261
|
|
@@ -4,35 +4,48 @@ module ActionMCP
|
|
4
4
|
module TestHelper
|
5
5
|
include ActiveSupport::Testing::Assertions
|
6
6
|
|
7
|
+
# Asserts that a tool is findable in the ToolsRegistry.
|
8
|
+
# @param [String] tool_name
|
7
9
|
def assert_tool_findable(tool_name)
|
8
10
|
assert ActionMCP::ToolsRegistry.tools.key?(tool_name), "Tool #{tool_name} not found in registry"
|
9
11
|
end
|
10
12
|
|
13
|
+
# Asserts that a prompt is findable in the PromptsRegistry.
|
14
|
+
# @param [String] prompt_name
|
11
15
|
def assert_prompt_findable(prompt_name)
|
12
16
|
assert ActionMCP::PromptsRegistry.prompts.key?(prompt_name), "Prompt #{prompt_name} not found in registry"
|
13
17
|
end
|
14
18
|
|
19
|
+
# Executes a tool with the given name and arguments.
|
20
|
+
# @param [String] tool_name
|
21
|
+
# @param [Hash] args
|
15
22
|
def execute_tool(tool_name, args = {})
|
16
23
|
result = ActionMCP::ToolsRegistry.tool_call(tool_name, args)
|
17
|
-
|
24
|
+
assert_not result.is_error, "Tool #{tool_name} returned an error: #{result.to_h[:message]}"
|
18
25
|
result
|
19
26
|
end
|
20
27
|
|
28
|
+
# Executes a prompt with the given name and arguments.
|
29
|
+
# @param [String] prompt_name
|
30
|
+
# @param [Hash] args
|
21
31
|
def execute_prompt(prompt_name, args = {})
|
22
32
|
result = ActionMCP::PromptsRegistry.prompt_call(prompt_name, args)
|
23
|
-
|
33
|
+
assert_not result.is_error, "Prompt #{prompt_name} returned an error: #{result.to_h[:message]}"
|
24
34
|
result
|
25
35
|
end
|
26
36
|
|
27
|
-
|
28
|
-
|
37
|
+
# Asserts that the output of a tool is equal to the expected output.
|
38
|
+
# @param [Hash] expected_output
|
39
|
+
# @param [ActionMCP::ToolResponse] result
|
40
|
+
def assert_tool_output(expected_output, result)
|
41
|
+
assert_equal expected_output, result.to_h[:content], "Tool output did not match expected output #{expected_output} != #{result.to_h[:content]}"
|
29
42
|
end
|
30
43
|
|
31
|
-
|
32
|
-
|
33
|
-
|
44
|
+
# Asserts that the output of a prompt is equal to the expected output.
|
45
|
+
# @param [Hash] expected_output
|
46
|
+
# @param [ActionMCP::PromptResponse] result
|
47
|
+
def assert_prompt_output(expected_output, result)
|
48
|
+
assert_equal expected_output, result.to_h[:messages], "Prompt output did not match expected output #{expected_output} != #{result.to_h[:messages]}"
|
34
49
|
end
|
35
|
-
|
36
|
-
# Add more assertion methods as needed
|
37
50
|
end
|
38
51
|
end
|
data/lib/action_mcp/version.rb
CHANGED