active_mcp 0.3.9 → 0.3.11
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67338ce686da0dee13981737b87274009ff6e333e0cf06274469b03f6b066c11
|
4
|
+
data.tar.gz: 86f3916c8df7848adea802a736f117f37f9a3c2a92f1aca811984b2782562a12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a58ff5874317b91aa79f84e373e57b04a0f11378ebe4299a9ce9408f930051038c5b86a1faa3c2e8e0b4a42463850d5e662112e48fae4876812b2c6e8aedafe
|
7
|
+
data.tar.gz: c64a85603d69a0e15c1cf8e0a42209a7f424e7f95bd0f064fcb785cf9e5b2d70c2ab0b1bb8fd36d8aa0af5dd2367ff767c3f431fbada308a23714f181c98bd6e
|
data/README.md
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
[](https://rubyonrails.org/)
|
8
8
|
|
9
9
|
A Ruby on Rails engine for the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) - connect your Rails apps to AI tools with minimal effort.
|
10
|
+
|
10
11
|
</div>
|
11
12
|
|
12
13
|
## 📖 Table of Contents
|
@@ -197,10 +198,7 @@ class SearchUsersTool < ActiveMcp::Tool
|
|
197
198
|
|
198
199
|
users = User.where(criteria).limit(limit)
|
199
200
|
|
200
|
-
|
201
|
-
type: "text",
|
202
|
-
content: users.to_json(only: [:id, :name, :email, :created_at])
|
203
|
-
}
|
201
|
+
users.attributes
|
204
202
|
end
|
205
203
|
end
|
206
204
|
```
|
@@ -218,15 +216,15 @@ argument :preferences, :object, required: false, description: 'User preferences'
|
|
218
216
|
|
219
217
|
Supported types:
|
220
218
|
|
221
|
-
| Type
|
222
|
-
|
|
223
|
-
| `:string`
|
224
|
-
| `:integer` | Whole numbers
|
225
|
-
| `:number`
|
226
|
-
| `:boolean` | True/false values
|
227
|
-
| `:array`
|
228
|
-
| `:object`
|
229
|
-
| `:null`
|
219
|
+
| Type | Description |
|
220
|
+
| ---------- | ------------------------------- |
|
221
|
+
| `:string` | Text values |
|
222
|
+
| `:integer` | Whole numbers |
|
223
|
+
| `:number` | Decimal numbers (float/decimal) |
|
224
|
+
| `:boolean` | True/false values |
|
225
|
+
| `:array` | Lists of values |
|
226
|
+
| `:object` | Hash/dictionary structures |
|
227
|
+
| `:null` | Null values |
|
230
228
|
|
231
229
|
## 🔐 Authorization & Authentication
|
232
230
|
|
@@ -244,7 +242,7 @@ class AdminOnlyTool < ActiveMcp::Tool
|
|
244
242
|
def self.visible?(auth_info)
|
245
243
|
return false unless auth_info
|
246
244
|
return false unless auth_info[:type] == :bearer
|
247
|
-
|
245
|
+
|
248
246
|
# Check if the token belongs to an admin
|
249
247
|
auth_info[:token] == "admin-token" || User.find_by_token(auth_info[:token])&.admin?
|
250
248
|
end
|
@@ -282,11 +280,11 @@ def call(resource_id:, auth_info: nil, **args)
|
|
282
280
|
|
283
281
|
# Verify the token
|
284
282
|
user = User.authenticate_with_token(auth_info[:token])
|
285
|
-
|
283
|
+
|
286
284
|
unless user
|
287
285
|
raise "Invalid authentication token"
|
288
286
|
end
|
289
|
-
|
287
|
+
|
290
288
|
# Proceed with authenticated operation
|
291
289
|
# ...
|
292
290
|
end
|
@@ -338,9 +336,9 @@ Always validate and sanitize inputs in your tool implementations:
|
|
338
336
|
def call(user_id:, **args)
|
339
337
|
# Validate input
|
340
338
|
unless user_id.is_a?(Integer) || user_id.to_s.match?(/^\d+$/)
|
341
|
-
|
339
|
+
raise "Invalid user ID format"
|
342
340
|
end
|
343
|
-
|
341
|
+
|
344
342
|
# Proceed with validated data
|
345
343
|
user = User.find_by(id: user_id)
|
346
344
|
# ...
|
@@ -354,9 +352,8 @@ Return structured responses that are easy for AI to parse:
|
|
354
352
|
```ruby
|
355
353
|
def call(query:, **args)
|
356
354
|
results = User.search(query)
|
357
|
-
|
355
|
+
|
358
356
|
{
|
359
|
-
type: "text",
|
360
357
|
content: results.to_json(only: [:id, :name, :email]),
|
361
358
|
metadata: {
|
362
359
|
count: results.size,
|
@@ -377,4 +374,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/moekio
|
|
377
374
|
## 📄 License
|
378
375
|
|
379
376
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
380
|
-
|
@@ -1,2 +1,2 @@
|
|
1
1
|
json.jsonrpc ActiveMcp::JSON_RPC_VERSION
|
2
|
-
json.
|
2
|
+
json.method ActiveMcp::Method::CANCELLED
|
@@ -5,5 +5,10 @@ if @format == :jsonrpc
|
|
5
5
|
json.result @tool_result
|
6
6
|
else
|
7
7
|
json.isError @tool_result[:isError] if @tool_result[:isError]
|
8
|
-
json.content
|
8
|
+
json.content do
|
9
|
+
json.array!(@tool_result[:content]) do |content|
|
10
|
+
json.type content[:type]
|
11
|
+
json.text raw content[:text]
|
12
|
+
end
|
13
|
+
end
|
9
14
|
end
|
data/lib/active_mcp/tool.rb
CHANGED
@@ -14,11 +14,7 @@ module ActiveMcp
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def property(name, type, required: false, description: nil)
|
17
|
-
@schema ||=
|
18
|
-
"type" => "object",
|
19
|
-
"properties" => {},
|
20
|
-
"required" => []
|
21
|
-
}
|
17
|
+
@schema ||= default_schema
|
22
18
|
|
23
19
|
@schema["properties"][name.to_s] = {"type" => type.to_s}
|
24
20
|
@schema["properties"][name.to_s]["description"] = description if description
|
@@ -46,7 +42,7 @@ module ActiveMcp
|
|
46
42
|
true
|
47
43
|
end
|
48
44
|
end
|
49
|
-
|
45
|
+
|
50
46
|
def authorized_tools(auth_info = nil)
|
51
47
|
registered_tools.select do |tool_class|
|
52
48
|
tool_class.visible?(auth_info)
|
@@ -54,10 +50,18 @@ module ActiveMcp
|
|
54
50
|
{
|
55
51
|
name: tool_class.tool_name,
|
56
52
|
description: tool_class.desc,
|
57
|
-
inputSchema: tool_class.schema
|
53
|
+
inputSchema: tool_class.schema || default_schema
|
58
54
|
}
|
59
55
|
end
|
60
56
|
end
|
57
|
+
|
58
|
+
def default_schema
|
59
|
+
{
|
60
|
+
"type" => "object",
|
61
|
+
"properties" => {},
|
62
|
+
"required" => []
|
63
|
+
}
|
64
|
+
end
|
61
65
|
end
|
62
66
|
|
63
67
|
def initialize
|
data/lib/active_mcp/version.rb
CHANGED