@portlesslabs/sdk 0.0.0-stage → 0.0.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/dist/index.d.ts
ADDED
|
@@ -0,0 +1,587 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hand-written types for the Portless gateway HTTP API (`/api/v1`).
|
|
3
|
+
* They mirror the API contract exactly; see the README's API reference.
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* How the gateway reaches an upstream MCP server.
|
|
9
|
+
* `stdio` servers cannot be reached by the hosted gateway.
|
|
10
|
+
*/
|
|
11
|
+
type Transport = "http" | "sse" | "stdio";
|
|
12
|
+
/** Health of an upstream MCP server as last observed by the gateway. */
|
|
13
|
+
type ServerStatus = "healthy" | "degraded" | "offline";
|
|
14
|
+
/** Response of `GET /api/v1/me`: who the API key belongs to. */
|
|
15
|
+
interface Me {
|
|
16
|
+
/** Workspace the API key belongs to. */
|
|
17
|
+
workspace: string;
|
|
18
|
+
/** The API key used for the request (never includes the secret). */
|
|
19
|
+
key: {
|
|
20
|
+
/** API key id. */
|
|
21
|
+
id: string;
|
|
22
|
+
/** Human-readable key name set in the dashboard. */
|
|
23
|
+
name: string;
|
|
24
|
+
};
|
|
25
|
+
/** The agent the request was attributed to, or `null` if none (or an unknown name) was sent. */
|
|
26
|
+
agentId: string | null;
|
|
27
|
+
}
|
|
28
|
+
/** An upstream MCP server registered in the Portless dashboard. */
|
|
29
|
+
interface Server {
|
|
30
|
+
/** Server id; pass it to `servers.sync()`. */
|
|
31
|
+
id: string;
|
|
32
|
+
/** Display name. */
|
|
33
|
+
name: string;
|
|
34
|
+
/** Unique namespace; tool names are qualified as `namespace.tool`. */
|
|
35
|
+
namespace: string;
|
|
36
|
+
/** How the gateway connects to the server. */
|
|
37
|
+
transport: Transport;
|
|
38
|
+
/** Upstream endpoint URL (or command for stdio servers). */
|
|
39
|
+
endpoint: string;
|
|
40
|
+
/** Last observed health. */
|
|
41
|
+
status: ServerStatus;
|
|
42
|
+
/** Names of the credential headers the gateway injects. Values are never returned. */
|
|
43
|
+
credentialHeaders: string[];
|
|
44
|
+
/** Creation time, ISO 8601. */
|
|
45
|
+
createdAt: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Response of `POST /api/v1/servers/{id}/sync`.
|
|
49
|
+
* Entries are qualified tool names, e.g. `github.get_issue`.
|
|
50
|
+
*/
|
|
51
|
+
interface SyncResult {
|
|
52
|
+
/** Namespace of the synced server. */
|
|
53
|
+
server: string;
|
|
54
|
+
/** Tools discovered for the first time. */
|
|
55
|
+
added: string[];
|
|
56
|
+
/** Tools whose definition changed. */
|
|
57
|
+
updated: string[];
|
|
58
|
+
/** Tools known to Portless that the upstream no longer lists. */
|
|
59
|
+
missing: string[];
|
|
60
|
+
}
|
|
61
|
+
/** The server a {@link Tool} belongs to (summary). */
|
|
62
|
+
interface ToolServer {
|
|
63
|
+
/** Server id. */
|
|
64
|
+
id: string;
|
|
65
|
+
/** Server namespace. */
|
|
66
|
+
namespace: string;
|
|
67
|
+
/** Server display name. */
|
|
68
|
+
name: string;
|
|
69
|
+
/** Server transport. */
|
|
70
|
+
transport: Transport;
|
|
71
|
+
/** Server health. */
|
|
72
|
+
status: ServerStatus;
|
|
73
|
+
}
|
|
74
|
+
/** A tool exposed through the gateway. */
|
|
75
|
+
interface Tool {
|
|
76
|
+
/** Tool id. */
|
|
77
|
+
id: string;
|
|
78
|
+
/** Unqualified tool name as the upstream reports it, e.g. `get_issue`. */
|
|
79
|
+
name: string;
|
|
80
|
+
/** Tool description from the upstream. */
|
|
81
|
+
description: string;
|
|
82
|
+
/** Whether the tool is switched on in the dashboard. Disabled tools return 403. */
|
|
83
|
+
enabled: boolean;
|
|
84
|
+
/** Qualified name to pass to `tools.call()`, e.g. `github.get_issue`. */
|
|
85
|
+
tool: string;
|
|
86
|
+
/** The server that provides this tool. */
|
|
87
|
+
server: ToolServer;
|
|
88
|
+
}
|
|
89
|
+
/** Text content returned by a tool. */
|
|
90
|
+
interface TextContent {
|
|
91
|
+
/** Discriminator. */
|
|
92
|
+
type: "text";
|
|
93
|
+
/** The text. */
|
|
94
|
+
text: string;
|
|
95
|
+
/** Optional MCP annotations and metadata. */
|
|
96
|
+
[key: string]: unknown;
|
|
97
|
+
}
|
|
98
|
+
/** Base64 image content returned by a tool. */
|
|
99
|
+
interface ImageContent {
|
|
100
|
+
/** Discriminator. */
|
|
101
|
+
type: "image";
|
|
102
|
+
/** Base64-encoded image bytes. */
|
|
103
|
+
data: string;
|
|
104
|
+
/** MIME type, e.g. `image/png`. */
|
|
105
|
+
mimeType: string;
|
|
106
|
+
/** Optional MCP annotations and metadata. */
|
|
107
|
+
[key: string]: unknown;
|
|
108
|
+
}
|
|
109
|
+
/** Base64 audio content returned by a tool. */
|
|
110
|
+
interface AudioContent {
|
|
111
|
+
/** Discriminator. */
|
|
112
|
+
type: "audio";
|
|
113
|
+
/** Base64-encoded audio bytes. */
|
|
114
|
+
data: string;
|
|
115
|
+
/** MIME type, e.g. `audio/wav`. */
|
|
116
|
+
mimeType: string;
|
|
117
|
+
/** Optional MCP annotations and metadata. */
|
|
118
|
+
[key: string]: unknown;
|
|
119
|
+
}
|
|
120
|
+
/** A link to a resource the client may fetch separately. */
|
|
121
|
+
interface ResourceLinkContent {
|
|
122
|
+
/** Discriminator. */
|
|
123
|
+
type: "resource_link";
|
|
124
|
+
/** Resource URI. */
|
|
125
|
+
uri: string;
|
|
126
|
+
/** Optional resource name. */
|
|
127
|
+
name?: string;
|
|
128
|
+
/** Other MCP fields (title, description, mimeType, annotations, ...). */
|
|
129
|
+
[key: string]: unknown;
|
|
130
|
+
}
|
|
131
|
+
/** Contents of an embedded resource. */
|
|
132
|
+
interface ResourceContents {
|
|
133
|
+
/** Resource URI. */
|
|
134
|
+
uri: string;
|
|
135
|
+
/** MIME type, if known. */
|
|
136
|
+
mimeType?: string;
|
|
137
|
+
/** Text contents (text resources). */
|
|
138
|
+
text?: string;
|
|
139
|
+
/** Base64 contents (binary resources). */
|
|
140
|
+
blob?: string;
|
|
141
|
+
/** Other MCP fields. */
|
|
142
|
+
[key: string]: unknown;
|
|
143
|
+
}
|
|
144
|
+
/** A resource embedded directly in the tool result. */
|
|
145
|
+
interface EmbeddedResourceContent {
|
|
146
|
+
/** Discriminator. */
|
|
147
|
+
type: "resource";
|
|
148
|
+
/** The embedded resource. */
|
|
149
|
+
resource: ResourceContents;
|
|
150
|
+
/** Optional MCP annotations and metadata. */
|
|
151
|
+
[key: string]: unknown;
|
|
152
|
+
}
|
|
153
|
+
/** Any content type this SDK version doesn't know about yet (forward compatibility). */
|
|
154
|
+
interface UnknownContent {
|
|
155
|
+
/** Content type. */
|
|
156
|
+
type: string;
|
|
157
|
+
/** Content fields. */
|
|
158
|
+
[key: string]: unknown;
|
|
159
|
+
}
|
|
160
|
+
/** One content block of a {@link CallToolResult}. */
|
|
161
|
+
type ContentBlock = TextContent | ImageContent | AudioContent | ResourceLinkContent | EmbeddedResourceContent | UnknownContent;
|
|
162
|
+
/** The MCP `CallToolResult` exactly as the upstream server returned it. */
|
|
163
|
+
interface CallToolResult {
|
|
164
|
+
/** Content blocks. */
|
|
165
|
+
content: ContentBlock[];
|
|
166
|
+
/** Structured (JSON) output, if the tool declares an output schema. */
|
|
167
|
+
structuredContent?: Record<string, unknown>;
|
|
168
|
+
/** `true` when the tool ran but failed. The HTTP status is still 200. */
|
|
169
|
+
isError?: boolean;
|
|
170
|
+
/** MCP metadata. */
|
|
171
|
+
_meta?: Record<string, unknown>;
|
|
172
|
+
}
|
|
173
|
+
/** Raw response body of `POST /api/v1/tools/call`. */
|
|
174
|
+
interface ToolCallResponse {
|
|
175
|
+
/** Qualified tool name that was called. */
|
|
176
|
+
tool: string;
|
|
177
|
+
/** Gateway-measured latency of the upstream call, in milliseconds. */
|
|
178
|
+
latencyMs: number;
|
|
179
|
+
/** The upstream result. */
|
|
180
|
+
result: CallToolResult;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* A `fetch`-compatible function. The global `fetch` of every supported runtime satisfies it.
|
|
184
|
+
* The SDK always calls it with an absolute URL string.
|
|
185
|
+
*/
|
|
186
|
+
type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
|
|
187
|
+
/** Options for `new Portless(options)`. */
|
|
188
|
+
interface PortlessOptions {
|
|
189
|
+
/**
|
|
190
|
+
* API key (`pl_live_...`). Defaults to the `PORTLESS_API_KEY` environment variable.
|
|
191
|
+
* Never ship a real key to browser code: anyone who can open devtools can read it.
|
|
192
|
+
*/
|
|
193
|
+
apiKey?: string;
|
|
194
|
+
/**
|
|
195
|
+
* Gateway base URL. Defaults to `PORTLESS_BASE_URL`, then `https://www.initpbj.dev`.
|
|
196
|
+
* Trailing slashes are removed.
|
|
197
|
+
*/
|
|
198
|
+
baseUrl?: string;
|
|
199
|
+
/**
|
|
200
|
+
* Default agent name or id, sent as `X-Portless-Agent` on every request.
|
|
201
|
+
* The gateway ignores names it doesn't know.
|
|
202
|
+
*/
|
|
203
|
+
agent?: string;
|
|
204
|
+
/** Per-request timeout in milliseconds (each attempt). Default `60000`. */
|
|
205
|
+
timeoutMs?: number;
|
|
206
|
+
/** Retries for idempotent requests (GETs) on network errors and 502/503/504. Default `2`. */
|
|
207
|
+
maxRetries?: number;
|
|
208
|
+
/** Custom `fetch` (testing, proxies). Defaults to the global `fetch`. */
|
|
209
|
+
fetch?: FetchLike;
|
|
210
|
+
/** Extra headers sent on every request. They cannot override `Authorization`. */
|
|
211
|
+
headers?: Record<string, string>;
|
|
212
|
+
}
|
|
213
|
+
/** Per-call options for `tools.call()` and `tools.run()`. */
|
|
214
|
+
interface CallOptions {
|
|
215
|
+
/** Agent name or id for this call; overrides the client's default `agent`. */
|
|
216
|
+
agent?: string;
|
|
217
|
+
/** Abort the call. Rejects with the signal's reason (an `AbortError` by default). */
|
|
218
|
+
signal?: AbortSignal;
|
|
219
|
+
/** Timeout for this call in milliseconds; overrides the client's `timeoutMs`. */
|
|
220
|
+
timeoutMs?: number;
|
|
221
|
+
/**
|
|
222
|
+
* Retry on network errors and 502/503/504. Default `false`, because tool calls may
|
|
223
|
+
* have side effects (a retried "create issue" can create two issues).
|
|
224
|
+
* Only enable it for idempotent tools.
|
|
225
|
+
*/
|
|
226
|
+
retry?: boolean;
|
|
227
|
+
}
|
|
228
|
+
/** Options for `tools.list()`. */
|
|
229
|
+
interface ListToolsOptions {
|
|
230
|
+
/** `true`: only enabled tools. `false`: only disabled tools. Omit: all tools. */
|
|
231
|
+
enabled?: boolean;
|
|
232
|
+
}
|
|
233
|
+
/** Options for request methods other than tool calls. */
|
|
234
|
+
interface RequestOptions {
|
|
235
|
+
/** Abort the request. */
|
|
236
|
+
signal?: AbortSignal;
|
|
237
|
+
/** Timeout for this request in milliseconds. */
|
|
238
|
+
timeoutMs?: number;
|
|
239
|
+
}
|
|
240
|
+
/** Options for `mcp.config()`. */
|
|
241
|
+
interface McpConfigOptions {
|
|
242
|
+
/** Key under `mcpServers`. Default `"portless"`. */
|
|
243
|
+
name?: string;
|
|
244
|
+
/** Agent to attribute MCP calls to. Defaults to the client's `agent`, if any. */
|
|
245
|
+
agent?: string;
|
|
246
|
+
}
|
|
247
|
+
/** One MCP server entry in an MCP client config. */
|
|
248
|
+
interface McpServerConfig {
|
|
249
|
+
/** Streamable HTTP endpoint: `${baseUrl}/api/v1/mcp`. */
|
|
250
|
+
url: string;
|
|
251
|
+
/** Headers the MCP client must send. **Contains the secret API key.** */
|
|
252
|
+
headers: {
|
|
253
|
+
/** `Bearer pl_live_...` — the secret API key. */
|
|
254
|
+
Authorization: string;
|
|
255
|
+
/** Optional agent attribution. */
|
|
256
|
+
"X-Portless-Agent"?: string;
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* MCP client configuration (Claude, Cursor, ...).
|
|
261
|
+
* **This object contains your secret API key.** Do not commit it, log it, or send it to a browser.
|
|
262
|
+
*/
|
|
263
|
+
interface McpClientConfig {
|
|
264
|
+
/** Server entries keyed by name. */
|
|
265
|
+
mcpServers: Record<string, McpServerConfig>;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* The HTTP layer around `fetch`.
|
|
270
|
+
*
|
|
271
|
+
* Adds auth and client headers, enforces timeouts, forwards cancellation, retries
|
|
272
|
+
* idempotent requests and turns non-2xx responses into typed errors.
|
|
273
|
+
*/
|
|
274
|
+
|
|
275
|
+
/** Resolved client configuration used by {@link HttpClient}. */
|
|
276
|
+
interface HttpClientConfig {
|
|
277
|
+
apiKey: string;
|
|
278
|
+
baseUrl: string;
|
|
279
|
+
agent: string | undefined;
|
|
280
|
+
timeoutMs: number;
|
|
281
|
+
maxRetries: number;
|
|
282
|
+
fetch: FetchLike;
|
|
283
|
+
headers: Record<string, string>;
|
|
284
|
+
}
|
|
285
|
+
/** One logical API request (possibly several attempts). */
|
|
286
|
+
interface HttpRequest {
|
|
287
|
+
method: "GET" | "POST";
|
|
288
|
+
/** Path below the base URL, starting with `/api/v1`. */
|
|
289
|
+
path: string;
|
|
290
|
+
query?: Record<string, string>;
|
|
291
|
+
/** JSON body. `undefined` sends no body. */
|
|
292
|
+
body?: unknown;
|
|
293
|
+
agent?: string | undefined;
|
|
294
|
+
signal?: AbortSignal | undefined;
|
|
295
|
+
timeoutMs?: number | undefined;
|
|
296
|
+
/** Retry transient failures. Defaults to `true` for GET, `false` otherwise. */
|
|
297
|
+
retry?: boolean | undefined;
|
|
298
|
+
}
|
|
299
|
+
/** Redacted form of an API key, safe for output. */
|
|
300
|
+
declare const REDACTED_KEY = "pl_live_****";
|
|
301
|
+
/** Fetch wrapper: auth headers, timeouts, cancellation, retries and error mapping. */
|
|
302
|
+
declare class HttpClient {
|
|
303
|
+
#private;
|
|
304
|
+
constructor(config: HttpClientConfig);
|
|
305
|
+
/** Performs the request, retrying when allowed, and returns the parsed JSON body. */
|
|
306
|
+
request<T>(req: HttpRequest): Promise<T>;
|
|
307
|
+
/** Removes the API key from any text. */
|
|
308
|
+
redact(text: string): string;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* `portless.mcp`: config helpers for MCP clients (Claude, Cursor, VS Code).
|
|
313
|
+
*/
|
|
314
|
+
|
|
315
|
+
/** Helpers for pointing MCP clients (Claude, Cursor, VS Code) at the gateway. No MCP dependency. */
|
|
316
|
+
declare class McpResource {
|
|
317
|
+
#private;
|
|
318
|
+
constructor(apiKey: string, baseUrl: string, agent: string | undefined);
|
|
319
|
+
/** The Streamable HTTP MCP endpoint: `${baseUrl}/api/v1/mcp`. */
|
|
320
|
+
get url(): string;
|
|
321
|
+
/**
|
|
322
|
+
* Builds an `mcpServers` config block for MCP clients.
|
|
323
|
+
*
|
|
324
|
+
* **The returned object CONTAINS YOUR SECRET API KEY** in `headers.Authorization`.
|
|
325
|
+
* Write it only to local, git-ignored config files. Never log it, commit it,
|
|
326
|
+
* or send it to a browser.
|
|
327
|
+
*/
|
|
328
|
+
config(options?: McpConfigOptions): McpClientConfig;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* `portless.servers`: list and sync the workspace's upstream MCP servers.
|
|
333
|
+
*/
|
|
334
|
+
|
|
335
|
+
/** Upstream MCP servers registered in the dashboard. */
|
|
336
|
+
declare class ServersResource {
|
|
337
|
+
#private;
|
|
338
|
+
constructor(http: HttpClient);
|
|
339
|
+
/** Lists the workspace's servers. Retried on transient failures. */
|
|
340
|
+
list(options?: RequestOptions): Promise<Server[]>;
|
|
341
|
+
/**
|
|
342
|
+
* Re-reads the server's tool list from the upstream and updates Portless.
|
|
343
|
+
* Not retried automatically.
|
|
344
|
+
*/
|
|
345
|
+
sync(serverId: string, options?: RequestOptions): Promise<SyncResult>;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* `ToolCall`: the result of `tools.call()` with `isError`, `text` and `json()` helpers.
|
|
350
|
+
*/
|
|
351
|
+
|
|
352
|
+
/** The result of `tools.call()`: the raw gateway response plus convenience accessors. */
|
|
353
|
+
declare class ToolCall {
|
|
354
|
+
/** Qualified name of the tool that ran, e.g. `github.get_issue`. */
|
|
355
|
+
readonly tool: string;
|
|
356
|
+
/** Gateway-measured upstream latency in milliseconds. */
|
|
357
|
+
readonly latencyMs: number;
|
|
358
|
+
/** The MCP result exactly as the upstream returned it. */
|
|
359
|
+
readonly result: CallToolResult;
|
|
360
|
+
constructor(response: ToolCallResponse);
|
|
361
|
+
/** `true` when the tool ran but reported failure (`result.isError === true`). */
|
|
362
|
+
get isError(): boolean;
|
|
363
|
+
/** All `text` content parts joined with `"\n"`. Non-text parts are skipped. */
|
|
364
|
+
get text(): string;
|
|
365
|
+
/**
|
|
366
|
+
* The tool's JSON output: `structuredContent` when present, otherwise `JSON.parse(text)`.
|
|
367
|
+
* The type parameter is not validated at runtime.
|
|
368
|
+
*
|
|
369
|
+
* @throws {@link PortlessError} with code `invalid_json` when there is no structured content and
|
|
370
|
+
* the text is not valid JSON.
|
|
371
|
+
*/
|
|
372
|
+
json<T = unknown>(): T;
|
|
373
|
+
/** JSON form: the gateway response plus `isError` and `text`. */
|
|
374
|
+
toJSON(): ToolCallResponse & {
|
|
375
|
+
isError: boolean;
|
|
376
|
+
text: string;
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* `portless.tools`: list tools, and call them through the gateway.
|
|
382
|
+
*/
|
|
383
|
+
|
|
384
|
+
/** Tools exposed through the gateway. */
|
|
385
|
+
declare class ToolsResource {
|
|
386
|
+
#private;
|
|
387
|
+
constructor(http: HttpClient);
|
|
388
|
+
/**
|
|
389
|
+
* Lists tools. `{ enabled: true }` asks the gateway for enabled tools only;
|
|
390
|
+
* `{ enabled: false }` returns only disabled tools. Retried on transient failures.
|
|
391
|
+
*/
|
|
392
|
+
list(options?: ListToolsOptions & RequestOptions): Promise<Tool[]>;
|
|
393
|
+
/**
|
|
394
|
+
* Calls a tool through the gateway. A tool that ran but failed resolves normally with
|
|
395
|
+
* `isError: true`; use {@link ToolsResource.run} to throw instead.
|
|
396
|
+
*
|
|
397
|
+
* Not retried unless `options.retry` is `true`, because tool calls may have side effects.
|
|
398
|
+
*
|
|
399
|
+
* @param tool - `"namespace.tool"` or `"namespace__tool"`.
|
|
400
|
+
* @param args - Tool arguments (a JSON object).
|
|
401
|
+
*/
|
|
402
|
+
call(tool: string, args?: Record<string, unknown>, options?: CallOptions): Promise<ToolCall>;
|
|
403
|
+
/**
|
|
404
|
+
* Like {@link ToolsResource.call}, but throws {@link ToolExecutionError} when the tool
|
|
405
|
+
* returns `isError: true`. The call is available as `error.toolCall`.
|
|
406
|
+
*/
|
|
407
|
+
run(tool: string, args?: Record<string, unknown>, options?: CallOptions): Promise<ToolCall>;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* The `Portless` client.
|
|
412
|
+
*
|
|
413
|
+
* Resolves options and environment variables, validates the API key and base URL,
|
|
414
|
+
* and wires the resources (`servers`, `tools`, `mcp`) to one shared HTTP client.
|
|
415
|
+
*/
|
|
416
|
+
|
|
417
|
+
/** Production gateway. */
|
|
418
|
+
declare const DEFAULT_BASE_URL = "https://www.initpbj.dev";
|
|
419
|
+
/** Every Portless API key starts with this prefix. */
|
|
420
|
+
declare const API_KEY_PREFIX = "pl_live_";
|
|
421
|
+
/** Safe, secret-free description of a client (used by `toJSON` and inspection). */
|
|
422
|
+
interface PortlessDescription {
|
|
423
|
+
baseUrl: string;
|
|
424
|
+
apiKey: typeof REDACTED_KEY;
|
|
425
|
+
agent?: string;
|
|
426
|
+
timeoutMs: number;
|
|
427
|
+
maxRetries: number;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Client for the Portless MCP gateway.
|
|
431
|
+
*
|
|
432
|
+
* ```ts
|
|
433
|
+
* const portless = new Portless(); // reads PORTLESS_API_KEY
|
|
434
|
+
* const call = await portless.tools.call("github.get_issue", {
|
|
435
|
+
* owner: "acme",
|
|
436
|
+
* repo: "app",
|
|
437
|
+
* issue_number: 1,
|
|
438
|
+
* });
|
|
439
|
+
* console.log(call.text);
|
|
440
|
+
* ```
|
|
441
|
+
*
|
|
442
|
+
* **Security:** do not construct a client with a real API key in browser code. Anything shipped
|
|
443
|
+
* to a browser can be read by its user. Call Portless from a server, Worker or edge function.
|
|
444
|
+
*/
|
|
445
|
+
declare class Portless {
|
|
446
|
+
#private;
|
|
447
|
+
/** Upstream MCP servers. */
|
|
448
|
+
readonly servers: ServersResource;
|
|
449
|
+
/** Tools: list, call, run. */
|
|
450
|
+
readonly tools: ToolsResource;
|
|
451
|
+
/** MCP client config helpers. */
|
|
452
|
+
readonly mcp: McpResource;
|
|
453
|
+
/** Normalised gateway base URL (no trailing slash). */
|
|
454
|
+
readonly baseUrl: string;
|
|
455
|
+
/** Default agent sent as `X-Portless-Agent`, if configured. */
|
|
456
|
+
readonly agent: string | undefined;
|
|
457
|
+
/** Per-request timeout in milliseconds. */
|
|
458
|
+
readonly timeoutMs: number;
|
|
459
|
+
/** Retries for idempotent requests. */
|
|
460
|
+
readonly maxRetries: number;
|
|
461
|
+
/**
|
|
462
|
+
* @throws {@link AuthenticationError} (`missing_api_key`) when no key is given or found in
|
|
463
|
+
* `PORTLESS_API_KEY`, or (`invalid_api_key`) when the key does not start with `pl_live_`.
|
|
464
|
+
* @throws {@link ValidationError} for other invalid options.
|
|
465
|
+
*/
|
|
466
|
+
constructor(options?: PortlessOptions);
|
|
467
|
+
/** `GET /api/v1/me`: the workspace, key and agent these credentials resolve to. */
|
|
468
|
+
me(options?: RequestOptions): Promise<Me>;
|
|
469
|
+
/** Secret-free JSON form. The API key is always shown as `pl_live_****`. */
|
|
470
|
+
toJSON(): PortlessDescription;
|
|
471
|
+
/** Secret-free string form. */
|
|
472
|
+
toString(): string;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Error classes, and the mapping from gateway responses to them.
|
|
477
|
+
*
|
|
478
|
+
* A response is classified by its `error.code` first and by its HTTP status second,
|
|
479
|
+
* so unknown codes still land in a sensible class.
|
|
480
|
+
*/
|
|
481
|
+
|
|
482
|
+
/** Options accepted by every {@link PortlessError} constructor. */
|
|
483
|
+
interface PortlessErrorOptions {
|
|
484
|
+
/** Machine-readable error code, e.g. `tool_disabled`. */
|
|
485
|
+
code: string;
|
|
486
|
+
/** HTTP status, when the error came from a response. */
|
|
487
|
+
status?: number | undefined;
|
|
488
|
+
/** Request id from the gateway's response headers, if present. */
|
|
489
|
+
requestId?: string | undefined;
|
|
490
|
+
/** Underlying error. */
|
|
491
|
+
cause?: unknown;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Base class of every error thrown by the SDK.
|
|
495
|
+
* Messages never contain the API key.
|
|
496
|
+
*/
|
|
497
|
+
declare class PortlessError extends Error {
|
|
498
|
+
name: string;
|
|
499
|
+
/** HTTP status, when the error came from a gateway response. */
|
|
500
|
+
readonly status: number | undefined;
|
|
501
|
+
/** Machine-readable error code (the gateway's `error.code`, or an SDK code for local errors). */
|
|
502
|
+
readonly code: string;
|
|
503
|
+
/** Gateway request id, useful when contacting support. */
|
|
504
|
+
readonly requestId: string | undefined;
|
|
505
|
+
constructor(message: string, options: PortlessErrorOptions);
|
|
506
|
+
/** A JSON-safe summary (no stack, no cause). */
|
|
507
|
+
toJSON(): {
|
|
508
|
+
name: string;
|
|
509
|
+
message: string;
|
|
510
|
+
code: string;
|
|
511
|
+
status?: number;
|
|
512
|
+
requestId?: string;
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* 401: missing, unknown or revoked API key (`missing_api_key`, `invalid_api_key`).
|
|
517
|
+
* Also thrown by the constructor when no valid key is configured.
|
|
518
|
+
*/
|
|
519
|
+
declare class AuthenticationError extends PortlessError {
|
|
520
|
+
name: string;
|
|
521
|
+
}
|
|
522
|
+
/** 403: the tool is switched off in the dashboard (`tool_disabled`). */
|
|
523
|
+
declare class PermissionError extends PortlessError {
|
|
524
|
+
name: string;
|
|
525
|
+
}
|
|
526
|
+
/** 404: unknown tool or server (`tool_not_found`, `server_not_found`). */
|
|
527
|
+
declare class NotFoundError extends PortlessError {
|
|
528
|
+
name: string;
|
|
529
|
+
}
|
|
530
|
+
/** 400 / 405 / 422 from the gateway, or input rejected locally before sending. */
|
|
531
|
+
declare class ValidationError extends PortlessError {
|
|
532
|
+
name: string;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* 501 / 502: the upstream MCP server could not be used.
|
|
536
|
+
* Check `code`: `transport_not_supported` (stdio server, 501), `upstream_error`
|
|
537
|
+
* or `upstream_unreachable`.
|
|
538
|
+
*/
|
|
539
|
+
declare class UpstreamError extends PortlessError {
|
|
540
|
+
name: string;
|
|
541
|
+
}
|
|
542
|
+
/** Any other 5xx from the gateway (`credentials_unavailable`, `internal_error`, 503, 504, ...). */
|
|
543
|
+
declare class ServerError extends PortlessError {
|
|
544
|
+
name: string;
|
|
545
|
+
}
|
|
546
|
+
/** The request never got a response: DNS, TCP, TLS or similar network failure. */
|
|
547
|
+
declare class ConnectionError extends PortlessError {
|
|
548
|
+
name: string;
|
|
549
|
+
}
|
|
550
|
+
/** The SDK's own timeout (`timeoutMs`) fired. Not thrown for user aborts. */
|
|
551
|
+
declare class TimeoutError extends PortlessError {
|
|
552
|
+
name: string;
|
|
553
|
+
}
|
|
554
|
+
/** Thrown only by `tools.run()` when the tool ran but returned `isError: true`. */
|
|
555
|
+
declare class ToolExecutionError extends PortlessError {
|
|
556
|
+
name: string;
|
|
557
|
+
/** The full call, including `result` and `text`. */
|
|
558
|
+
readonly toolCall: ToolCall;
|
|
559
|
+
constructor(message: string, options: PortlessErrorOptions & {
|
|
560
|
+
toolCall: ToolCall;
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Parsing and validation of qualified tool names (`namespace.tool` or `namespace__tool`).
|
|
566
|
+
*/
|
|
567
|
+
/** A validated tool name. */
|
|
568
|
+
interface ParsedToolName {
|
|
569
|
+
/** Server namespace, e.g. `github`. */
|
|
570
|
+
namespace: string;
|
|
571
|
+
/** Tool name within the namespace, e.g. `get_issue`. */
|
|
572
|
+
name: string;
|
|
573
|
+
/** Canonical qualified form sent to the gateway: `namespace.name`. */
|
|
574
|
+
qualified: string;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Parses `namespace.tool` or `namespace__tool`. The namespace ends at the first separator
|
|
578
|
+
* (whichever of `.` or `__` comes first), so tool names may themselves contain `.` or `__`.
|
|
579
|
+
*
|
|
580
|
+
* @throws {@link ValidationError} with code `invalid_tool_name` when the shape is wrong.
|
|
581
|
+
*/
|
|
582
|
+
declare function parseToolName(input: unknown): ParsedToolName;
|
|
583
|
+
|
|
584
|
+
/** The SDK version. Generated from package.json by scripts/sync-version.mjs; do not edit. */
|
|
585
|
+
declare const VERSION = "0.0.0";
|
|
586
|
+
|
|
587
|
+
export { API_KEY_PREFIX, type AudioContent, AuthenticationError, type CallOptions, type CallToolResult, ConnectionError, type ContentBlock, DEFAULT_BASE_URL, type EmbeddedResourceContent, type FetchLike, type ImageContent, type ListToolsOptions, type McpClientConfig, type McpConfigOptions, McpResource, type McpServerConfig, type Me, NotFoundError, type ParsedToolName, PermissionError, Portless, type PortlessDescription, PortlessError, type PortlessErrorOptions, type PortlessOptions, type RequestOptions, type ResourceContents, type ResourceLinkContent, type Server, ServerError, type ServerStatus, ServersResource, type SyncResult, type TextContent, TimeoutError, type Tool, ToolCall, type ToolCallResponse, ToolExecutionError, type ToolServer, ToolsResource, type Transport, type UnknownContent, UpstreamError, VERSION, ValidationError, parseToolName };
|