leash-sdk 0.3.0 → 0.3.1

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: 43e34f3d6e756f73f7612d2386e8e8db0b8db9ebcd02497e840617d5136ee83c
4
- data.tar.gz: b8065f2e37c1218b01c0dd88ef363694762359338167d9e2defa232976efe2d9
3
+ metadata.gz: 3ccdeebdeeb2eea92794836b7ae51f02cc1c048a3912483c8c410e662184c5f4
4
+ data.tar.gz: 9626c0261ec8d76cd14323b290c558be5df6707b0c7cdb6a7cc780feaeeee079
5
5
  SHA512:
6
- metadata.gz: cfedee526258e982cf6220618965ac55d7adfcb054ea325510ef74d174765eb956cb8e2eeefcb031ce02af5d8645cf239b9de61f23995cad5ae60139d97b74b3
7
- data.tar.gz: a6693f07510e34bd6f39fe4c0d3815a0266088b8cc7c8609d6075f4624be27f0d989384274efb2bf658ac60b3f42b33d2b5962f0550f6599f1787c40169e1e47
6
+ metadata.gz: 03d22fe090135500591a41e86aadb0fe90409a0b572f43d9671362ce989737e9f238a987d4665e6a32a0d1197c1e9fb21b97039e836cfc2d1d28cea9cf4938a3
7
+ data.tar.gz: 5a0c39178994eff5875f52793d772b52cc0f0304d0c17bd63e6f7fce742909b8ff373ec2545a121f30c4762d0712bb5bcbb09e23e7147c43f43e77294af00485
data/Gemfile CHANGED
@@ -3,3 +3,5 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
+
7
+ gem "minitest", ">= 5.0"
data/README.md CHANGED
@@ -49,6 +49,25 @@ end
49
49
  - custom integration calls
50
50
  - app env fetch and caching
51
51
 
52
+ ## Server Auth
53
+
54
+ The SDK includes helpers for authenticating users on the server side by reading
55
+ the `leash-auth` cookie set by the Leash platform.
56
+
57
+ ```ruby
58
+ # Rails / Sinatra
59
+ user = Leash::Auth.get_user(request)
60
+ # => #<Leash::User id="usr_123" email="alice@example.com" name="Alice">
61
+ ```
62
+
63
+ ## MCP Calls
64
+
65
+ Execute MCP-backed tools through the platform:
66
+
67
+ ```ruby
68
+ result = client.run_mcp(package: "@some/mcp-package", tool: "tool-name", args: { key: "value" })
69
+ ```
70
+
52
71
  ## Notes
53
72
 
54
73
  - `auth_token` should be a valid Leash platform JWT
data/leash-sdk.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/leash"
3
+ require_relative "lib/leash/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "leash-sdk"
@@ -139,6 +139,67 @@ module Leash
139
139
  url
140
140
  end
141
141
 
142
+ # Get the user's current access token for a provider -- built-in or
143
+ # org-registered (LEA-142). Lets you call third-party APIs directly
144
+ # without proxying every request through Leash. Refresh-on-expiry
145
+ # happens transparently on the platform side.
146
+ #
147
+ # @param provider [String] the provider slug (e.g. "slack", "gmail")
148
+ # @return [String] the access token
149
+ # @raise [Leash::NotConnectedError] if the user hasn't completed the OAuth flow
150
+ # @raise [Leash::TokenExpiredError] if the token is expired and cannot be refreshed
151
+ # @raise [Leash::Error] if the platform returns a non-success response
152
+ def get_access_token(provider)
153
+ uri = URI("#{@platform_url}/api/integrations/token")
154
+
155
+ request = Net::HTTP::Post.new(uri)
156
+ request["Content-Type"] = "application/json"
157
+ request["Authorization"] = "Bearer #{@auth_token}" if @auth_token
158
+ request["X-API-Key"] = @api_key if @api_key
159
+ request.body = { provider: provider }.to_json
160
+
161
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
162
+ http.request(request)
163
+ end
164
+
165
+ data = JSON.parse(response.body)
166
+
167
+ unless data["success"]
168
+ raise_error(data)
169
+ end
170
+
171
+ data["data"]["accessToken"]
172
+ end
173
+
174
+ # Get the resolved config for a customer-registered MCP server (LEA-143).
175
+ # Returns the customer's MCP URL plus auth headers (e.g. +Authorization:
176
+ # Bearer ...+ for bearer-auth servers) -- feed this directly into your
177
+ # MCP client. Leash isn't on the MCP request path.
178
+ #
179
+ # @param slug [String] the MCP server slug
180
+ # @return [Hash] hash with "slug", "displayName", "url", and "headers"
181
+ # @raise [Leash::Error] if the platform returns a non-success response
182
+ # (e.g. code +unknown_mcp_server+)
183
+ def get_custom_mcp_config(slug)
184
+ uri = URI("#{@platform_url}/api/integrations/mcp-config/#{URI.encode_www_form_component(slug)}")
185
+
186
+ request = Net::HTTP::Get.new(uri)
187
+ request["Authorization"] = "Bearer #{@auth_token}" if @auth_token
188
+ request["X-API-Key"] = @api_key if @api_key
189
+
190
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
191
+ http.request(request)
192
+ end
193
+
194
+ data = JSON.parse(response.body)
195
+
196
+ unless data["success"]
197
+ raise_error(data)
198
+ end
199
+
200
+ data["data"]
201
+ end
202
+
142
203
  # Call any MCP server tool directly.
143
204
  #
144
205
  # @param package_name [String] the npm package name of the MCP server
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leash
4
+ VERSION = "0.3.1"
5
+ end
data/lib/leash.rb CHANGED
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "leash/version"
3
4
  require_relative "leash/integrations"
4
5
  require_relative "leash/auth"
5
-
6
- module Leash
7
- VERSION = "0.3.0"
8
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leash-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leash
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-19 00:00:00.000000000 Z
11
+ date: 2026-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -44,6 +44,7 @@ files:
44
44
  - lib/leash/errors.rb
45
45
  - lib/leash/gmail.rb
46
46
  - lib/leash/integrations.rb
47
+ - lib/leash/version.rb
47
48
  homepage: https://github.com/leash-build/leash-sdk-ruby
48
49
  licenses:
49
50
  - Apache-2.0