kailash 4.2.0-aarch64-linux → 4.3.0-aarch64-linux

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: 83264505ee8447fa0e0d675d5bacb1d45d3f2c71b68a3fb1568c8e43f2bb18e9
4
- data.tar.gz: 5f7d25ec46a8ef7c0ce156c1b11ed9d4f219c1b7796a0de576556e862a9356a1
3
+ metadata.gz: 7b8f6e5e693eeabb267e902de1218f2748d33b22c9e8f8bf1802372b5f08526f
4
+ data.tar.gz: 310ecfe3c01d34e9912b25b28f2964884515d963696992b9480a5c59021eabf8
5
5
  SHA512:
6
- metadata.gz: 57bad5eacd868d37784c151364010cdfb82f483c42e12128fc58355416720abed4303d9c970c75a5756d30a897c809442b847bc2a0fd6c05eee3c3402b13d598
7
- data.tar.gz: cd33c2871b018ba5f18339781ef3fb86521f2876ba7ae15f830b5ddbfc4de9207aea067722af6fc874123becad86bdb55b2af62f4c0c2ec6bf94c5c3d180bf02
6
+ metadata.gz: c6d4682db7446fb31837bddde8738626e1dc33f65c33390d44ce73ea5a56db040f07735fcf264bb9f27637ae11e2ca27feb980d403e8db0aa7e6afce0d41e63e
7
+ data.tar.gz: b66927ba5a60f918174a7cdebe4c57f6d8a5e4ec6af0d70f5079445c7101f645fd6704a2132148d44ab5eda83e8f4ce8f8b00c1691c66c46d0036dd59fca2c26
Binary file
@@ -0,0 +1,207 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kailash
4
+ # MCP (Model Context Protocol) module — Ruby bindings for the canonical
5
+ # MCP types exposed by the underlying `kailash_mcp` Rust crate.
6
+ #
7
+ # Four layers ship under this namespace:
8
+ #
9
+ # 1. **Info types** (defined in the native extension, mirror Python / Node):
10
+ # - `Kailash::Mcp::McpToolInfo` — `tools/list` entry
11
+ # - `Kailash::Mcp::McpResourceInfo` — `resources/list` entry
12
+ # - `Kailash::Mcp::ServerCapabilities` — `initialize` capability flags
13
+ # - `Kailash::Mcp::ServerInfo` — full `initialize` payload
14
+ #
15
+ # 2. **Elicitation** (gated on the `_gvl_release` build feature, default ON):
16
+ # - `Kailash::Mcp::ElicitationSystem` — MCP 2025-06-18 server→client
17
+ # `elicitation/create` round-trips
18
+ #
19
+ # 3. **Server / client / auth surface** (Wave-3c W3.5b + F15):
20
+ # - `Kailash::Mcp::McpServer` — catalog-backed MCP server
21
+ # - `Kailash::Mcp::McpClient` — in-memory client (pairs with McpServer)
22
+ # - `Kailash::Mcp::OAuth2Client` — OAuth 2.1 + PKCE client (sync flow-setup
23
+ # + async token redemption; see below)
24
+ # - `Kailash::Mcp::PermissionManager` — fine-grained scope→tool RBAC
25
+ #
26
+ # **Current W3.5b limitation (visible deferral, NOT a silent stub):**
27
+ #
28
+ # - **Tool-callback dispatch** — `McpServer.register_tool` accepts a Ruby
29
+ # block, but the tool invocation path through `_ruby_catalog_stub` echoes
30
+ # the request and does NOT yet route the Ruby block as the response body.
31
+ # Real Ruby-callback dispatch lands after the cross-binding W0-CALLBACK
32
+ # shard wires async dispatch through the capi callback ABI.
33
+ #
34
+ # **OAuth2Client surface (sync + async, F15 complete):**
35
+ #
36
+ # Sync surfaces (PKCE flow setup + state verification; see registration at
37
+ # `bindings/kailash-ruby/ext/kailash/src/mcp_server.rs:1714-1721`):
38
+ # `new`, `client_id`, `token_endpoint`, `build_authorization_request`,
39
+ # `verify_state`, plus lifecycle (`close`, `closed?`, `inspect`, `to_s`
40
+ # at `bindings/kailash-ruby/ext/kailash/src/mcp_server.rs:1735-1738`).
41
+ #
42
+ # Async surfaces (token redemption + revocation, F15; see registration at
43
+ # `bindings/kailash-ruby/ext/kailash/src/mcp_server.rs:1722-1734`):
44
+ # `redeem_authorization_code(code, verifier)` — RFC 6749 § 4.1.3
45
+ # `refresh_token(refresh_token)` — RFC 6749 § 6
46
+ # `cache_token(key, token_hash)` — persist for later retrieval
47
+ # `get_valid_token(key)` — auto-refresh on expiry
48
+ # `revoke_token(endpoint, token, hint)` — RFC 7009
49
+ #
50
+ # Each async method blocks on a per-call tokio runtime (mirrors the
51
+ # capi `build_runtime` pattern) and releases the GVL so other Ruby
52
+ # threads run concurrently. Token-response Hashes carry the canonical
53
+ # OAuth2 shape (`access_token`, `token_type`, `expires_in`,
54
+ # `refresh_token`, `scope`, `id_token`, `expires_at`).
55
+ #
56
+ # 4. **Exception hierarchy** (also defined by `elicitation_system`):
57
+ # - `Kailash::Mcp::RequestCancelled`
58
+ # - `Kailash::Mcp::SchemaValidation`
59
+ # - `Kailash::Mcp::ElicitationTimeout`
60
+ # - `Kailash::Mcp::TransportRebound`
61
+ #
62
+ # ## Examples
63
+ #
64
+ # Build a tool descriptor for a tools/list response:
65
+ #
66
+ # tool = Kailash::Mcp::McpToolInfo.new("search", "Search the web")
67
+ # tool.to_json
68
+ # # => '{"name":"search","description":"Search the web","inputSchema":{}}'
69
+ #
70
+ # Build a resource descriptor with keyword args:
71
+ #
72
+ # res = Kailash::Mcp::McpResourceInfo.new(
73
+ # "cfg://settings",
74
+ # "Settings",
75
+ # description: "Application settings",
76
+ # mime_type: "application/json",
77
+ # )
78
+ #
79
+ # Block-based server lifecycle:
80
+ #
81
+ # Kailash::Mcp::McpServer.open(name: "my-server", version: "1.0.0") do |srv|
82
+ # srv.register_tool(name: "search", description: "Search the web")
83
+ # srv.register_resource(uri: "doc://1", name: "Doc 1")
84
+ # # ... use srv ...
85
+ # end # srv automatically closed at block exit
86
+ #
87
+ module Mcp
88
+ # Keyword-arg convenience constructor for `McpResourceInfo`. The native
89
+ # `McpResourceInfo.new` now accepts keyword args directly; this helper
90
+ # is preserved for back-compat with code written against the previous
91
+ # API and as a documented entry point for the keyword form.
92
+ #
93
+ # @param uri [String] resource URI (required)
94
+ # @param name [String] human-readable name (required)
95
+ # @param description [String, nil] optional description
96
+ # @param mime_type [String, nil] optional MIME type
97
+ # @return [Kailash::Mcp::McpResourceInfo]
98
+ def self.resource(uri:, name:, description: nil, mime_type: nil)
99
+ McpResourceInfo.new(uri, name, description: description, mime_type: mime_type)
100
+ end
101
+
102
+ # Convenience: predicate-only summary of a `ServerCapabilities`. Returns
103
+ # a Hash with boolean values, useful for logging the server handshake.
104
+ #
105
+ # caps = Kailash::Mcp::ServerCapabilities.from_json('{"tools":{}}')
106
+ # Kailash::Mcp.capability_summary(caps)
107
+ # # => { tools: true, resources: false, prompts: false, elicitation: false }
108
+ #
109
+ # @param caps [Kailash::Mcp::ServerCapabilities]
110
+ # @return [Hash{Symbol => Boolean}]
111
+ def self.capability_summary(caps)
112
+ {
113
+ tools: caps.has_tools?,
114
+ resources: caps.has_resources?,
115
+ prompts: caps.has_prompts?,
116
+ elicitation: caps.has_elicitation?,
117
+ }
118
+ end
119
+
120
+ # `McpServer` block-based lifecycle (Ruby idiom matching File.open /
121
+ # Registry.open). Yields a fresh `McpServer` to the block and calls
122
+ # `close` automatically when the block returns. Returns the block's
123
+ # value.
124
+ #
125
+ # Kailash::Mcp::McpServer.open(name: "srv", version: "1.0") do |srv|
126
+ # srv.register_tool(name: "search", description: "...")
127
+ # srv
128
+ # end
129
+ #
130
+ # When called WITHOUT a block, returns the constructed `McpServer`
131
+ # (equivalent to `McpServer.new` — caller MUST `close` explicitly).
132
+ class McpServer
133
+ def self.open(*args, **kwargs)
134
+ srv = if kwargs.empty?
135
+ new(*args)
136
+ elsif args.empty?
137
+ new(kwargs)
138
+ else
139
+ new(*args, kwargs)
140
+ end
141
+ return srv unless block_given?
142
+
143
+ begin
144
+ yield srv
145
+ ensure
146
+ srv.close
147
+ end
148
+ end
149
+ end
150
+
151
+ # `McpClient` block-based lifecycle. Same shape as `McpServer.open`.
152
+ #
153
+ # Kailash::Mcp::McpClient.open(server: srv) do |client|
154
+ # # ... use client ...
155
+ # end
156
+ class McpClient
157
+ def self.open(*args, **kwargs)
158
+ client = if kwargs.empty?
159
+ new(*args)
160
+ elsif args.empty?
161
+ new(kwargs)
162
+ else
163
+ new(*args, kwargs)
164
+ end
165
+ return client unless block_given?
166
+
167
+ begin
168
+ yield client
169
+ ensure
170
+ client.close
171
+ end
172
+ end
173
+ end
174
+
175
+ # `OAuth2Client` block-based lifecycle.
176
+ #
177
+ # Kailash::Mcp::OAuth2Client.open(client_id: "...", token_endpoint: "...") do |oauth|
178
+ # # ... use oauth ...
179
+ # end
180
+ class OAuth2Client
181
+ def self.open(**kwargs, &_block)
182
+ oauth = new(kwargs)
183
+ return oauth unless block_given?
184
+
185
+ begin
186
+ yield oauth
187
+ ensure
188
+ oauth.close
189
+ end
190
+ end
191
+ end
192
+
193
+ # `PermissionManager` block-based lifecycle.
194
+ class PermissionManager
195
+ def self.open(&_block)
196
+ pm = new
197
+ return pm unless block_given?
198
+
199
+ begin
200
+ yield pm
201
+ ensure
202
+ pm.close
203
+ end
204
+ end
205
+ end
206
+ end
207
+ end
data/lib/kailash.rb CHANGED
@@ -9,6 +9,13 @@ rescue LoadError
9
9
  require "kailash/kailash"
10
10
  end
11
11
 
12
+ # Pure-Ruby convenience layer on top of the native MCP type wrappers
13
+ # (Kailash::Mcp::McpToolInfo / McpResourceInfo / ServerCapabilities /
14
+ # ServerInfo are defined by the native extension; this file adds the
15
+ # keyword-arg helper `Kailash::Mcp.resource(...)` and a capability-
16
+ # summary helper for logging).
17
+ require_relative "kailash/mcp"
18
+
12
19
  module Kailash
13
20
  module Nexus
14
21
  # Typed exception a `handler_extract` callable raises to emit a
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kailash
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.3.0
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Kailash Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-05-16 00:00:00.000000000 Z
11
+ date: 2026-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -48,6 +48,7 @@ files:
48
48
  - README.md
49
49
  - lib/kailash.rb
50
50
  - lib/kailash/kailash.so
51
+ - lib/kailash/mcp.rb
51
52
  - lib/kailash/trust_plane.rb
52
53
  - lib/kailash/version.rb
53
54
  homepage: https://github.com/kailash/kailash