hub_kernel-mcp 0.1.0 → 0.2.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 +12 -0
- data/app/controllers/hub_kernel/mcp/messages_controller.rb +18 -0
- data/lib/hub_kernel/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: fdf5562d9d62588f25ee064ae1571430d08a6ac2c452b957b1df4784f5c9cc1d
|
|
4
|
+
data.tar.gz: e122d851e02746457f5f4232eb118f3a2cd21100fb1931827f5af939c234076e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 120c5a8941826f02ceea5d9cf251d3ec30e0061f4282010526fd067da2f5b7fdfde270d90900842b58cefed05aafb9decf8acb52c49d05131eaf8ab0fe4a499d
|
|
7
|
+
data.tar.gz: 9082038898f81950d9a26c9973bc8d05e5d6769485d43f20eea358df2d274a388012fb3a1cd24393b88c73a4fecb2d3330e68923ec296f6ec34f6b0d9860b97c
|
data/README.md
CHANGED
|
@@ -43,6 +43,18 @@ its input schema names the values the method takes:
|
|
|
43
43
|
{ "name": "supplies__price_of", "inputSchema": { "type": "object", "properties": { "item": {} } } }
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
`tools/call` runs the hub method a tool names, for the person and account the host's methods
|
|
47
|
+
give, and returns the method's answer as JSON text:
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{ "content": [ { "type": "text", "text": "\"soap costs 3\"" } ], "isError": false }
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
A hub's refusal, or a value the method requires and the call left out, comes back as a tool
|
|
54
|
+
error carrying the reason, with `isError` set. A tool the caller may not call, a tool that does
|
|
55
|
+
not exist, and a tool naming a hub the host does not serve are all answered with the same
|
|
56
|
+
JSON-RPC error, code -32602, `Unknown tool: <name>`.
|
|
57
|
+
|
|
46
58
|
A caller the host's sign-in refuses is refused before any hub is asked.
|
|
47
59
|
|
|
48
60
|
## Installation
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
module HubKernel
|
|
2
2
|
module Mcp
|
|
3
3
|
class MessagesController < HubKernel::Mcp.base_controller.constantize
|
|
4
|
+
UnknownTool = Class.new(StandardError)
|
|
5
|
+
|
|
4
6
|
PROTOCOL_VERSIONS = %w[2025-11-25 2025-06-18 2025-03-26 2024-11-05].freeze
|
|
5
7
|
|
|
6
8
|
def create
|
|
7
9
|
return head :accepted unless params.key?(:id)
|
|
8
10
|
|
|
9
11
|
render json: { jsonrpc: "2.0", id: params[:id], result: answer }
|
|
12
|
+
rescue UnknownTool, HubKernel::UnexposedMethodError, HubKernel::NotAllowed
|
|
13
|
+
render json: { jsonrpc: "2.0", id: params[:id], error: { code: -32602, message: "Unknown tool: #{tool_name}" } }
|
|
10
14
|
end
|
|
11
15
|
|
|
12
16
|
private
|
|
@@ -15,6 +19,7 @@ module HubKernel
|
|
|
15
19
|
case params[:method]
|
|
16
20
|
when "initialize" then initialized
|
|
17
21
|
when "tools/list" then { tools: tools }
|
|
22
|
+
when "tools/call" then called
|
|
18
23
|
end
|
|
19
24
|
end
|
|
20
25
|
|
|
@@ -30,6 +35,19 @@ module HubKernel
|
|
|
30
35
|
|
|
31
36
|
def tool(served_name, exposure) = { name: "#{served_name}__#{exposure.name}", inputSchema: { type: "object", properties: exposure.takes.index_with { {} } } }
|
|
32
37
|
|
|
38
|
+
def called
|
|
39
|
+
served_name, method_name = tool_name.split("__", 2)
|
|
40
|
+
hub = HubKernel::Interface.find(served_name) || raise(UnknownTool)
|
|
41
|
+
answer = hub.call_exposed(method_name, values: arguments, person: caller_person, account: caller_account)
|
|
42
|
+
{ content: [ { type: "text", text: answer.to_json } ], isError: false }
|
|
43
|
+
rescue HubKernel::Refused, HubKernel::MissingArgumentError => refusal
|
|
44
|
+
{ content: [ { type: "text", text: refusal.message } ], isError: true }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def tool_name = params.dig(:params, :name).to_s
|
|
48
|
+
|
|
49
|
+
def arguments = params.dig(:params, :arguments)&.to_unsafe_h.to_h.deep_symbolize_keys
|
|
50
|
+
|
|
33
51
|
def caller_person = send(HubKernel::Mcp.person_method)
|
|
34
52
|
|
|
35
53
|
def caller_account = send(HubKernel::Mcp.account_method)
|