@lushly-dev/afd-client 2.4.0 → 3.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.
Files changed (57) hide show
  1. package/README.md +51 -10
  2. package/dist/client-errors.d.ts +22 -1
  3. package/dist/client-errors.d.ts.map +1 -1
  4. package/dist/client-errors.js +76 -2
  5. package/dist/client-errors.js.map +1 -1
  6. package/dist/client.d.ts +50 -7
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/client.js +237 -16
  9. package/dist/client.js.map +1 -1
  10. package/dist/direct-approval.d.ts +12 -4
  11. package/dist/direct-approval.d.ts.map +1 -1
  12. package/dist/direct-approval.js +23 -6
  13. package/dist/direct-approval.js.map +1 -1
  14. package/dist/direct-timeout.d.ts.map +1 -1
  15. package/dist/direct-timeout.js +1 -0
  16. package/dist/direct-timeout.js.map +1 -1
  17. package/dist/direct-transport.d.ts.map +1 -1
  18. package/dist/direct-transport.js +24 -7
  19. package/dist/direct-transport.js.map +1 -1
  20. package/dist/direct-types.d.ts +46 -9
  21. package/dist/direct-types.d.ts.map +1 -1
  22. package/dist/direct.d.ts +10 -11
  23. package/dist/direct.d.ts.map +1 -1
  24. package/dist/direct.js +65 -13
  25. package/dist/direct.js.map +1 -1
  26. package/dist/handoff.d.ts.map +1 -1
  27. package/dist/handoff.js +1 -0
  28. package/dist/handoff.js.map +1 -1
  29. package/dist/index.d.ts +4 -4
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +2 -2
  32. package/dist/index.js.map +1 -1
  33. package/dist/result-parsing.d.ts +11 -3
  34. package/dist/result-parsing.d.ts.map +1 -1
  35. package/dist/result-parsing.js +37 -4
  36. package/dist/result-parsing.js.map +1 -1
  37. package/dist/result-state.d.ts +98 -0
  38. package/dist/result-state.d.ts.map +1 -0
  39. package/dist/result-state.js +91 -0
  40. package/dist/result-state.js.map +1 -0
  41. package/dist/streamable-http-transport.d.ts +11 -1
  42. package/dist/streamable-http-transport.d.ts.map +1 -1
  43. package/dist/streamable-http-transport.js +152 -2
  44. package/dist/streamable-http-transport.js.map +1 -1
  45. package/dist/streamable-http.d.ts +1 -1
  46. package/dist/streamable-http.d.ts.map +1 -1
  47. package/dist/streamable-http.js.map +1 -1
  48. package/dist/transport.d.ts.map +1 -1
  49. package/dist/transport.js +9 -3
  50. package/dist/transport.js.map +1 -1
  51. package/dist/types.d.ts +28 -1
  52. package/dist/types.d.ts.map +1 -1
  53. package/dist/unknown-tool.d.ts +13 -4
  54. package/dist/unknown-tool.d.ts.map +1 -1
  55. package/dist/unknown-tool.js +1 -1
  56. package/dist/unknown-tool.js.map +1 -1
  57. package/package.json +9 -5
package/README.md CHANGED
@@ -183,6 +183,14 @@ for that request. They throw `NotConnectedError`, `RequestTimeoutError`, `JsonRp
183
183
  (with the JSON-RPC `code` and `data`) or `HttpStatusError`; `call()`, `batch()`, `pipe()` and
184
184
  `stream()` never throw and return these as failures instead.
185
185
 
186
+ When a `call()` times out, drops the connection, gets an HTTP 5xx, receives a JSON-RPC
187
+ `-32603`, or loses the result of a started MCP task while polling, the server may already have
188
+ run the command. Unless the tool was positively declared `_meta.mutation: false` in the cached
189
+ tool listing before dispatch (without contradicting destructive or non-read-only markers),
190
+ `call()` returns `OUTCOME_UNKNOWN` with `retryable: false` and records the underlying error code
191
+ in `details.cause`. Tools declared `_meta.mutation: false` return the underlying cause
192
+ (`TIMEOUT`, `CONNECTION_ERROR`, `HTTP_5xx`, `INTERNAL_ERROR`).
193
+
186
194
  ### Batches and Pipelines
187
195
 
188
196
  ```typescript
