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 +4 -4
- data/Gemfile +2 -0
- data/README.md +19 -0
- data/leash-sdk.gemspec +1 -1
- data/lib/leash/integrations.rb +61 -0
- data/lib/leash/version.rb +5 -0
- data/lib/leash.rb +1 -4
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3ccdeebdeeb2eea92794836b7ae51f02cc1c048a3912483c8c410e662184c5f4
|
|
4
|
+
data.tar.gz: 9626c0261ec8d76cd14323b290c558be5df6707b0c7cdb6a7cc780feaeeee079
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 03d22fe090135500591a41e86aadb0fe90409a0b572f43d9671362ce989737e9f238a987d4665e6a32a0d1197c1e9fb21b97039e836cfc2d1d28cea9cf4938a3
|
|
7
|
+
data.tar.gz: 5a0c39178994eff5875f52793d772b52cc0f0304d0c17bd63e6f7fce742909b8ff373ec2545a121f30c4762d0712bb5bcbb09e23e7147c43f43e77294af00485
|
data/Gemfile
CHANGED
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
data/lib/leash/integrations.rb
CHANGED
|
@@ -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
|
data/lib/leash.rb
CHANGED
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.
|
|
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-
|
|
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
|