@openrouter/agent 0.8.0 → 0.10.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 (193) hide show
  1. package/README.md +732 -7
  2. package/THIRD_PARTY_NOTICES.md +25 -0
  3. package/esm/index.d.ts +20 -5
  4. package/esm/index.d.ts.map +1 -1
  5. package/esm/index.js +10 -3
  6. package/esm/index.js.map +1 -1
  7. package/esm/inner-loop/call-model.d.ts.map +1 -1
  8. package/esm/inner-loop/call-model.js +63 -46
  9. package/esm/inner-loop/call-model.js.map +1 -1
  10. package/esm/inner-loop/resume-tool-results.d.ts +128 -0
  11. package/esm/inner-loop/resume-tool-results.d.ts.map +1 -0
  12. package/esm/inner-loop/resume-tool-results.js +244 -0
  13. package/esm/inner-loop/resume-tool-results.js.map +1 -0
  14. package/esm/lib/agent-tool.d.ts +92 -0
  15. package/esm/lib/agent-tool.d.ts.map +1 -0
  16. package/esm/lib/agent-tool.js +211 -0
  17. package/esm/lib/agent-tool.js.map +1 -0
  18. package/esm/lib/async-params.d.ts +96 -0
  19. package/esm/lib/async-params.d.ts.map +1 -1
  20. package/esm/lib/async-params.js +30 -1
  21. package/esm/lib/async-params.js.map +1 -1
  22. package/esm/lib/async-tool-registry.d.ts +134 -0
  23. package/esm/lib/async-tool-registry.d.ts.map +1 -0
  24. package/esm/lib/async-tool-registry.js +352 -0
  25. package/esm/lib/async-tool-registry.js.map +1 -0
  26. package/esm/lib/async-tools.d.ts +23 -0
  27. package/esm/lib/async-tools.d.ts.map +1 -0
  28. package/esm/lib/async-tools.js +19 -0
  29. package/esm/lib/async-tools.js.map +1 -0
  30. package/esm/lib/conversation-state.d.ts +1 -0
  31. package/esm/lib/conversation-state.d.ts.map +1 -1
  32. package/esm/lib/conversation-state.js +8 -0
  33. package/esm/lib/conversation-state.js.map +1 -1
  34. package/esm/lib/doom-loop.d.ts +533 -0
  35. package/esm/lib/doom-loop.d.ts.map +1 -0
  36. package/esm/lib/doom-loop.js +1221 -0
  37. package/esm/lib/doom-loop.js.map +1 -0
  38. package/esm/lib/hooks-schemas.d.ts +33 -0
  39. package/esm/lib/hooks-schemas.d.ts.map +1 -1
  40. package/esm/lib/hooks-schemas.js +54 -0
  41. package/esm/lib/hooks-schemas.js.map +1 -1
  42. package/esm/lib/hooks-types.d.ts +6 -2
  43. package/esm/lib/hooks-types.d.ts.map +1 -1
  44. package/esm/lib/hooks-types.js.map +1 -1
  45. package/esm/lib/model-result.d.ts +648 -12
  46. package/esm/lib/model-result.d.ts.map +1 -1
  47. package/esm/lib/model-result.js +2784 -164
  48. package/esm/lib/model-result.js.map +1 -1
  49. package/esm/lib/next-turn-params.d.ts.map +1 -1
  50. package/esm/lib/next-turn-params.js +3 -1
  51. package/esm/lib/next-turn-params.js.map +1 -1
  52. package/esm/lib/next-turn-params.test.js +72 -0
  53. package/esm/lib/next-turn-params.test.js.map +1 -1
  54. package/esm/lib/reusable-stream.d.ts +9 -0
  55. package/esm/lib/reusable-stream.d.ts.map +1 -1
  56. package/esm/lib/reusable-stream.js +17 -0
  57. package/esm/lib/reusable-stream.js.map +1 -1
  58. package/esm/lib/stream-transformers.d.ts +21 -1
  59. package/esm/lib/stream-transformers.d.ts.map +1 -1
  60. package/esm/lib/stream-transformers.js +45 -0
  61. package/esm/lib/stream-transformers.js.map +1 -1
  62. package/esm/lib/tool-check.d.ts +76 -0
  63. package/esm/lib/tool-check.d.ts.map +1 -0
  64. package/esm/lib/tool-check.js +241 -0
  65. package/esm/lib/tool-check.js.map +1 -0
  66. package/esm/lib/tool-concurrency.d.ts +42 -0
  67. package/esm/lib/tool-concurrency.d.ts.map +1 -0
  68. package/esm/lib/tool-concurrency.js +80 -0
  69. package/esm/lib/tool-concurrency.js.map +1 -0
  70. package/esm/lib/tool-context.d.ts +45 -1
  71. package/esm/lib/tool-context.d.ts.map +1 -1
  72. package/esm/lib/tool-context.js +60 -1
  73. package/esm/lib/tool-context.js.map +1 -1
  74. package/esm/lib/tool-executor.d.ts +52 -9
  75. package/esm/lib/tool-executor.d.ts.map +1 -1
  76. package/esm/lib/tool-executor.js +253 -21
  77. package/esm/lib/tool-executor.js.map +1 -1
  78. package/esm/lib/tool-orchestrator.d.ts.map +1 -1
  79. package/esm/lib/tool-orchestrator.js +87 -50
  80. package/esm/lib/tool-orchestrator.js.map +1 -1
  81. package/esm/lib/tool-set-types.d.ts +298 -0
  82. package/esm/lib/tool-set-types.d.ts.map +1 -0
  83. package/esm/lib/tool-set-types.js +2 -0
  84. package/esm/lib/tool-set-types.js.map +1 -0
  85. package/esm/lib/tool-set.d.ts +157 -0
  86. package/esm/lib/tool-set.d.ts.map +1 -0
  87. package/esm/lib/tool-set.js +473 -0
  88. package/esm/lib/tool-set.js.map +1 -0
  89. package/esm/lib/tool-task.d.ts +157 -0
  90. package/esm/lib/tool-task.d.ts.map +1 -0
  91. package/esm/lib/tool-task.js +206 -0
  92. package/esm/lib/tool-task.js.map +1 -0
  93. package/esm/lib/tool-types.d.ts +667 -38
  94. package/esm/lib/tool-types.d.ts.map +1 -1
  95. package/esm/lib/tool-types.js +59 -10
  96. package/esm/lib/tool-types.js.map +1 -1
  97. package/esm/lib/tool.d.ts +227 -19
  98. package/esm/lib/tool.d.ts.map +1 -1
  99. package/esm/lib/tool.js +206 -6
  100. package/esm/lib/tool.js.map +1 -1
  101. package/esm/mcp/auth/auth-resolver.d.ts +14 -0
  102. package/esm/mcp/auth/auth-resolver.d.ts.map +1 -0
  103. package/esm/mcp/auth/auth-resolver.js +27 -0
  104. package/esm/mcp/auth/auth-resolver.js.map +1 -0
  105. package/esm/mcp/auth/auth-types.d.ts +33 -0
  106. package/esm/mcp/auth/auth-types.d.ts.map +1 -0
  107. package/esm/mcp/auth/auth-types.js +4 -0
  108. package/esm/mcp/auth/auth-types.js.map +1 -0
  109. package/esm/mcp/build-tools.d.ts +29 -0
  110. package/esm/mcp/build-tools.d.ts.map +1 -0
  111. package/esm/mcp/build-tools.js +80 -0
  112. package/esm/mcp/build-tools.js.map +1 -0
  113. package/esm/mcp/cache/cache-store.d.ts +24 -0
  114. package/esm/mcp/cache/cache-store.d.ts.map +1 -0
  115. package/esm/mcp/cache/cache-store.js +20 -0
  116. package/esm/mcp/cache/cache-store.js.map +1 -0
  117. package/esm/mcp/cache/cache-types.d.ts +71 -0
  118. package/esm/mcp/cache/cache-types.d.ts.map +1 -0
  119. package/esm/mcp/cache/cache-types.js +49 -0
  120. package/esm/mcp/cache/cache-types.js.map +1 -0
  121. package/esm/mcp/cache/serialize.d.ts +25 -0
  122. package/esm/mcp/cache/serialize.d.ts.map +1 -0
  123. package/esm/mcp/cache/serialize.js +96 -0
  124. package/esm/mcp/cache/serialize.js.map +1 -0
  125. package/esm/mcp/close-quietly.d.ts +24 -0
  126. package/esm/mcp/close-quietly.d.ts.map +1 -0
  127. package/esm/mcp/close-quietly.js +30 -0
  128. package/esm/mcp/close-quietly.js.map +1 -0
  129. package/esm/mcp/create-mcp-tools.d.ts +13 -0
  130. package/esm/mcp/create-mcp-tools.d.ts.map +1 -0
  131. package/esm/mcp/create-mcp-tools.js +87 -0
  132. package/esm/mcp/create-mcp-tools.js.map +1 -0
  133. package/esm/mcp/elicitation.d.ts +11 -0
  134. package/esm/mcp/elicitation.d.ts.map +1 -0
  135. package/esm/mcp/elicitation.js +51 -0
  136. package/esm/mcp/elicitation.js.map +1 -0
  137. package/esm/mcp/errors.d.ts +91 -0
  138. package/esm/mcp/errors.d.ts.map +1 -0
  139. package/esm/mcp/errors.js +91 -0
  140. package/esm/mcp/errors.js.map +1 -0
  141. package/esm/mcp/handle.d.ts +66 -0
  142. package/esm/mcp/handle.d.ts.map +1 -0
  143. package/esm/mcp/handle.js +323 -0
  144. package/esm/mcp/handle.js.map +1 -0
  145. package/esm/mcp/index.d.ts +13 -0
  146. package/esm/mcp/index.d.ts.map +1 -0
  147. package/esm/mcp/index.js +11 -0
  148. package/esm/mcp/index.js.map +1 -0
  149. package/esm/mcp/mcp-connection.d.ts +150 -0
  150. package/esm/mcp/mcp-connection.d.ts.map +1 -0
  151. package/esm/mcp/mcp-connection.js +478 -0
  152. package/esm/mcp/mcp-connection.js.map +1 -0
  153. package/esm/mcp/mcp-sdk.d.ts +10 -0
  154. package/esm/mcp/mcp-sdk.d.ts.map +1 -0
  155. package/esm/mcp/mcp-sdk.js +37 -0
  156. package/esm/mcp/mcp-sdk.js.map +1 -0
  157. package/esm/mcp/rehydrate.d.ts +76 -0
  158. package/esm/mcp/rehydrate.d.ts.map +1 -0
  159. package/esm/mcp/rehydrate.js +505 -0
  160. package/esm/mcp/rehydrate.js.map +1 -0
  161. package/esm/mcp/resource-tools.d.ts +17 -0
  162. package/esm/mcp/resource-tools.d.ts.map +1 -0
  163. package/esm/mcp/resource-tools.js +155 -0
  164. package/esm/mcp/resource-tools.js.map +1 -0
  165. package/esm/mcp/result-mapper.d.ts +19 -0
  166. package/esm/mcp/result-mapper.d.ts.map +1 -0
  167. package/esm/mcp/result-mapper.js +40 -0
  168. package/esm/mcp/result-mapper.js.map +1 -0
  169. package/esm/mcp/schema/json-schema-guards.d.ts +14 -0
  170. package/esm/mcp/schema/json-schema-guards.d.ts.map +1 -0
  171. package/esm/mcp/schema/json-schema-guards.js +19 -0
  172. package/esm/mcp/schema/json-schema-guards.js.map +1 -0
  173. package/esm/mcp/schema/json-schema-to-zod.d.ts +20 -0
  174. package/esm/mcp/schema/json-schema-to-zod.d.ts.map +1 -0
  175. package/esm/mcp/schema/json-schema-to-zod.js +72 -0
  176. package/esm/mcp/schema/json-schema-to-zod.js.map +1 -0
  177. package/esm/mcp/tool-wrapper.d.ts +41 -0
  178. package/esm/mcp/tool-wrapper.d.ts.map +1 -0
  179. package/esm/mcp/tool-wrapper.js +131 -0
  180. package/esm/mcp/tool-wrapper.js.map +1 -0
  181. package/esm/mcp/transport-types.d.ts +45 -0
  182. package/esm/mcp/transport-types.d.ts.map +1 -0
  183. package/esm/mcp/transport-types.js +2 -0
  184. package/esm/mcp/transport-types.js.map +1 -0
  185. package/esm/mcp/types.d.ts +119 -0
  186. package/esm/mcp/types.d.ts.map +1 -0
  187. package/esm/mcp/types.js +2 -0
  188. package/esm/mcp/types.js.map +1 -0
  189. package/esm/mcp/version.d.ts +3 -0
  190. package/esm/mcp/version.d.ts.map +1 -0
  191. package/esm/mcp/version.js +5 -0
  192. package/esm/mcp/version.js.map +1 -0
  193. package/package.json +70 -5
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Base error for all @openrouter/agent/mcp failures.
3
+ */
4
+ export class MCPError extends Error {
5
+ constructor(message, options) {
6
+ super(message, options);
7
+ this.name = 'MCPError';
8
+ }
9
+ }
10
+ /**
11
+ * Raised when an MCP tool call returns `isError: true` or when the result
12
+ * cannot be mapped to a usable model output.
13
+ */
14
+ export class MCPToolCallError extends MCPError {
15
+ constructor(toolName, message, options) {
16
+ super(message, options);
17
+ this.name = 'MCPToolCallError';
18
+ this.toolName = toolName;
19
+ }
20
+ }
21
+ /**
22
+ * Raised when a cached snapshot cannot be validated or rehydrated.
23
+ */
24
+ export class MCPCacheError extends MCPError {
25
+ constructor(message, options) {
26
+ super(message, options);
27
+ this.name = 'MCPCacheError';
28
+ }
29
+ }
30
+ /**
31
+ * Raised when the tool list was read successfully but writing the snapshot back
32
+ * to the caller's `MCPCacheStore` failed.
33
+ *
34
+ * Distinct from the read failing, because the consequences differ completely: the
35
+ * connection is live and its tools are current, so the only thing lost is a cache
36
+ * entry. Callers who treat a store outage as fatal can catch this; callers who
37
+ * would rather keep working with a warm handle can ignore it.
38
+ *
39
+ * Subclasses {@link MCPCacheError}, so existing catch sites keep working.
40
+ */
41
+ export class MCPCacheWriteError extends MCPCacheError {
42
+ constructor(message, options) {
43
+ super(message, options);
44
+ this.name = 'MCPCacheWriteError';
45
+ }
46
+ }
47
+ /**
48
+ * Raised when a snapshot is older than `staleness.maxAgeMs` and the re-list that
49
+ * would have refreshed it failed — so the only tools available are ones the
50
+ * caller declared too old to use.
51
+ *
52
+ * Subclasses {@link MCPCacheError}, so existing `catch (e instanceof
53
+ * MCPCacheError)` sites keep working. Catch this specifically to fall back to
54
+ * stale-but-usable tools instead of failing.
55
+ */
56
+ export class MCPStaleSnapshotError extends MCPCacheError {
57
+ constructor(message, options) {
58
+ super(message, options);
59
+ this.name = 'MCPStaleSnapshotError';
60
+ }
61
+ }
62
+ /**
63
+ * Raised when connecting to the MCP server fails across all attempted transports.
64
+ */
65
+ export class MCPConnectionError extends MCPError {
66
+ constructor(message, options) {
67
+ super(message, options);
68
+ this.name = 'MCPConnectionError';
69
+ // Default a single-attempt failure to its own cause, so `errors` is a
70
+ // uniform "every attempt" list rather than empty-unless-multi.
71
+ this.errors =
72
+ options?.errors ??
73
+ (options?.cause !== undefined
74
+ ? [
75
+ options.cause,
76
+ ]
77
+ : []);
78
+ }
79
+ }
80
+ /**
81
+ * Raised when MCP support is used without its optional SDK peer installed.
82
+ */
83
+ export class MCPMissingPeerDependencyError extends MCPConnectionError {
84
+ constructor(options) {
85
+ super('MCP support requires the optional peer "@modelcontextprotocol/client". ' +
86
+ 'Install it alongside @openrouter/agent (for example: pnpm add @modelcontextprotocol/client).', options);
87
+ this.packageName = '@modelcontextprotocol/client';
88
+ this.name = 'MCPMissingPeerDependencyError';
89
+ }
90
+ }
91
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/mcp/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,YACE,OAAe,EACf,OAEC;QAED,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,gBAAiB,SAAQ,QAAQ;IAG5C,YACE,QAAgB,EAChB,OAAe,EACf,OAEC;QAED,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,I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IAAI,CAAC,IAAI,GAAG,+BAA+B,CAAC;IAC9C,CAAC;CACF"}
@@ -0,0 +1,66 @@
1
+ import type { MCPConnection } from './mcp-connection.js';
2
+ import type { McpToolDef } from './tool-wrapper.js';
3
+ import type { MCPTransportKind } from './transport-types.js';
4
+ import type { CreateMCPToolsOptions, MCPToolsHandle } from './types.js';
5
+ export declare function normalizeUrl(url: string | URL): URL;
6
+ /**
7
+ * Read the discovered tools off the live connection into our internal shape.
8
+ *
9
+ * `tools/list` is paginated: each response may carry a `nextCursor` that must be
10
+ * passed back as `{ cursor }` to fetch the next page. We accumulate every page so
11
+ * servers that paginate their tool list aren't silently truncated.
12
+ *
13
+ * Always `cacheMode: 'refresh'`. SDK v2 keeps a per-client response cache
14
+ * honouring the server's `ttlMs` on `tools/list` (up to 24h), so the default
15
+ * `'use'` would serve a still-fresh cached list without a round trip. That is
16
+ * fine for an opportunistic read but wrong for every caller here: `refresh()`
17
+ * documents a forced re-read, `freshConnect` is establishing the tool set for the
18
+ * first time, and the stale-replay path exists precisely because the age of the
19
+ * cached list is no longer acceptable. `'refresh'` fetches and re-stores, so the
20
+ * cache stays warm for the SDK's own readers.
21
+ *
22
+ * `'refresh'` rather than `'bypass'` deliberately — bypass would skip the write
23
+ * too, leaving a stale entry behind for anything that later reads with `'use'`.
24
+ */
25
+ export declare function listToolDefs(connection: MCPConnection, signal: AbortSignal | undefined): Promise<McpToolDef[]>;
26
+ interface HandleContext {
27
+ url: URL;
28
+ transport: MCPTransportKind;
29
+ cacheKey: string;
30
+ }
31
+ export interface MakeHandleArgs {
32
+ connection: MCPConnection;
33
+ options: CreateMCPToolsOptions;
34
+ context: HandleContext;
35
+ initialToolDefs: McpToolDef[];
36
+ /**
37
+ * `cachedAt` to carry forward when `initialToolDefs` came from a snapshot
38
+ * rather than a live `listTools()`. Omit on a cold connect so the write
39
+ * stamps now.
40
+ *
41
+ * Without this a replay would restamp `cachedAt` on the write-back below,
42
+ * resetting the staleness clock on a tool set that was never re-listed —
43
+ * so `staleness.maxAgeMs` could never fire on a repeatedly-rehydrated
44
+ * snapshot. Age tracks when the tools were last actually discovered, not
45
+ * when they were last replayed. `refresh()` clears it, because that path
46
+ * does re-list.
47
+ */
48
+ replayedCachedAt?: number;
49
+ }
50
+ /**
51
+ * Connect, discover tools via `listTools()`, and build a handle WITHOUT
52
+ * consulting the cache for a hit. The cache (when present on `options`) is still
53
+ * written through `makeHandle`, so refreshes persist. This is the cold cache-miss
54
+ * path, and is also called directly by `rehydrateMCPTools`'s fallback: routing
55
+ * the fallback here instead of back through `createMCPTools` is what prevents the
56
+ * cache-fallback loop — re-reading the same snapshot would re-enter rehydrate and
57
+ * recurse without bound.
58
+ */
59
+ export declare function freshConnect(options: CreateMCPToolsOptions, url: URL, cacheKey: string): Promise<MCPToolsHandle>;
60
+ /**
61
+ * Construct an {@link MCPToolsHandle} around a live connection, wiring refresh,
62
+ * serialize, list_changed listeners, and cache writes.
63
+ */
64
+ export declare function makeHandle(args: MakeHandleArgs): Promise<MCPToolsHandle>;
65
+ export {};
66
+ //# sourceMappingURL=handle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../../src/mcp/handle.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAExE,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,GAAG,GAAG,CAEnD;AAiCD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,aAAa,EACzB,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,OAAO,CAAC,UAAU,EAAE,CAAC,CA0CvB;AAOD,UAAU,aAAa;IACrB,GAAG,EAAE,GAAG,CAAC;IACT,SAAS,EAAE,gBAAgB,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,aAAa,CAAC;IAC1B,OAAO,EAAE,qBAAqB,CAAC;IAC/B,OAAO,EAAE,aAAa,CAAC;IACvB,eAAe,EAAE,UAAU,EAAE,CAAC;IAC9B;;;;;;;;;;;OAWG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,qBAAqB,EAC9B,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,cAAc,CAAC,CA+CzB;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CA4H9E"}
@@ -0,0 +1,323 @@
1
+ import { buildTools } from './build-tools.js';
2
+ import { serializeServer } from './cache/serialize.js';
3
+ import { closeQuietly } from './close-quietly.js';
4
+ import { MCPCacheWriteError } from './errors.js';
5
+ import { connect } from './mcp-connection.js';
6
+ export function normalizeUrl(url) {
7
+ return url instanceof URL ? url : new URL(url);
8
+ }
9
+ // Hard cap on pagination pages. A well-behaved server terminates the cursor
10
+ // chain by omitting `nextCursor`; this bounds a misbehaving one that never does.
11
+ const MAX_LIST_PAGES = 1000;
12
+ /**
13
+ * Normalize a paginated `nextCursor` field: treat anything that is not a
14
+ * non-empty string as "no more pages" so a malformed cursor terminates the loop.
15
+ */
16
+ function nextCursorOrUndefined(value) {
17
+ return typeof value === 'string' && value.length > 0 ? value : undefined;
18
+ }
19
+ /**
20
+ * Parse a server-advertised doom-loop identity from a tool definition's
21
+ * `_meta['openrouter/loopKey']`: a field-name array (the declarative subset
22
+ * of arguments identifying a call) or `false` (tool exempt). Data-only by
23
+ * design — functions can't cross the wire; any other shape is ignored.
24
+ */
25
+ function advertisedLoopKey(meta) {
26
+ const advertised = meta?.['openrouter/loopKey'];
27
+ if (advertised === false) {
28
+ return false;
29
+ }
30
+ if (Array.isArray(advertised) && advertised.every((f) => typeof f === 'string')) {
31
+ return advertised;
32
+ }
33
+ return undefined;
34
+ }
35
+ /**
36
+ * Read the discovered tools off the live connection into our internal shape.
37
+ *
38
+ * `tools/list` is paginated: each response may carry a `nextCursor` that must be
39
+ * passed back as `{ cursor }` to fetch the next page. We accumulate every page so
40
+ * servers that paginate their tool list aren't silently truncated.
41
+ *
42
+ * Always `cacheMode: 'refresh'`. SDK v2 keeps a per-client response cache
43
+ * honouring the server's `ttlMs` on `tools/list` (up to 24h), so the default
44
+ * `'use'` would serve a still-fresh cached list without a round trip. That is
45
+ * fine for an opportunistic read but wrong for every caller here: `refresh()`
46
+ * documents a forced re-read, `freshConnect` is establishing the tool set for the
47
+ * first time, and the stale-replay path exists precisely because the age of the
48
+ * cached list is no longer acceptable. `'refresh'` fetches and re-stores, so the
49
+ * cache stays warm for the SDK's own readers.
50
+ *
51
+ * `'refresh'` rather than `'bypass'` deliberately — bypass would skip the write
52
+ * too, leaving a stale entry behind for anything that later reads with `'use'`.
53
+ */
54
+ export async function listToolDefs(connection, signal) {
55
+ const requestOptions = {
56
+ cacheMode: 'refresh',
57
+ ...(signal !== undefined && {
58
+ signal,
59
+ }),
60
+ };
61
+ const collected = [];
62
+ let cursor;
63
+ for (let page = 0; page < MAX_LIST_PAGES; page += 1) {
64
+ const params = cursor !== undefined
65
+ ? {
66
+ cursor,
67
+ }
68
+ : undefined;
69
+ const { tools, nextCursor } = await connection.client.listTools(params, requestOptions);
70
+ for (const t of tools) {
71
+ const loopKey = advertisedLoopKey(t._meta);
72
+ collected.push({
73
+ name: t.name,
74
+ ...(t.description !== undefined && {
75
+ description: t.description,
76
+ }),
77
+ inputSchema: t.inputSchema,
78
+ ...(t.outputSchema !== undefined && {
79
+ outputSchema: t.outputSchema,
80
+ }),
81
+ ...(loopKey !== undefined && {
82
+ loopKey,
83
+ }),
84
+ });
85
+ }
86
+ const next = nextCursorOrUndefined(nextCursor);
87
+ // Stop at the end of the chain, or if the server echoes the same cursor
88
+ // (which would otherwise spin forever).
89
+ if (next === undefined || next === cursor) {
90
+ break;
91
+ }
92
+ cursor = next;
93
+ }
94
+ return collected;
95
+ }
96
+ function serverHasResources(connection) {
97
+ const caps = connection.client.getServerCapabilities();
98
+ return caps?.resources !== undefined;
99
+ }
100
+ /**
101
+ * Connect, discover tools via `listTools()`, and build a handle WITHOUT
102
+ * consulting the cache for a hit. The cache (when present on `options`) is still
103
+ * written through `makeHandle`, so refreshes persist. This is the cold cache-miss
104
+ * path, and is also called directly by `rehydrateMCPTools`'s fallback: routing
105
+ * the fallback here instead of back through `createMCPTools` is what prevents the
106
+ * cache-fallback loop — re-reading the same snapshot would re-enter rehydrate and
107
+ * recurse without bound.
108
+ */
109
+ export async function freshConnect(options, url, cacheKey) {
110
+ const connection = await connect({
111
+ url,
112
+ ...(options.transport !== undefined && {
113
+ transport: options.transport,
114
+ }),
115
+ ...(options.auth !== undefined && {
116
+ auth: options.auth,
117
+ }),
118
+ ...(options.fetch !== undefined && {
119
+ fetch: options.fetch,
120
+ }),
121
+ ...(options.clientInfo !== undefined && {
122
+ clientInfo: options.clientInfo,
123
+ }),
124
+ ...(options.onElicitation !== undefined && {
125
+ onElicitation: options.onElicitation,
126
+ }),
127
+ ...(options.protocolNegotiation !== undefined && {
128
+ protocolNegotiation: options.protocolNegotiation,
129
+ }),
130
+ ...(options.probeTimeoutMs !== undefined && {
131
+ probeTimeoutMs: options.probeTimeoutMs,
132
+ }),
133
+ ...(options.signal !== undefined && {
134
+ signal: options.signal,
135
+ }),
136
+ });
137
+ // Tear the connection down if discovery or the initial cache write throws —
138
+ // otherwise the open transport (HTTP keep-alive / SSE stream) leaks.
139
+ try {
140
+ const initialToolDefs = await listToolDefs(connection, options.signal);
141
+ return await makeHandle({
142
+ connection,
143
+ options,
144
+ context: {
145
+ url,
146
+ transport: connection.transport,
147
+ cacheKey,
148
+ },
149
+ initialToolDefs,
150
+ });
151
+ }
152
+ catch (err) {
153
+ await closeQuietly(connection);
154
+ throw err;
155
+ }
156
+ }
157
+ /**
158
+ * Construct an {@link MCPToolsHandle} around a live connection, wiring refresh,
159
+ * serialize, list_changed listeners, and cache writes.
160
+ */
161
+ export async function makeHandle(args) {
162
+ const { connection, options, context, initialToolDefs } = args;
163
+ const listeners = new Set();
164
+ let toolDefs = initialToolDefs;
165
+ // Cleared by refresh(): once we have re-listed, age is measured from now.
166
+ let replayedCachedAt = args.replayedCachedAt;
167
+ const serverInfo = connection.client.getServerVersion();
168
+ const rebuild = () => buildTools(buildToolsArgs(connection, toolDefs, options));
169
+ let tools = rebuild();
170
+ const snapshot = () => serializeServer(serializeArgs({
171
+ connection,
172
+ context,
173
+ toolDefs,
174
+ serverInfo,
175
+ options,
176
+ ...(replayedCachedAt !== undefined && {
177
+ cachedAt: replayedCachedAt,
178
+ }),
179
+ }));
180
+ const writeCache = async () => {
181
+ const store = options.cache?.store;
182
+ if (store === undefined) {
183
+ return;
184
+ }
185
+ // Built OUTSIDE the try: `snapshot()` can reject from the caller's own
186
+ // OAuth provider (`provider.tokens()`), and relabelling that as a cache
187
+ // write failure would send it down every "store outages are harmless"
188
+ // path — swallowed by the list_changed handler, ignored by
189
+ // `refreshStaleReplay`, and dismissed by callers following the documented
190
+ // `MCPCacheWriteError` pattern. Only the store op earns the tag.
191
+ const payload = await snapshot();
192
+ try {
193
+ await store.set(context.cacheKey, payload);
194
+ }
195
+ catch (writeErr) {
196
+ // Tagged so callers can tell a store outage from a failed read. The two
197
+ // look identical coming out of `refresh()` but mean opposite things: a
198
+ // failed read leaves the tool set unknown, while a failed write leaves a
199
+ // live connection with current tools and only a stale cache entry.
200
+ throw new MCPCacheWriteError('Failed to write the MCP snapshot to the cache store', {
201
+ cause: writeErr,
202
+ });
203
+ }
204
+ };
205
+ // INVARIANT internal callers rely on: `refresh()` swaps `tools` to a fresh
206
+ // array (rebuild() always allocates) exactly when the re-list succeeded, and
207
+ // it does so BEFORE attempting to persist. A caller that captured the old
208
+ // reference can therefore tell "the re-list failed" (reference unchanged)
209
+ // from "only something after the re-list failed" (reference changed) without
210
+ // inspecting the error — which no error-class check can do reliably, since
211
+ // persistence can fail outside the store op too (the caller's own OAuth
212
+ // provider rejecting inside `snapshot()`).
213
+ const refresh = async () => {
214
+ toolDefs = await listToolDefs(connection, options.signal);
215
+ // Re-listed, so the snapshot is genuinely current from here on.
216
+ replayedCachedAt = undefined;
217
+ tools = rebuild();
218
+ await writeCache();
219
+ return tools;
220
+ };
221
+ if (options.autoRefreshOnListChanged ?? true) {
222
+ connection.setToolListChangedHandler(() => {
223
+ // Fire-and-forget, but never let a failed refresh escape as an unhandled
224
+ // rejection. Whether to announce is keyed on ADOPTION (the reference
225
+ // swap above), not on error class: once `refresh()` has swapped `tools`,
226
+ // skipping the announcement would leave subscribers permanently out of
227
+ // sync with `handle.tools`, no matter what broke afterwards — a store
228
+ // outage and an OAuth provider failing during serialize gate it equally
229
+ // little. On a failed re-list the reference is untouched and subscribers
230
+ // correctly keep the last good set.
231
+ const before = tools;
232
+ void refresh()
233
+ .catch(() => undefined)
234
+ .then(() => {
235
+ if (tools === before) {
236
+ return;
237
+ }
238
+ for (const listener of listeners) {
239
+ listener(tools);
240
+ }
241
+ })
242
+ .catch(() => { });
243
+ });
244
+ }
245
+ // Skipped entirely on a replay: with `replayedCachedAt` carried forward the
246
+ // snapshot we would write is the one just read — same tool defs, same
247
+ // `cachedAt` — so the write is an external store round-trip per rehydrate
248
+ // buying nothing. (It also cannot *refresh* anything: preserving the age is
249
+ // the point.) A cold connect writes; `refresh()` clears `replayedCachedAt`
250
+ // and writes. Skipping here additionally narrows DEV-766's surface — one
251
+ // fewer path that can rewrite a credentialed entry under different options.
252
+ //
253
+ // Best-effort when it does run: the handle is fully usable without its cache
254
+ // entry, so a store outage should not stop a connection that already
255
+ // succeeded. `refresh()` reports write failures as `MCPCacheWriteError` for
256
+ // callers that do care.
257
+ if (args.replayedCachedAt === undefined) {
258
+ await writeCache().catch(() => { });
259
+ }
260
+ return {
261
+ get tools() {
262
+ return tools;
263
+ },
264
+ ...(serverInfo !== undefined && {
265
+ serverInfo,
266
+ }),
267
+ serialize: snapshot,
268
+ refresh,
269
+ onToolsChanged: (listener) => {
270
+ listeners.add(listener);
271
+ return () => listeners.delete(listener);
272
+ },
273
+ close: () => connection.close(),
274
+ };
275
+ }
276
+ /** Assemble the {@link buildTools} arguments, threading only the defined options. */
277
+ function buildToolsArgs(connection, toolDefs, options) {
278
+ return {
279
+ client: connection.client,
280
+ toolDefs,
281
+ emitProgress: options.emitProgress ?? true,
282
+ serverHasResources: serverHasResources(connection),
283
+ ...(options.toolNamePrefix !== undefined && {
284
+ namePrefix: options.toolNamePrefix,
285
+ }),
286
+ ...(options.includeTools !== undefined && {
287
+ includeTools: options.includeTools,
288
+ }),
289
+ ...(options.excludeTools !== undefined && {
290
+ excludeTools: options.excludeTools,
291
+ }),
292
+ ...(options.onUnconvertibleSchema !== undefined && {
293
+ schemaMode: options.onUnconvertibleSchema,
294
+ }),
295
+ ...(options.signal !== undefined && {
296
+ signal: options.signal,
297
+ }),
298
+ ...(options.loopKeys !== undefined && {
299
+ loopKeys: options.loopKeys,
300
+ }),
301
+ ...(options.resources !== undefined && {
302
+ resources: options.resources,
303
+ }),
304
+ };
305
+ }
306
+ /** Assemble the {@link serializeServer} input, threading only the defined fields. */
307
+ function serializeArgs(args) {
308
+ const { connection, context, toolDefs, serverInfo, options } = args;
309
+ return {
310
+ url: context.url.href,
311
+ transport: connection.transport,
312
+ toolDefs,
313
+ cacheCredentials: options.cacheCredentials ?? false,
314
+ cachedAt: args.cachedAt ?? Date.now(),
315
+ ...(serverInfo !== undefined && {
316
+ serverInfo,
317
+ }),
318
+ ...(options.auth !== undefined && {
319
+ auth: options.auth,
320
+ }),
321
+ };
322
+ }
323
+ //#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E,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,GAAG,EAAE;QACrC,GAAG,CAAC,UAAU,KAAK,SAAS,IAAI;YAC9B,UAAU;SACX,CAAC;QACF,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI;YAChC,IAAI,EAAE,OAAO,CAAC,IAAI;SACnB,CAAC;KACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ export type { MCPAuth, MCPOAuthClientProvider } from './auth/auth-types.js';
2
+ export type { MCPCacheStore } from './cache/cache-store.js';
3
+ export { defaultCacheKey, InMemoryMCPCacheStore } from './cache/cache-store.js';
4
+ export type { SerializedMCPServer, SerializedMCPToolDef, SerializedTokenSet, } from './cache/cache-types.js';
5
+ export { isSerializedMCPServer } from './cache/cache-types.js';
6
+ export { createMCPTools } from './create-mcp-tools.js';
7
+ export { MCPCacheError, MCPCacheWriteError, MCPConnectionError, MCPError, MCPMissingPeerDependencyError, MCPStaleSnapshotError, MCPToolCallError, } from './errors.js';
8
+ export type { RehydrateMCPToolsOptions } from './rehydrate.js';
9
+ export { rehydrateMCPTools } from './rehydrate.js';
10
+ export type { UnconvertibleSchemaMode } from './schema/json-schema-to-zod.js';
11
+ export { convertMcpInputSchema } from './schema/json-schema-to-zod.js';
12
+ export type { CreateMCPToolsOptions, ElicitationHandler, ElicitationResponse, MCPProtocolNegotiation, MCPProtocolRevision, MCPToolsHandle, MCPTransportKind, ResourcesOption, } from './types.js';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAGA,YAAY,EAAE,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC5E,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAChF,YAAY,EACV,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,QAAQ,EACR,6BAA6B,EAC7B,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,YAAY,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAE9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAEvE,YAAY,EACV,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,eAAe,GAChB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,11 @@
1
+ // Main factory + rehydration
2
+ // Cache
3
+ export { defaultCacheKey, InMemoryMCPCacheStore } from './cache/cache-store.js';
4
+ export { isSerializedMCPServer } from './cache/cache-types.js';
5
+ export { createMCPTools } from './create-mcp-tools.js';
6
+ // Errors
7
+ export { MCPCacheError, MCPCacheWriteError, MCPConnectionError, MCPError, MCPMissingPeerDependencyError, MCPStaleSnapshotError, MCPToolCallError, } from './errors.js';
8
+ export { rehydrateMCPTools } from './rehydrate.js';
9
+ // Schema conversion (exported for testing/reuse)
10
+ export { convertMcpInputSchema } from './schema/json-schema-to-zod.js';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAK7B,QAAQ;AACR,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAMhF,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,SAAS;AACT,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,QAAQ,EACR,6BAA6B,EAC7B,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,iDAAiD;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC"}