@@ -330,7 +338,7 @@ It exports `StreamableHttpTransport`, `MODERN_PROTOCOL_VERSION`, and the types
330
338
  - A page on another origin needs the server to allow it through CORS: MCP's headers trigger a
331
339
  preflight, and the response must expose `Mcp-Session-Id`. AFD's server does both for an allowed
332
340
  origin.
333
- - A browser-safe `DirectClient` is a separate entry, [#655](https://github.com/lushly-dev/afd/issues/655).
341
+ - For in-process calls in a browser, use `@lushly-dev/afd-client/direct` (see DirectClient below).
334
342
 
335
343
  ### SSE Transport (Deprecated)
336
344
 
@@ -364,7 +372,7 @@ server). No URL is needed.
364
372
 
365
373
  ```typescript
366
374
  import { createClient } from '@lushly-dev/afd-client';
367
- import { createDirectRegistry } from '@lushly-dev/afd-server';
375
+ import { createDirectRegistry } from '@lushly-dev/afd-server/direct';
368
376
 
369
377
  const client = createClient({ transport: 'direct', registry: createDirectRegistry(commands) });
370
378
  await client.connect();
@@ -379,12 +387,14 @@ the meta-tools and grouped tools that `call()` routes, and one tool per command
379
387
 
380
388
  ### DirectClient (Zero Overhead)
381
389
 
390
+ Use `@lushly-dev/afd-client/direct` for the browser-safe in-process client and its types. It loads no MCP SDK, `eventsource` or Node built-in. Pair it with `@lushly-dev/afd-server/direct` in browsers, workers and webviews; root imports remain supported.
391
+
382
392
  For co-located agents (same runtime as the application), use `createDirectClient` to bypass all transport overhead. Build the registry with `createDirectRegistry` from `@lushly-dev/afd-server`: it runs each call through the same engine as the MCP server (Zod input validation, middleware, error sanitization) and only offers commands exposed to agents (`expose.agent`, on by default).
383
393
 
384
394
  ```typescript
385
395
  import { isSuccess } from '@lushly-dev/afd-core';
386
- import { createDirectClient, isUnknownToolError } from '@lushly-dev/afd-client';
387
- import { createDirectRegistry } from '@lushly-dev/afd-server';
396
+ import { createDirectClient, isUnknownToolError } from '@lushly-dev/afd-client/direct';
397
+ import { createDirectRegistry } from '@lushly-dev/afd-server/direct';
388
398
  import { commands } from '@my-app/commands';
389
399
 
390
400
  // Direct execution - ~0.03-0.1ms latency vs 2-10ms for MCP
@@ -549,7 +559,11 @@ implement the following, and is then responsible for its own validation and
549
559
  exposure checks:
550
560
 
551
561
  ```typescript
552
- import type { CommandDefinition, DirectRegistry } from '@lushly-dev/afd-client';
562
+ import type {
563
+ CommandDefinition,
564
+ DirectCommandSummary,
565
+ DirectRegistry,
566
+ } from '@lushly-dev/afd-client';
553
567
  import type { CommandResult, CommandContext, McpTool } from '@lushly-dev/afd-core';
554
568
 
555
569
  class MyRegistry implements DirectRegistry {
@@ -562,7 +576,7 @@ class MyRegistry implements DirectRegistry {
562
576
  ): Promise<CommandResult<T>>;
563
577
 
564
578
  listCommandNames(): string[];
565
- listCommands(): Array<{ name: string; description: string }>;
579
+ listCommands(): DirectCommandSummary[];
566
580
  hasCommand(name: string): boolean;
567
581
 
568
582
  // Optional - enables DirectClient's shallow input checks
@@ -573,6 +587,31 @@ class MyRegistry implements DirectRegistry {
573
587
  }
574
588
  ```
575
589
 
