@portlesslabs/sdk 0.0.0-stage → 0.1.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.
- package/CHANGELOG.md +3 -0
- package/LICENSE +21 -0
- package/README.md +1112 -2
- package/dist/index.cjs +843 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +587 -0
- package/dist/index.d.ts +587 -0
- package/dist/index.js +826 -0
- package/dist/index.js.map +1 -0
- package/package.json +88 -4
package/README.md
CHANGED
|
@@ -1,3 +1,1113 @@
|
|
|
1
|
-
# Temporary Holding Version
|
|
2
1
|
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
<h2 align="center">
|
|
4
|
+
The official TypeScript client for the
|
|
5
|
+
<a href="https://www.initpbj.dev">Portless</a> MCP gateway.
|
|
6
|
+
</h2>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<img
|
|
10
|
+
src="https://purple-above-mite-195.mypinata.cloud/ipfs/bafybeifu4iz2g6dodnjmp44axjqpdyhuuw6bfr3mzf4qziags2m25n6pni"
|
|
11
|
+
alt="Portless"
|
|
12
|
+
width="100%"
|
|
13
|
+
/>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
<p align="center">
|
|
17
|
+
Call any MCP tool through one endpoint, with types, retries and safe defaults built in.
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
<p align="center">
|
|
23
|
+
<a href="https://www.npmjs.com/package/@portlesslabs/sdk"><img alt="npm" src="https://img.shields.io/npm/v/@portlesslabs/sdk?style=flat-square&color=10b981&label=npm"></a>
|
|
24
|
+
<a href="https://github.com/portlesslabs/sdk-js/actions/workflows/ci.yml"><img alt="CI" src="https://img.shields.io/github/actions/workflow/status/portlesslabs/sdk-js/ci.yml?branch=main&style=flat-square&label=CI"></a>
|
|
25
|
+
<a href="https://bundlejs.com/?q=@portlesslabs/sdk"><img alt="bundle size" src="https://img.shields.io/bundlejs/size/@portlesslabs/sdk?style=flat-square&color=3b82f6"></a>
|
|
26
|
+
<a href="./src/types.ts"><img alt="TypeScript" src="https://img.shields.io/badge/TypeScript-ready-3178c6?style=flat-square&logo=typescript&logoColor=white"></a>
|
|
27
|
+
<a href="./package.json"><img alt="zero dependencies" src="https://img.shields.io/badge/dependencies-0-10b981?style=flat-square"></a>
|
|
28
|
+
<a href="./LICENSE"><img alt="MIT license" src="https://img.shields.io/badge/license-MIT-64748b?style=flat-square"></a>
|
|
29
|
+
</p>
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
<p align="center">
|
|
34
|
+
|
|
35
|
+
<a href="https://www.initpbj.dev/docs"><b>Documentation</b></a> •
|
|
36
|
+
|
|
37
|
+
<a href="#quickstart"><b>Quickstart</b></a> •
|
|
38
|
+
|
|
39
|
+
<a href="./examples"><b>Examples</b></a> •
|
|
40
|
+
|
|
41
|
+
<a href="#api-reference"><b>API reference</b></a> •
|
|
42
|
+
|
|
43
|
+
<a href="./CHANGELOG.md"><b>Changelog</b></a>
|
|
44
|
+
|
|
45
|
+
</p>
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
<br>
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
## ⚡ At a glance
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
<table>
|
|
58
|
+
|
|
59
|
+
<tr>
|
|
60
|
+
|
|
61
|
+
<th width="50%">Install</th>
|
|
62
|
+
|
|
63
|
+
<th width="50%">Configure</th>
|
|
64
|
+
|
|
65
|
+
</tr>
|
|
66
|
+
|
|
67
|
+
<tr>
|
|
68
|
+
|
|
69
|
+
<td valign="top">
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
|
|
75
|
+
npm install @portlesslabs/sdk
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
</td>
|
|
82
|
+
|
|
83
|
+
<td valign="top">
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
|
|
89
|
+
export PORTLESS_API_KEY=pl_live_...
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
</td>
|
|
96
|
+
|
|
97
|
+
</tr>
|
|
98
|
+
|
|
99
|
+
<tr>
|
|
100
|
+
|
|
101
|
+
<th>Call a tool</th>
|
|
102
|
+
|
|
103
|
+
<th>What you get back</th>
|
|
104
|
+
|
|
105
|
+
</tr>
|
|
106
|
+
|
|
107
|
+
<tr>
|
|
108
|
+
|
|
109
|
+
<td valign="top">
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
|
|
115
|
+
import { Portless } from "@portlesslabs/sdk";
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
const portless = new Portless();
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
const call = await portless.tools.call(
|
|
124
|
+
|
|
125
|
+
"github.get_issue",
|
|
126
|
+
|
|
127
|
+
{ owner: "acme", repo: "app", issue_number: 1 },
|
|
128
|
+
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
console.log(call.json());
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
</td>
|
|
140
|
+
|
|
141
|
+
<td valign="top">
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
```jsonc
|
|
146
|
+
|
|
147
|
+
{
|
|
148
|
+
|
|
149
|
+
"number": 1,
|
|
150
|
+
|
|
151
|
+
"title": "Bug",
|
|
152
|
+
|
|
153
|
+
"state": "open"
|
|
154
|
+
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// plus: call.text, call.isError,
|
|
158
|
+
|
|
159
|
+
// call.latencyMs, call.result
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
</td>
|
|
166
|
+
|
|
167
|
+
</tr>
|
|
168
|
+
|
|
169
|
+
</table>
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
## ✨ Highlights
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
<table>
|
|
178
|
+
|
|
179
|
+
<tr>
|
|
180
|
+
|
|
181
|
+
<td width="33%" valign="top">
|
|
182
|
+
|
|
183
|
+
<h4>🔒 Typed end to end</h4>
|
|
184
|
+
|
|
185
|
+
Every request and response matches the gateway's <code>/api/v1</code> contract. No <code>any</code> anywhere.
|
|
186
|
+
|
|
187
|
+
</td>
|
|
188
|
+
|
|
189
|
+
<td width="33%" valign="top">
|
|
190
|
+
|
|
191
|
+
<h4>🪶 Zero dependencies</h4>
|
|
192
|
+
|
|
193
|
+
About 8 KB gzipped. Ships ESM, CJS and <code>.d.ts</code>.
|
|
194
|
+
|
|
195
|
+
</td>
|
|
196
|
+
|
|
197
|
+
<td width="33%" valign="top">
|
|
198
|
+
|
|
199
|
+
<h4>🌍 Runs everywhere</h4>
|
|
200
|
+
|
|
201
|
+
Node.js 18+, Bun, Deno, Cloudflare Workers and Vercel Edge.
|
|
202
|
+
|
|
203
|
+
</td>
|
|
204
|
+
|
|
205
|
+
</tr>
|
|
206
|
+
|
|
207
|
+
<tr>
|
|
208
|
+
|
|
209
|
+
<td width="33%" valign="top">
|
|
210
|
+
|
|
211
|
+
<h4>🛡️ Safe by default</h4>
|
|
212
|
+
|
|
213
|
+
Tool calls are never retried unless you opt in. Your key never appears in errors or logs.
|
|
214
|
+
|
|
215
|
+
</td>
|
|
216
|
+
|
|
217
|
+
<td width="33%" valign="top">
|
|
218
|
+
|
|
219
|
+
<h4>🔁 Resilient reads</h4>
|
|
220
|
+
|
|
221
|
+
Timeouts, cancellation, and backoff with jitter that honours <code>Retry-After</code>.
|
|
222
|
+
|
|
223
|
+
</td>
|
|
224
|
+
|
|
225
|
+
<td width="33%" valign="top">
|
|
226
|
+
|
|
227
|
+
<h4>🔌 MCP-ready</h4>
|
|
228
|
+
|
|
229
|
+
One line generates config for Claude, Cursor and VS Code.
|
|
230
|
+
|
|
231
|
+
</td>
|
|
232
|
+
|
|
233
|
+
</tr>
|
|
234
|
+
|
|
235
|
+
</table>
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
## 📚 Contents
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
<table>
|
|
244
|
+
|
|
245
|
+
<tr>
|
|
246
|
+
|
|
247
|
+
<td valign="top">
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
**Getting started**
|
|
252
|
+
|
|
253
|
+
- [What is Portless?](#what-is-portless)
|
|
254
|
+
|
|
255
|
+
- [Install](#install)
|
|
256
|
+
|
|
257
|
+
- [Quickstart](#quickstart)
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
**Guides**
|
|
262
|
+
|
|
263
|
+
- [Calling tools](#calling-tools)
|
|
264
|
+
|
|
265
|
+
- [Agent attribution](#agent-attribution)
|
|
266
|
+
|
|
267
|
+
- [Servers & tools](#servers-and-tools)
|
|
268
|
+
|
|
269
|
+
- [Using with MCP clients](#mcp-clients)
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
</td>
|
|
274
|
+
|
|
275
|
+
<td valign="top">
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
**Going to production**
|
|
280
|
+
|
|
281
|
+
- [Error handling](#error-handling)
|
|
282
|
+
|
|
283
|
+
- [Timeouts, retries & cancellation](#timeouts-retries)
|
|
284
|
+
|
|
285
|
+
- [Runtimes](#runtimes)
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
**Reference**
|
|
290
|
+
|
|
291
|
+
- [Configuration](#configuration)
|
|
292
|
+
|
|
293
|
+
- [API reference](#api-reference)
|
|
294
|
+
|
|
295
|
+
- [Limitations](#limitations)
|
|
296
|
+
|
|
297
|
+
- [Contributing, security & license](#contributing)
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
</td>
|
|
302
|
+
|
|
303
|
+
</tr>
|
|
304
|
+
|
|
305
|
+
</table>
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
<a id="what-is-portless"></a>
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
## 🧭 What is Portless?
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
[Portless](https://www.initpbj.dev) is an open-source gateway for the [Model Context Protocol](https://modelcontextprotocol.io) (MCP).
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
1. **Register** your MCP servers in the dashboard and choose which tools are switched on.
|
|
322
|
+
|
|
323
|
+
2. **Create** an API key, and optionally name your agents.
|
|
324
|
+
|
|
325
|
+
3. **Call** tools through one endpoint. Portless routes each call to the right server, adds that server's stored credentials, and logs it on the **Activity** page.
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
```mermaid
|
|
330
|
+
|
|
331
|
+
flowchart LR
|
|
332
|
+
|
|
333
|
+
A["🤖 Your agent<br/>(this SDK)"] -->|"tools.call()"| G{{"Portless gateway<br/>auth · credentials · logs"}}
|
|
334
|
+
|
|
335
|
+
C["💬 Claude / Cursor / VS Code"] -->|MCP| G
|
|
336
|
+
|
|
337
|
+
G --> S1["GitHub MCP"]
|
|
338
|
+
|
|
339
|
+
G --> S2["Linear MCP"]
|
|
340
|
+
|
|
341
|
+
G --> S3["Your MCP server"]
|
|
342
|
+
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
This SDK is a thin client for the gateway's HTTP API. It never talks to your MCP servers directly. 👉 [Read the docs](https://www.initpbj.dev/docs)
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
<a id="install"></a>
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
## 📦 Install
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
```sh
|
|
360
|
+
|
|
361
|
+
npm install @portlesslabs/sdk
|
|
362
|
+
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
<details>
|
|
368
|
+
|
|
369
|
+
<summary>pnpm · yarn · bun</summary>
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
```sh
|
|
374
|
+
|
|
375
|
+
pnpm add @portlesslabs/sdk
|
|
376
|
+
|
|
377
|
+
yarn add @portlesslabs/sdk
|
|
378
|
+
|
|
379
|
+
bun add @portlesslabs/sdk
|
|
380
|
+
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
</details>
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
<a id="quickstart"></a>
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
## 🚀 Quickstart
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
**1.** Create an API key in the [Portless dashboard](https://www.initpbj.dev). It starts with `pl_live_`.
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
**2.** Put it in your environment:
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
```sh
|
|
406
|
+
|
|
407
|
+
export PORTLESS_API_KEY=pl_live_...
|
|
408
|
+
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
**3.** List your tools and call one:
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
```ts
|
|
418
|
+
|
|
419
|
+
import { Portless } from "@portlesslabs/sdk";
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
const portless = new Portless(); // reads PORTLESS_API_KEY
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
const tools = await portless.tools.list({ enabled: true });
|
|
428
|
+
|
|
429
|
+
console.log(tools.map((t) => t.tool)); // ["github.get_issue", ...]
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
const call = await portless.tools.call("github.get_issue", { owner: "acme", repo: "app", issue_number: 1 });
|
|
434
|
+
|
|
435
|
+
console.log(call.text);
|
|
436
|
+
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
> [!TIP]
|
|
442
|
+
|
|
443
|
+
> More runnable examples are in [`examples/`](./examples).
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
<a id="calling-tools"></a>
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
## 🛠 Calling tools
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
Tools are named **`namespace.tool`**, using the namespace you gave the server in the dashboard. The MCP style `namespace__tool` works too. The SDK checks the name before sending anything.
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
| | Tool ran but failed (`isError: true`) |
|
|
460
|
+
|
|
461
|
+
| ---------------- | ------------------------------------------------------- |
|
|
462
|
+
|
|
463
|
+
| `tools.call()` | ✅ resolves, so check `call.isError` |
|
|
464
|
+
|
|
465
|
+
| `tools.run()` | ❌ throws `ToolExecutionError` (see `error.toolCall`) |
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
```ts
|
|
470
|
+
|
|
471
|
+
import { Portless, ToolExecutionError } from "@portlesslabs/sdk";
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
const portless = new Portless();
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
// call(): you inspect the result
|
|
480
|
+
|
|
481
|
+
const call = await portless.tools.call("github.get_issue", { owner: "acme", repo: "app", issue_number: 1 });
|
|
482
|
+
|
|
483
|
+
if (call.isError) {
|
|
484
|
+
|
|
485
|
+
console.error("tool failed:", call.text);
|
|
486
|
+
|
|
487
|
+
} else {
|
|
488
|
+
|
|
489
|
+
console.log(call.text); // all text parts, joined with "\n"
|
|
490
|
+
|
|
491
|
+
const issue = call.json<{ title: string }>(); // structuredContent, or JSON.parse(text)
|
|
492
|
+
|
|
493
|
+
console.log(issue.title, call.latencyMs);
|
|
494
|
+
|
|
495
|
+
console.log(call.result.content); // raw MCP content blocks
|
|
496
|
+
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
// run(): failures become exceptions
|
|
502
|
+
|
|
503
|
+
try {
|
|
504
|
+
|
|
505
|
+
const ok = await portless.tools.run("github.get_issue", { owner: "acme", repo: "app", issue_number: 1 });
|
|
506
|
+
|
|
507
|
+
console.log(ok.json());
|
|
508
|
+
|
|
509
|
+
} catch (error) {
|
|
510
|
+
|
|
511
|
+
if (error instanceof ToolExecutionError) console.error(error.toolCall.text);
|
|
512
|
+
|
|
513
|
+
else throw error;
|
|
514
|
+
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
> [!NOTE]
|
|
522
|
+
|
|
523
|
+
> A tool that runs and fails still gets **HTTP 200** from the gateway. `isError` is how you tell. Problems at the gateway itself, such as a disabled tool, an unknown tool or a server that's down, always throw a [`PortlessError`](#error-handling).
|
|
524
|
+
|
|
525
|
+
>
|
|
526
|
+
|
|
527
|
+
> `json<T>()` doesn't validate the data; `T` is only a type hint. Validate untrusted output yourself.
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
<p align="right"><sub><a href="#top">↑ back to top</a></sub></p>
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
<a id="agent-attribution"></a>
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
## 🏷 Agent attribution
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
Name your agents in the dashboard, then say which agent is calling. Each call then shows that agent on the **Activity** page. The gateway ignores names it doesn't know.
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
```ts
|
|
548
|
+
|
|
549
|
+
import { Portless } from "@portlesslabs/sdk";
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
const portless = new Portless({ agent: "ci-bot" }); // default for every request
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
await portless.tools.call("github.get_issue", { owner: "acme", repo: "app", issue_number: 1 }, { agent: "cursor" }); // per-call override wins
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
const me = await portless.me();
|
|
562
|
+
|
|
563
|
+
console.log(me.agentId); // resolved agent id, or null
|
|
564
|
+
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
<p align="right"><sub><a href="#top">↑ back to top</a></sub></p>
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
<a id="servers-and-tools"></a>
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
## 🗂 Listing and syncing servers & tools
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
```ts
|
|
582
|
+
|
|
583
|
+
const servers = await portless.servers.list();
|
|
584
|
+
|
|
585
|
+
for (const s of servers) console.log(s.namespace, s.transport, s.status);
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
// Re-read a server's tool list after changing it upstream
|
|
590
|
+
|
|
591
|
+
const { added, updated, missing } = await portless.servers.sync("srv_123");
|
|
592
|
+
|
|
593
|
+
console.log(added, updated, missing); // e.g. ["github.list_prs"]
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
const all = await portless.tools.list();
|
|
598
|
+
|
|
599
|
+
const enabled = await portless.tools.list({ enabled: true });
|
|
600
|
+
|
|
601
|
+
const disabled = await portless.tools.list({ enabled: false });
|
|
602
|
+
|
|
603
|
+
console.log(all.length, enabled.length, disabled.length);
|
|
604
|
+
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
`credentialHeaders` lists header **names** only. The gateway never returns credential values.
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
<p align="right"><sub><a href="#top">↑ back to top</a></sub></p>
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
<a id="mcp-clients"></a>
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
## 🔌 Using with MCP clients
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
Claude, Cursor and VS Code can connect straight to the gateway's MCP endpoint, where tools appear as `namespace__tool`. The SDK builds the config for you:
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
```ts
|
|
630
|
+
|
|
631
|
+
import { Portless } from "@portlesslabs/sdk";
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
const portless = new Portless();
|
|
636
|
+
|
|
637
|
+
console.log(portless.mcp.url); // https://www.initpbj.dev/api/v1/mcp
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
const config = portless.mcp.config({ name: "portless", agent: "cursor" });
|
|
642
|
+
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
> [!WARNING]
|
|
648
|
+
|
|
649
|
+
> **The config contains your secret API key.** Save it only in a local, git-ignored file. Never commit it, log it, or paste it into an issue. [`examples/mcp-config.ts`](./examples/mcp-config.ts) prints a redacted copy unless you pass `--reveal`.
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
<details>
|
|
654
|
+
|
|
655
|
+
<summary><b>Cursor</b> · <code>~/.cursor/mcp.json</code> (and other <code>mcpServers</code> clients)</summary>
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
```json
|
|
660
|
+
|
|
661
|
+
{
|
|
662
|
+
|
|
663
|
+
"mcpServers": {
|
|
664
|
+
|
|
665
|
+
"portless": {
|
|
666
|
+
|
|
667
|
+
"url": "https://www.initpbj.dev/api/v1/mcp",
|
|
668
|
+
|
|
669
|
+
"headers": { "Authorization": "Bearer pl_live_...", "X-Portless-Agent": "cursor" }
|
|
670
|
+
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
</details>
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
<details>
|
|
686
|
+
|
|
687
|
+
<summary><b>VS Code</b> · <code>.vscode/mcp.json</code></summary>
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
```json
|
|
692
|
+
|
|
693
|
+
{
|
|
694
|
+
|
|
695
|
+
"servers": {
|
|
696
|
+
|
|
697
|
+
"portless": {
|
|
698
|
+
|
|
699
|
+
"type": "http",
|
|
700
|
+
|
|
701
|
+
"url": "https://www.initpbj.dev/api/v1/mcp",
|
|
702
|
+
|
|
703
|
+
"headers": { "Authorization": "Bearer pl_live_..." }
|
|
704
|
+
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
</details>
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
<details>
|
|
720
|
+
|
|
721
|
+
<summary><b>Claude</b></summary>
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
Claude Code:
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
```sh
|
|
730
|
+
|
|
731
|
+
claude mcp add --transport http portless https://www.initpbj.dev/api/v1/mcp \
|
|
732
|
+
|
|
733
|
+
--header "Authorization: Bearer pl_live_..."
|
|
734
|
+
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
Claude Desktop accepts the same URL and header wherever your version lets you add a remote MCP server.
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
</details>
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
<p align="right"><sub><a href="#top">↑ back to top</a></sub></p>
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
<a id="error-handling"></a>
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
## 🚨 Error handling
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
Every error extends **`PortlessError`** and carries `status`, `code`, `requestId` and `cause`. The class is chosen by `code` first, then by HTTP status, so codes this version doesn't know about still land in a sensible class.
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
| Class | When | Example codes |
|
|
764
|
+
|
|
765
|
+
| --------------------- | -------------------------------------- | ---------------------------------------------------------------- |
|
|
766
|
+
|
|
767
|
+
| `AuthenticationError` | 401, or a missing or bad key at startup | `missing_api_key`, `invalid_api_key` |
|
|
768
|
+
|
|
769
|
+
| `PermissionError` | 403 | `tool_disabled` |
|
|
770
|
+
|
|
771
|
+
| `NotFoundError` | 404 | `tool_not_found`, `server_not_found` |
|
|
772
|
+
|
|
773
|
+
| `ValidationError` | 400 / 405 / 422, or rejected locally | `invalid_request`, `invalid_tool_name`, `invalid_arguments` |
|
|
774
|
+
|
|
775
|
+
| `UpstreamError` | 501 / 502: your MCP server failed | `transport_not_supported`, `upstream_error`, `upstream_unreachable` |
|
|
776
|
+
|
|
777
|
+
| `ServerError` | other 5xx | `internal_error`, `credentials_unavailable` |
|
|
778
|
+
|
|
779
|
+
| `ConnectionError` | no response (DNS, TCP, TLS) | `connection_error` |
|
|
780
|
+
|
|
781
|
+
| `TimeoutError` | the SDK's `timeoutMs` fired | `timeout` |
|
|
782
|
+
|
|
783
|
+
| `ToolExecutionError` | only from `tools.run()` on `isError` | `tool_error` |
|
|
784
|
+
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
```ts
|
|
788
|
+
|
|
789
|
+
import { AuthenticationError, PermissionError, Portless, PortlessError, UpstreamError } from "@portlesslabs/sdk";
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
const portless = new Portless();
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
|
|
797
|
+
try {
|
|
798
|
+
|
|
799
|
+
await portless.tools.run("local.read_file", { path: "README.md" });
|
|
800
|
+
|
|
801
|
+
} catch (error) {
|
|
802
|
+
|
|
803
|
+
if (error instanceof UpstreamError && error.code === "transport_not_supported") {
|
|
804
|
+
|
|
805
|
+
console.error("stdio servers can't be reached by the hosted gateway");
|
|
806
|
+
|
|
807
|
+
} else if (error instanceof PermissionError) {
|
|
808
|
+
|
|
809
|
+
console.error("switch the tool on in the dashboard");
|
|
810
|
+
|
|
811
|
+
} else if (error instanceof AuthenticationError) {
|
|
812
|
+
|
|
813
|
+
console.error("check PORTLESS_API_KEY");
|
|
814
|
+
|
|
815
|
+
} else if (error instanceof PortlessError) {
|
|
816
|
+
|
|
817
|
+
console.error(error.name, error.code, error.status, error.requestId);
|
|
818
|
+
|
|
819
|
+
} else {
|
|
820
|
+
|
|
821
|
+
throw error;
|
|
822
|
+
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
```
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
If an error response isn't JSON (for example an HTML 502 page from a proxy), `code` is `http_<status>`. Error messages, `toString()` and `toJSON()` **never contain your API key**, even if a server echoes it back.
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
<p align="right"><sub><a href="#top">↑ back to top</a></sub></p>
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
<a id="timeouts-retries"></a>
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
## ⏱️ Timeouts, retries and cancellation
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
| | Default | Notes |
|
|
848
|
+
|
|
849
|
+
| --- | --- | --- |
|
|
850
|
+
|
|
851
|
+
| **Timeout** | 60 s per request | Throws `TimeoutError`, never retried. Can be overridden per call. |
|
|
852
|
+
|
|
853
|
+
| **Retries for reads** | 2 (3 attempts in total) | `me()`, `servers.list()` and `tools.list()` retry on network errors and 502/503/504, with exponential backoff and jitter (300 ms base, 4 s cap). `Retry-After` takes precedence. |
|
|
854
|
+
|
|
855
|
+
| **Retries for tool calls** | **off** | A retried `create_issue` could create two issues. Turn on with `retry: true` only for tools you know are safe to repeat. `servers.sync()` is never retried. |
|
|
856
|
+
|
|
857
|
+
| **Cancellation** | | Pass an `AbortSignal`. The call rejects with the platform `AbortError`, and no retries follow. |
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
```ts
|
|
862
|
+
|
|
863
|
+
const controller = new AbortController();
|
|
864
|
+
|
|
865
|
+
setTimeout(() => controller.abort(), 5_000);
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
const call = await portless.tools.call(
|
|
870
|
+
|
|
871
|
+
"github.get_issue",
|
|
872
|
+
|
|
873
|
+
{ owner: "acme", repo: "app", issue_number: 1 },
|
|
874
|
+
|
|
875
|
+
{ retry: true, timeoutMs: 20_000, signal: controller.signal },
|
|
876
|
+
|
|
877
|
+
);
|
|
878
|
+
|
|
879
|
+
console.log(call.text);
|
|
880
|
+
|
|
881
|
+
```
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
<p align="right"><sub><a href="#top">↑ back to top</a></sub></p>
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
<a id="runtimes"></a>
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
## 🌍 Runtimes
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
<p>
|
|
898
|
+
|
|
899
|
+
<img alt="Node.js" src="https://img.shields.io/badge/Node.js_18+-339933?style=for-the-badge&logo=nodedotjs&logoColor=white">
|
|
900
|
+
|
|
901
|
+
<img alt="Bun" src="https://img.shields.io/badge/Bun-000000?style=for-the-badge&logo=bun&logoColor=white">
|
|
902
|
+
|
|
903
|
+
<img alt="Deno" src="https://img.shields.io/badge/Deno-000000?style=for-the-badge&logo=deno&logoColor=white">
|
|
904
|
+
|
|
905
|
+
<img alt="Cloudflare Workers" src="https://img.shields.io/badge/Workers-F38020?style=for-the-badge&logo=cloudflare&logoColor=white">
|
|
906
|
+
|
|
907
|
+
<img alt="Vercel Edge" src="https://img.shields.io/badge/Vercel_Edge-000000?style=for-the-badge&logo=vercel&logoColor=white">
|
|
908
|
+
|
|
909
|
+
</p>
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
| Runtime | Notes |
|
|
914
|
+
|
|
915
|
+
| --- | --- |
|
|
916
|
+
|
|
917
|
+
| **Node.js ≥ 18** | Works with both ESM `import` and CJS `require`. |
|
|
918
|
+
|
|
919
|
+
| **Bun · Deno** | `PORTLESS_API_KEY` is read from the environment (Deno needs `--allow-env`). |
|
|
920
|
+
|
|
921
|
+
| **Workers · Vercel Edge · Deno Deploy** | Pass `apiKey` from your secrets. See [`examples/edge-runtime.ts`](./examples/edge-runtime.ts). |
|
|
922
|
+
|
|
923
|
+
| **Browsers** | ⚠️ Works, but don't do it with a real key. |
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
> [!CAUTION]
|
|
928
|
+
|
|
929
|
+
> **Never ship a real API key to a browser.** Anyone can read it in devtools and call your tools with your stored credentials. Call Portless from your server or an edge function instead.
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
The SDK uses only `fetch`, `AbortController`, `URL` and `Headers`. It writes nothing to the console and sends no telemetry.
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
<p align="right"><sub><a href="#top">↑ back to top</a></sub></p>
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
<a id="configuration"></a>
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
## ⚙️ Configuration reference
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
```ts
|
|
950
|
+
|
|
951
|
+
import { Portless } from "@portlesslabs/sdk";
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
|
|
955
|
+
const portless = new Portless({
|
|
956
|
+
|
|
957
|
+
apiKey: "pl_live_...", // default: env PORTLESS_API_KEY
|
|
958
|
+
|
|
959
|
+
baseUrl: "https://www.initpbj.dev", // default: env PORTLESS_BASE_URL, then production
|
|
960
|
+
|
|
961
|
+
agent: "ci-bot", // default X-Portless-Agent
|
|
962
|
+
|
|
963
|
+
timeoutMs: 60_000, // per request
|
|
964
|
+
|
|
965
|
+
maxRetries: 2, // for reads only
|
|
966
|
+
|
|
967
|
+
fetch: globalThis.fetch, // custom fetch (tests, proxies)
|
|
968
|
+
|
|
969
|
+
headers: { "X-Trace-Id": "abc" }, // extra headers, can't override Authorization
|
|
970
|
+
|
|
971
|
+
});
|
|
972
|
+
|
|
973
|
+
console.log(portless.baseUrl);
|
|
974
|
+
|
|
975
|
+
```
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
| Option | Type | Default | Env var |
|
|
980
|
+
|
|
981
|
+
| --- | --- | --- | --- |
|
|
982
|
+
|
|
983
|
+
| `apiKey` | `string` | none, so the constructor throws `missing_api_key` | `PORTLESS_API_KEY` |
|
|
984
|
+
|
|
985
|
+
| `baseUrl` | `string` | `https://www.initpbj.dev` | `PORTLESS_BASE_URL` |
|
|
986
|
+
|
|
987
|
+
| `agent` | `string` | none | none |
|
|
988
|
+
|
|
989
|
+
| `timeoutMs` | `number` | `60000` | none |
|
|
990
|
+
|
|
991
|
+
| `maxRetries` | `number` | `2` | none |
|
|
992
|
+
|
|
993
|
+
| `fetch` | `(url, init?) => Promise<Response>` | global `fetch` | none |
|
|
994
|
+
|
|
995
|
+
| `headers` | `Record<string, string>` | `{}` | none |
|
|
996
|
+
|
|
997
|
+
|
|
998
|
+
|
|
999
|
+
Explicit options win over environment variables. `console.log(portless)` and `JSON.stringify(portless)` show the key as `pl_live_****`.
|
|
1000
|
+
|
|
1001
|
+
|
|
1002
|
+
|
|
1003
|
+
<p align="right"><sub><a href="#top">↑ back to top</a></sub></p>
|
|
1004
|
+
|
|
1005
|
+
|
|
1006
|
+
|
|
1007
|
+
<a id="api-reference"></a>
|
|
1008
|
+
|
|
1009
|
+
|
|
1010
|
+
|
|
1011
|
+
## 📖 API reference
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
|
|
1015
|
+
| Member | Returns |
|
|
1016
|
+
|
|
1017
|
+
| --- | --- |
|
|
1018
|
+
|
|
1019
|
+
| `new Portless(options?)` | `Portless` |
|
|
1020
|
+
|
|
1021
|
+
| `portless.me(opts?)` | `Promise<Me>` |
|
|
1022
|
+
|
|
1023
|
+
| `portless.servers.list(opts?)` | `Promise<Server[]>` |
|
|
1024
|
+
|
|
1025
|
+
| `portless.servers.sync(serverId, opts?)` | `Promise<SyncResult>` |
|
|
1026
|
+
|
|
1027
|
+
| `portless.tools.list({ enabled? }?)` | `Promise<Tool[]>` |
|
|
1028
|
+
|
|
1029
|
+
| `portless.tools.call(tool, args?, options?)` | `Promise<ToolCall>` |
|
|
1030
|
+
|
|
1031
|
+
| `portless.tools.run(tool, args?, options?)` | `Promise<ToolCall>`, throws on `isError` |
|
|
1032
|
+
|
|
1033
|
+
| `portless.mcp.url` | `string` |
|
|
1034
|
+
|
|
1035
|
+
| `portless.mcp.config({ name?, agent? }?)` | `McpClientConfig` ⚠️ contains the key |
|
|
1036
|
+
|
|
1037
|
+
| `parseToolName(name)` | `{ namespace, name, qualified }` |
|
|
1038
|
+
|
|
1039
|
+
|
|
1040
|
+
|
|
1041
|
+
<details>
|
|
1042
|
+
|
|
1043
|
+
<summary>Option and result types</summary>
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
|
|
1047
|
+
- `RequestOptions` = `{ signal?: AbortSignal; timeoutMs?: number }`
|
|
1048
|
+
|
|
1049
|
+
- `CallOptions` = `{ agent?: string; signal?: AbortSignal; timeoutMs?: number; retry?: boolean }`
|
|
1050
|
+
|
|
1051
|
+
- `ToolCall` = `{ tool; latencyMs; result: CallToolResult; isError: boolean; text: string; json<T>(): T }`
|
|
1052
|
+
|
|
1053
|
+
|
|
1054
|
+
|
|
1055
|
+
Also exported: `Me`, `Server`, `Tool`, `ToolServer`, `SyncResult`, `CallToolResult`, `ContentBlock` (`TextContent`, `ImageContent`, `AudioContent`, `ResourceLinkContent`, `EmbeddedResourceContent`, `UnknownContent`), `PortlessOptions`, `ListToolsOptions`, `McpClientConfig`, `Transport`, `ServerStatus`, `FetchLike`. Every type has TSDoc.
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
|
|
1059
|
+
</details>
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
|
|
1063
|
+
<p align="right"><sub><a href="#top">↑ back to top</a></sub></p>
|
|
1064
|
+
|
|
1065
|
+
|
|
1066
|
+
|
|
1067
|
+
<a id="limitations"></a>
|
|
1068
|
+
|
|
1069
|
+
|
|
1070
|
+
|
|
1071
|
+
## ⚠️ Limitations
|
|
1072
|
+
|
|
1073
|
+
|
|
1074
|
+
|
|
1075
|
+
- **stdio servers:** the hosted gateway can't start local processes, so calls to them fail with `UpstreamError` (`transport_not_supported`).
|
|
1076
|
+
|
|
1077
|
+
- **Gateway timeouts:** about 10 s to connect, about 30 s per upstream call and about 60 s per request. Slow upstreams fail at the gateway before the SDK's own timeout.
|
|
1078
|
+
|
|
1079
|
+
- **No caching:** responses are `Cache-Control: no-store`.
|
|
1080
|
+
|
|
1081
|
+
- **No MCP protocol in the SDK:** for streaming, resources and prompts, use a real MCP client with `portless.mcp.url`.
|
|
1082
|
+
|
|
1083
|
+
|
|
1084
|
+
|
|
1085
|
+
<p align="right"><sub><a href="#top">↑ back to top</a></sub></p>
|
|
1086
|
+
|
|
1087
|
+
|
|
1088
|
+
|
|
1089
|
+
<a id="contributing"></a>
|
|
1090
|
+
|
|
1091
|
+
|
|
1092
|
+
|
|
1093
|
+
## 🤝 Contributing, security and license
|
|
1094
|
+
|
|
1095
|
+
|
|
1096
|
+
|
|
1097
|
+
- **Contributing:** see [CONTRIBUTING.md](./CONTRIBUTING.md) for setup, tests and releases.
|
|
1098
|
+
|
|
1099
|
+
- **Security:** report vulnerabilities privately as described in [SECURITY.md](./SECURITY.md). **Never paste API keys into issues.**
|
|
1100
|
+
|
|
1101
|
+
- **License:** [MIT](./LICENSE) © Portless Labs
|
|
1102
|
+
|
|
1103
|
+
|
|
1104
|
+
|
|
1105
|
+
---
|
|
1106
|
+
|
|
1107
|
+
|
|
1108
|
+
|
|
1109
|
+
<div align="center">
|
|
1110
|
+
|
|
1111
|
+
<sub>Built with ❤️ by <a href="https://www.initpbj.dev">Portless Labs</a> · <a href="#top">Back to top ↑</a></sub>
|
|
1112
|
+
|
|
1113
|
+
</div>
|