590
+ #### Normalising Results for UI State
591
+
592
+ `@lushly-dev/afd-client/direct` (and the root entry) exports `normalizeResultState` and
593
+ `loadingResultState` to turn a `CommandResult<T>` (or pending `null`/`undefined`) into a
594
+ discriminated `'loading' | 'ready' | 'empty' | 'error'` state while preserving every
595
+ `CommandResult` field (`confidence`, `reasoning`, `sources`, `plan`, `alternatives`,
596
+ `warnings`, `suggestions`, `metadata`, `undoCommand`, `undoArgs`, and the original `result`):
597
+
598
+ ```typescript
599
+ import {
600
+ loadingResultState,
601
+ type NormalizedResultState,
602
+ normalizeResultState,
603
+ } from '@lushly-dev/afd-client/direct';
604
+
605
+ let view: NormalizedResultState<Todo[]> = loadingResultState<Todo[]>();
606
+ const result = await client.call<Todo[]>('todo-list', {});
607
+ view = normalizeResultState(result);
608
+
609
+ // For enveloped list shapes ({ items: Todo[], total: number }):
610
+ const listView = normalizeResultState(envelopedResult, {
611
+ isEmpty: (data) => !data || data.items.length === 0,
612
+ });
613
+ ```
614
+
576
615
  ## Error Handling
577
616
 
578
617
  The client wraps all errors in the standard `CommandResult` format:
@@ -607,13 +646,15 @@ server's own `error.data.suggestion` is used when it sends one.
607
646
  | JSON-RPC -32600 | `INVALID_REQUEST` | no |
608
647
  | JSON-RPC -32601 | `METHOD_NOT_FOUND` | no |
609
648
  | JSON-RPC -32602 | `INVALID_INPUT` | no |
610
- | JSON-RPC -32603 | `INTERNAL_ERROR` | yes |
649
+ | JSON-RPC -32603 | `INTERNAL_ERROR` | yes (read-only `call()` only; otherwise `OUTCOME_UNKNOWN`, no) |
611
650
  | JSON-RPC -32000 (AFD: Host, Origin, Content-Type or size rejected) | `REQUEST_REJECTED` | no |
612
651
  | JSON-RPC -32001 (AFD: unknown or expired `Mcp-Session-Id`) | `SESSION_NOT_FOUND` | yes |
652
+ | HTTP 503 with JSON-RPC -32000 and `data.code: "SESSION_LIMIT_REACHED"` (AFD: session store full on `initialize`; `connect()` rejects with a `SessionLimitError`) | `SESSION_LIMIT_REACHED` | yes, after `Retry-After` (`details.retryAfterSeconds`) |
613
653
  | Other JSON-RPC codes | `JSON_RPC_ERROR` | no |
614
- | Other HTTP status | `HTTP_<status>` | 5xx and 429 only |
615
- | No response within `timeout` | `TIMEOUT` | yes |
616
- | Network failure | `CONNECTION_ERROR` | yes |
654
+ | Other HTTP status | `HTTP_<status>` | 429; 5xx on read-only `call()` only (otherwise `OUTCOME_UNKNOWN`, no) |
655
+ | No response within `timeout` | `TIMEOUT` | yes (read-only `call()` only; otherwise `OUTCOME_UNKNOWN`, no) |
656
+ | Network failure | `CONNECTION_ERROR` | yes (read-only `call()` only; otherwise `OUTCOME_UNKNOWN`, no) |
657
+ | Timeout, network failure, HTTP 5xx, JSON-RPC -32603, or lost task poll on `batch()`, `pipe()`, or a `call()` not declared `_meta.mutation: false` | `OUTCOME_UNKNOWN` | no (`details.cause` holds the underlying code) |
617
658
  | Called before `connect()` | `NOT_CONNECTED` | no |
618
659
 
619
660
  The details carry `jsonRpcCode` for JSON-RPC errors.
@@ -20,8 +20,29 @@ export declare class RequestTimeoutError extends Error {
20
20
  export declare class HttpStatusError extends Error {
21
21
  readonly status: number;
22
22
  readonly statusText: string;
23
- constructor(status: number, statusText: string);
23
+ constructor(status: number, statusText: string, options?: ErrorOptions);
24
24
  }
25
+ /** The `data.code` an AFD server gives a refused `initialize` when its session store is full. */
26
+ export declare const SESSION_LIMIT_REACHED = "SESSION_LIMIT_REACHED";
27
+ /**
28
+ * The server refused `initialize` because its session store is full (HTTP 503 with a JSON-RPC
29
+ * error whose `data.code` is `SESSION_LIMIT_REACHED`). Nothing ran; retry after `retryAfterSeconds`.
30
+ */
31
+ export declare class SessionLimitError extends Error {
32
+ readonly suggestion: string;
33
+ /** The delay the server gave, from `Retry-After` or `data.retryAfter`, in seconds. */
34
+ readonly retryAfterSeconds: number | undefined;
35
+ readonly code = "SESSION_LIMIT_REACHED";
36
+ readonly retryable = true;
37
+ constructor(message: string, suggestion: string,
38
+ /** The delay the server gave, from `Retry-After` or `data.retryAfter`, in seconds. */
39
+ retryAfterSeconds: number | undefined);
40
+ }
41
+ /**
42
+ * The `SessionLimitError` an HTTP response stands for: only a 503 whose JSON-RPC error carries
43
+ * `data.code: 'SESSION_LIMIT_REACHED'`. A bare JSON-RPC code, or that code on another status, is not one.
44
+ */
45
+ export declare function sessionLimitError(status: number, retryAfter: string | null | undefined, error: McpError): SessionLimitError | undefined;
25
46
  /** The server answered with a JSON-RPC error object. */
26
47
  export declare class JsonRpcResponseError extends Error {
27
48
  readonly code: number;
@@ -1 +1 @@
1
- {"version":3,"file":"client-errors.d.ts","sourceRoot":"","sources":["../src/client-errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGnE,wDAAwD;AACxD,qBAAa,iBAAkB,SAAQ,KAAK;IAC3C,cAGC;CACD;AAED,sDAAsD;AACtD,qBAAa,mBAAoB,SAAQ,KAAK;IAE5C,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM;IAF3B,YACU,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EAI1B;CACD;AAED,iFAAiF;AACjF,qBAAa,eAAgB,SAAQ,KAAK;IAExC,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,UAAU,EAAE,MAAM;IAF5B,YACU,MAAM,EAAE,MAAM,EACd,UAAU,EA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AAsF;IACtF,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,SAAS;IAP/C,QAAQ,CAAC,IAAI,2BAAyB;IACtC,QAAQ,CAAC,SAAS,QAAQ;IAE1B,YACC,OAAO,EAAE,MAAM,EACN,UAAU,EAAE,MAAM;IAC3B,sFAAsF;IAC7E,iBAAiB,EAAE,MAAM,GAAG,SAAS,EAI9C;CACD;AASD;;;GAGG;AACH,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACrC,KAAK,EAAE,QAAQ,GACb,iBAAiB,GAAG,SAAS,CAW/B;AAED,wDAAwD;AACxD,qBAAa,oBAAqB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAEvB,YAAY,KAAK,EAAE,QAAQ,EAK1B;CACD;AAkED,6FAA6F;AAC7F,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,oBAAoB,GAAG,YAAY,CAYpF;AASD,4EAA4E;AAC5E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAiBxD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAmD3D"}
@@ -28,13 +28,53 @@ export class RequestTimeoutError extends Error {
28
28
  export class HttpStatusError extends Error {
29
29
  status;
30
30
  statusText;
31
- constructor(status, statusText) {
32
- super(`HTTP error: ${status} ${statusText}`);
31
+ constructor(status, statusText, options) {
32
+ super(`HTTP error: ${status} ${statusText}`, options);
33
33
  this.status = status;
34
34
  this.statusText = statusText;
35
35
  this.name = 'HttpStatusError';
36
36
  }
37
37
  }
38
+ /** The `data.code` an AFD server gives a refused `initialize` when its session store is full. */
39
+ export const SESSION_LIMIT_REACHED = 'SESSION_LIMIT_REACHED';
40
+ /**
41
+ * The server refused `initialize` because its session store is full (HTTP 503 with a JSON-RPC
42
+ * error whose `data.code` is `SESSION_LIMIT_REACHED`). Nothing ran; retry after `retryAfterSeconds`.
43
+ */
44
+ export class SessionLimitError extends Error {
45
+ suggestion;
46
+ retryAfterSeconds;
47
+ code = SESSION_LIMIT_REACHED;
48
+ retryable = true;
49
+ constructor(message, suggestion,
50
+ /** The delay the server gave, from `Retry-After` or `data.retryAfter`, in seconds. */
51
+ retryAfterSeconds) {
52
+ super(message);
53
+ this.suggestion = suggestion;
54
+ this.retryAfterSeconds = retryAfterSeconds;
55
+ this.name = 'SessionLimitError';
56
+ }
57
+ }
58
+ function seconds(value) {
59
+ const parsed = typeof value === 'string' ? Number(value.trim()) : value;
60
+ return typeof parsed === 'number' && Number.isSafeInteger(parsed) && parsed >= 0
61
+ ? parsed
62
+ : undefined;
63
+ }
64
+ /**
65
+ * The `SessionLimitError` an HTTP response stands for: only a 503 whose JSON-RPC error carries
66
+ * `data.code: 'SESSION_LIMIT_REACHED'`. A bare JSON-RPC code, or that code on another status, is not one.
67
+ */
68
+ export function sessionLimitError(status, retryAfter, error) {
69
+ const data = error.data;
70
+ if (status !== 503 || typeof data !== 'object' || data === null)
71
+ return undefined;
72
+ if (!('code' in data) || data.code !== SESSION_LIMIT_REACHED)
73
+ return undefined;
74
+ const delay = seconds(retryAfter) ?? seconds('retryAfter' in data ? data.retryAfter : undefined);
75
+ return new SessionLimitError(error.message || 'The server has too many live MCP sessions', serverSuggestion(data) ??
76
+ `Retry after ${delay ?? 'the'} seconds the server gave in Retry-After, or reuse a session you hold`, delay);
77
+ }
38
78
  /** The server answered with a JSON-RPC error object. */
39
79
  export class JsonRpcResponseError extends Error {
40
80
  code;
@@ -84,6 +124,11 @@ const JSON_RPC_CODES = {
84
124
  retryable: true,
85
125
  suggestion: 'The MCP session is unknown or expired; reconnect to start a new session',
86
126
  },
127
+ [-32021]: {
128
+ code: 'MISSING_CLIENT_CAPABILITY',
129
+ retryable: false,
130
+ suggestion: 'Reconnect with the required client capability enabled (for MCP Tasks, set tasks: true on McpClient)',
131
+ },
87
132
  };
88
133
  function serverSuggestion(data) {
89
134
  if (typeof data !== 'object' || data === null || !('suggestion' in data))
@@ -105,6 +150,12 @@ export function jsonRpcErrorToCommandError(error) {
105
150
  details: { jsonRpcCode: error.code },
106
151
  };
107
152
  }
153
+ const UNKNOWN_OUTCOME_ERROR_CODES = new Set([
154
+ ErrorCodes.TIMEOUT,
155
+ ErrorCodes.CONNECTION_ERROR,
156
+ ErrorCodes.INTERNAL_ERROR,
157
+ 'OUTCOME_UNKNOWN',
158
+ ]);
108
159
  /** Whether the server can have run the request that failed with `error`. */
109
160
  export function isOutcomeUnknown(error) {
110
161
  if (error instanceof NotConnectedError)
@@ -112,8 +163,20 @@ export function isOutcomeUnknown(error) {
112
163
  if (error instanceof JsonRpcResponseError) {
113
164
  return JSON_RPC_CODES[error.code]?.outcomeUnknown === true;
114
165
  }
166
+ if (error instanceof SessionLimitError)
167
+ return false;
115
168
  if (error instanceof HttpStatusError)
116
169
  return error.status < 400 || error.status >= 500;
170
+ if (isCommandError(error)) {
171
+ if (UNKNOWN_OUTCOME_ERROR_CODES.has(error.code))
172
+ return true;
173
+ const httpMatch = /^HTTP_(\d{3})$/.exec(error.code);
174
+ if (httpMatch) {
175
+ const status = Number(httpMatch[1]);
176
+ return status < 400 || status >= 500;
177
+ }
178
+ return false;
179
+ }
117
180
  return true;
118
181
  }
119
182
  /**
@@ -122,6 +185,17 @@ export function isOutcomeUnknown(error) {
122
185
  export function toCommandError(error) {
123
186
  if (error instanceof JsonRpcResponseError)
124
187
  return jsonRpcErrorToCommandError(error);
188
+ if (error instanceof SessionLimitError) {
189
+ return {
190
+ code: error.code,
191
+ message: error.message,
192
+ suggestion: error.suggestion,
193
+ retryable: true,
194
+ ...(error.retryAfterSeconds === undefined
195
+ ? {}
196
+ : { details: { retryAfterSeconds: error.retryAfterSeconds } }),
197
+ };
198
+ }
125
199
  if (error instanceof NotConnectedError) {
126
200
  return {
127
201
  code: 'NOT_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,UAAU,GAAG,KAAK,CAAC,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,MAAM,KAAK,GAAG,CAAC;QAC/D,OAAO;YACN,IAAI,EAAE,QAAQ,KAAK,CAAC,MAAM,EAAE;YAC5B,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,UAAU,EAAE,UAAU;gBACrB,CAAC,CAAC,sDAAsD;gBACxD,CAAC,CAAC,yFAAyF;YAC5F,SAAS,EAAE,UAAU;SACrB,CAAC;IACH,CAAC;IACD,IAAI,cAAc,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,GAAG,KAAK,EAAE,CAAC;IAC/C,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO;QACN,IAAI,EAAE,UAAU,CAAC,gBAAgB;QACjC,OAAO,EAAE,OAAO,IAAI,oBAAoB;QACxC,UAAU,EACT,wIAAwI;QACzI,SAAS,EAAE,IAAI;KACf,CAAC;AACH,CAAC"}
package/dist/client.d.ts CHANGED
@@ -1,15 +1,24 @@
1
1
  /**
2
2
  * @fileoverview MCP Client implementation
3
3
  */
4
- import type { BatchCommand, BatchOptions, BatchResult, CommandResult, McpInitializeResult, McpTool, McpToolCallResult, PipelineOptions, PipelineRequest, PipelineResult, PipelineStep, StreamCallbacks, StreamChunk, StreamOptions } from '@lushly-dev/afd-core';
4
+ import type { BatchCommand, BatchOptions, BatchResult, CommandResult, McpInitializeResult, McpTool, McpToolCallResult, PipelineOptions, PipelineRequest, PipelineResult, PipelineStep, ServerContract, StreamCallbacks, StreamChunk, StreamOptions } from '@lushly-dev/afd-core';
5
5
  import { McpClientEventEmitter } from './client-events.js';
6
- import type { ClientStatus, McpClientConfig } from './types.js';
6
+ import type { ClientStatus, DetailedTask, McpClientConfig, TaskInfo } from './types.js';
7
7
  /** Options for a single `request()` or `callTool()`. */
8
8
  export interface RequestOptions {
9
9
  /** Request timeout in milliseconds. Default: the client's `timeout`. */
10
10
  timeout?: number;
11
11
  /** Cancel this request and signal in-process execution to stop. */
12
12
  signal?: AbortSignal;
13
+ /** Called when a task started by `callTool()` / `call()` changes status or `statusMessage`. */
14
+ onTaskProgress?: (task: TaskInfo) => void;
15
+ /**
16
+ * The call's idempotency key (`spec/idempotency.md`, K1), sent in
17
+ * `_meta["dev.afd/idempotencyKey"]` on `tools/call`. A server with the idempotency step answers
18
+ * a repeat of a `keyed` command with the same key and input from its store. Send the same key
19
+ * when you repeat a call whose outcome you do not know.
20
+ */
21
+ idempotencyKey?: string;
13
22
  }
14
23
  /**
15
24
  * Extra time `batch()` and `pipe()` wait beyond the server-side deadline in their options, so
@@ -48,11 +57,14 @@ export declare class McpClient extends McpClientEventEmitter {
48
57
  private state;
49
58
  private serverInfo;
50
59
  private capabilities;
60
+ private serverContract;
51
61
  private tools;
52
62
  private connectedAt;
53
63
  private reconnectAttempts;
54
64
  private pendingRequests;
55
65
  private activeStreams;
66
+ private activeTaskPolls;
67
+ private failedTaskPollErrors;
56
68
  private intentionalDisconnect;
57
69
  private connectionGeneration;
58
70
  private connectionController;
@@ -71,6 +83,13 @@ export declare class McpClient extends McpClientEventEmitter {
71
83
  * `STREAM_CANCELLED` error chunk.
72
84
  */
73
85
  disconnect(): Promise<void>;
86
+ /**
87
+ * The AFD contract advertised by the connected server in `_meta["dev.afd/contract"]` on
88
+ * `server/discover` or `initialize` (`spec/tool-strategies.md#contract-advertisement`, #1927).
89
+ * Returns `undefined` when disconnected, when the server omitted the key, or when the
90
+ * advertisement was malformed.
91
+ */
92
+ getServerContract(): ServerContract | undefined;
74
93
  /**
75
94
  * Get current client status.
76
95
  */
@@ -92,20 +111,36 @@ export declare class McpClient extends McpClientEventEmitter {
92
111
  */
93
112
  refreshTools(): Promise<McpTool[]>;
94
113
  /**
95
- * Call a tool and return raw MCP result.
114
+ * Fetch the current state of an MCP task (`tasks/get`).
115
+ */
116
+ getTask(taskId: string, options?: RequestOptions): Promise<DetailedTask>;
117
+ /**
118
+ * Request cooperative cancellation of an MCP task (`tasks/cancel`).
119
+ */
120
+ cancelTask(taskId: string, options?: RequestOptions): Promise<void>;
121
+ /**
122
+ * Call a tool and return raw MCP result. If the server responds with an MCP task
123
+ * (`resultType: 'task'`), polls `tasks/get` until the task completes.
96
124
  *
97
125
  * @param name - Tool name
98
126
  * @param args - Tool arguments
99
- * @param options - Request options such as `timeout`
127
+ * @param options - Request options such as `timeout`, `signal`, `onTaskProgress`
100
128
  */
101
129
  callTool(name: string, args?: Record<string, unknown>, options?: RequestOptions): Promise<McpToolCallResult>;
130
+ private markTaskPollFailure;
131
+ private isTaskPollFailure;
132
+ private pollTask;
102
133
  /**
103
134
  * Call a command and return a CommandResult.
104
135
  *
105
136
  * This is the preferred method for AFD - it wraps the MCP response
106
- * in a standardized CommandResult. It never rejects: a JSON-RPC error becomes a failure with
107
- * a matching AFD code (`INVALID_INPUT` for -32602, `SESSION_NOT_FOUND` for -32001, ...), a
108
- * timeout becomes `TIMEOUT`, and a connection problem `CONNECTION_ERROR` or `NOT_CONNECTED`.
137
+ * in a standardized CommandResult. It never rejects: a definite refusal becomes a failure with
138
+ * a matching AFD code (`INVALID_INPUT` for -32602, `SESSION_NOT_FOUND` for -32001, `HTTP_4xx`,
139
+ * `NOT_CONNECTED`, ...). When a timeout, connection loss, HTTP 5xx, JSON-RPC `-32603`, or a
140
+ * lost task poll leaves the outcome unknown, tools not positively declared `_meta.mutation === false`
141
+ * (without contradicting mutation/destructive/non-read-only markers) return `OUTCOME_UNKNOWN` with
142
+ * `retryable: false` and the underlying cause in `details.cause`; read-only tools return the
143
+ * underlying error (`TIMEOUT`, `CONNECTION_ERROR`, `HTTP_5xx`, `INTERNAL_ERROR`, ...).
109
144
  *
110
145
  * @param name - Command/tool name
111
146
  * @param args - Command arguments
@@ -245,6 +280,14 @@ export declare class McpClient extends McpClientEventEmitter {
245
280
  * HttpStatusError for another non-2xx HTTP status
246
281
  */
247
282
  request<T = unknown>(method: string, params?: Record<string, unknown>, options?: RequestOptions): Promise<T>;
283
+ /**
284
+ * Whether the cached tool listing positively declares `_meta.mutation === false` for `name`.
285
+ *
286
+ * Unknown tools, tools without `_meta.mutation: false`, and tools with any contradicting
287
+ * mutation, destructive, or non-read-only flag return `false` so ambiguous transport failures
288
+ * fail closed as `OUTCOME_UNKNOWN`.
289
+ */
290
+ private isReadOnlyTool;
248
291
  /** A request timeout that outlasts a server-side deadline by the margin. */
249
292
  private timeoutWithMargin;
250
293
  private initialize;
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,aAAa,EACb,mBAAmB,EAEnB,OAAO,EACP,iBAAiB,EAEjB,eAAe,EACf,eAAe,EACf,cAAc,EACd,YAAY,EACZ,eAAe,EACf,WAAW,EACX,aAAa,EACb,MAAM,sBAAsB,CAAC;AAkB9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AA0B3D,OAAO,KAAK,EACX,YAAY,EAEZ,eAAe,EAGf,MAAM,YAAY,CAAC;AAWpB,wDAAwD;AACxD,MAAM,WAAW,cAAc;IAC9B,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB;AAYD;;;GAGG;AACH,eAAO,MAAM,yBAAyB,OAAO,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,SAAU,SAAQ,qBAAqB;IACnD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6B;IACtD,OAAO,CAAC,SAAS,CAA0B;IAC3C,OAAO,CAAC,KAAK,CAAmC;IAChD,OAAO,CAAC,UAAU,CAAkD;IACp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