apps 0.0.1-beta.0 → 0.0.1-beta.10

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 (141) hide show
  1. package/README.md +145 -30
  2. package/framework-reference.json +1 -1
  3. package/js/browser-XIPJGLH2.js +65 -0
  4. package/js/{chunk-36DNRFZQ.js → chunk-27F7W2LG.js} +1 -1
  5. package/js/{chunk-VFUZI3NY.js → chunk-57RKNWL2.js} +4 -4
  6. package/js/{chunk-BPEFS4YF.js → chunk-5T57N25Q.js} +122 -18
  7. package/js/chunk-72JNVHPK.js +41 -0
  8. package/js/{chunk-2OTCEKL2.js → chunk-CDL5PM2Q.js} +2643 -1646
  9. package/js/{chunk-KWTCHVLT.js → chunk-CRDWFA74.js} +69 -54
  10. package/js/chunk-CZ7CSFO4.js +39 -0
  11. package/js/{chunk-WIDTG42X.js → chunk-EPT3ZP52.js} +79 -26
  12. package/js/chunk-FL2QR3XW.js +507 -0
  13. package/js/{chunk-3ANFZFCV.js → chunk-IJX4CYZO.js} +15 -18
  14. package/js/chunk-IPI4MFSN.js +78 -0
  15. package/js/chunk-JU7VHODU.js +104 -0
  16. package/js/chunk-KUMBKVJD.js +39 -0
  17. package/js/{chunk-YDR4CPJA.js → chunk-M3B3DE4K.js} +8 -8
  18. package/js/chunk-MKWZPDR6.js +63 -0
  19. package/js/{chunk-7JXHF5IF.js → chunk-N7YDVXYJ.js} +49 -1
  20. package/js/chunk-NKLWZJLE.js +172 -0
  21. package/js/{chunk-OWD2YICM.js → chunk-ODEIDRGW.js} +116 -88
  22. package/js/{chunk-D6BKYP2L.js → chunk-PJJ24GU7.js} +4 -4
  23. package/js/{chunk-EP6AEUZO.js → chunk-PZB6T6KU.js} +1 -1
  24. package/js/chunk-R3EV5FTO.js +97 -0
  25. package/js/chunk-RFVIONFX.js +189 -0
  26. package/js/{chunk-W7Q5EOTS.js → chunk-UK573G7W.js} +32 -32
  27. package/js/chunk-UVL56Z6E.js +6641 -0
  28. package/js/{chunk-Q2FD5IBM.js → chunk-V5KNQVCT.js} +505 -124
  29. package/js/{chunk-SBKHUC5L.js → chunk-VFZKSM3T.js} +5 -25
  30. package/js/{chunk-HP7E42X6.js → chunk-WLE7WX2U.js} +1158 -232
  31. package/js/{chunk-X3YBZCJW.js → chunk-YXQHV65J.js} +58 -62
  32. package/js/chunk-Z5M2LQOZ.js +209 -0
  33. package/js/{chunk-R6JMJSVT.js → chunk-ZQINWV4W.js} +60 -20
  34. package/js/client.js +11 -27
  35. package/js/contracts.js +138 -27
  36. package/js/effect.js +20 -15
  37. package/js/es-APDZKREY.js +40968 -0
  38. package/js/graphql.js +220 -123
  39. package/js/host.js +75 -19
  40. package/js/index.js +261 -117
  41. package/js/mcp/effect.js +24 -17
  42. package/js/mcp/stdio.js +26 -21
  43. package/js/mcp.js +127 -26
  44. package/js/openapi.js +3048 -150
  45. package/js/operations/approval.js +1 -1
  46. package/js/react.js +4 -4
  47. package/js/skills/effect.js +11 -0
  48. package/js/skills.js +893 -0
  49. package/js/storage/facet.js +7 -7
  50. package/js/ui/auth/contracts.js +9 -10
  51. package/js/ui/auth.js +17 -15
  52. package/js/ui/contracts.js +5 -5
  53. package/js/ui/serving.js +14 -13
  54. package/package.json +9 -1
  55. package/runtime.json +1 -1
  56. package/types/app-cache/src/contracts/cache.d.ts +119 -0
  57. package/types/app-cache/src/index.d.ts +93 -0
  58. package/types/app-data/src/contracts/database.d.ts +33 -6
  59. package/types/app-data/src/implementation/schema.d.ts +2 -17
  60. package/types/apps/src/contracts/api-response-error.d.ts +43 -0
  61. package/types/apps/src/contracts/app.d.ts +16 -4
  62. package/types/apps/src/contracts/cache.d.ts +44 -0
  63. package/types/apps/src/contracts/dynamic-skills.d.ts +10 -0
  64. package/types/apps/src/contracts/failure.d.ts +25 -0
  65. package/types/apps/src/contracts/graphql.d.ts +18 -1
  66. package/types/apps/src/contracts/host.d.ts +76 -528
  67. package/types/apps/src/contracts/mcp.d.ts +19 -1
  68. package/types/apps/src/contracts/openapi-compile.d.ts +11 -0
  69. package/types/apps/src/contracts/openapi-document.d.ts +53 -0
  70. package/types/apps/src/contracts/openapi.d.ts +160 -30
  71. package/types/apps/src/contracts/operations.d.ts +0 -5
  72. package/types/apps/src/contracts/protocol-version.d.ts +6 -0
  73. package/types/apps/src/contracts/protocols/1.d.ts +1589 -0
  74. package/types/apps/src/contracts/protocols/2.d.ts +668 -0
  75. package/types/apps/src/contracts/protocols/3.d.ts +676 -0
  76. package/types/apps/src/contracts/protocols/4.d.ts +1229 -0
  77. package/types/apps/src/contracts/protocols/5.d.ts +1090 -0
  78. package/types/apps/src/contracts/provider-error.d.ts +15 -0
  79. package/types/apps/src/contracts/provider.d.ts +69 -6
  80. package/types/apps/src/contracts/router.d.ts +59 -0
  81. package/types/apps/src/contracts/skills.d.ts +122 -0
  82. package/types/apps/src/contracts/storage.d.ts +3 -3
  83. package/types/apps/src/contracts/swagger-client.d.ts +29 -0
  84. package/types/apps/src/contracts/ui-auth.d.ts +6 -14
  85. package/types/apps/src/contracts/workflows.d.ts +34 -3
  86. package/types/apps/src/graphql.d.ts +5 -7
  87. package/types/apps/src/host.d.ts +1 -0
  88. package/types/apps/src/implementation/account-router.d.ts +12 -0
  89. package/types/apps/src/implementation/app.d.ts +5 -4
  90. package/types/apps/src/implementation/cache-session.d.ts +7 -0
  91. package/types/apps/src/implementation/cache.d.ts +8 -0
  92. package/types/apps/src/implementation/catalog-cache.d.ts +36 -0
  93. package/types/apps/src/implementation/dynamic-skills.d.ts +7 -0
  94. package/types/apps/src/implementation/elicitation.d.ts +13 -13
  95. package/types/apps/src/implementation/failure-detail.d.ts +25 -0
  96. package/types/apps/src/implementation/git.d.ts +25 -0
  97. package/types/apps/src/implementation/graphql-catalog.d.ts +7 -0
  98. package/types/apps/src/implementation/graphql.d.ts +81 -3
  99. package/types/apps/src/implementation/inflate.d.ts +16 -0
  100. package/types/apps/src/implementation/input-problems.d.ts +3 -0
  101. package/types/apps/src/implementation/mcp-call.d.ts +3 -2
  102. package/types/apps/src/implementation/mcp-catalog.d.ts +9 -0
  103. package/types/apps/src/implementation/mcp-client.d.ts +39 -22
  104. package/types/apps/src/implementation/mcp-stdio.d.ts +1 -1
  105. package/types/apps/src/implementation/mcp-tools.d.ts +6 -3
  106. package/types/apps/src/implementation/mcp.d.ts +55 -2
  107. package/types/apps/src/implementation/openapi-compile.d.ts +120 -0
  108. package/types/apps/src/implementation/openapi-document.d.ts +51 -0
  109. package/types/apps/src/implementation/openapi-names.d.ts +18 -0
  110. package/types/apps/src/implementation/openapi-request.d.ts +10 -4
  111. package/types/apps/src/implementation/openapi-source.d.ts +36 -0
  112. package/types/apps/src/implementation/openapi.d.ts +39 -3
  113. package/types/apps/src/implementation/operations.d.ts +26 -3
  114. package/types/apps/src/implementation/protocol-operations.d.ts +3 -4
  115. package/types/apps/src/implementation/provider-error.d.ts +10 -0
  116. package/types/apps/src/implementation/provider.d.ts +9 -4
  117. package/types/apps/src/implementation/router-catalog.d.ts +225 -0
  118. package/types/apps/src/implementation/router.d.ts +59 -0
  119. package/types/apps/src/implementation/schema.d.ts +11 -6
  120. package/types/apps/src/implementation/skill-files.d.ts +10 -0
  121. package/types/apps/src/implementation/skills.d.ts +43 -0
  122. package/types/apps/src/implementation/storage.d.ts +5 -3
  123. package/types/apps/src/implementation/swagger-client.d.ts +28 -0
  124. package/types/apps/src/implementation/ui-auth.d.ts +11 -5
  125. package/types/apps/src/implementation/ui-serving.d.ts +4 -2
  126. package/types/apps/src/implementation/webhooks.d.ts +1 -1
  127. package/types/apps/src/implementation/workflow-context.d.ts +11 -3
  128. package/types/apps/src/index.d.ts +11 -3
  129. package/types/apps/src/mcp-stdio.d.ts +2 -5
  130. package/types/apps/src/mcp.d.ts +8 -7
  131. package/types/apps/src/openapi.d.ts +8 -6
  132. package/types/apps/src/skills.d.ts +75 -0
  133. package/types/apps/src/ui-auth.d.ts +2 -2
  134. package/types/telemetry/src/browser-operations.d.ts +5 -2
  135. package/types/telemetry/src/config.d.ts +2 -0
  136. package/js/chunk-22WRQZT7.js +0 -389
  137. package/js/chunk-BKVL7XAJ.js +0 -47
  138. package/js/chunk-C24KEZXR.js +0 -59
  139. package/js/chunk-LOKGDT6B.js +0 -28
  140. package/js/chunk-MLKGABMK.js +0 -9
  141. package/types/apps/src/implementation/account-operations.d.ts +0 -32
@@ -1,28 +1,28 @@
1
1
  import {
2
2
  prepareElicitation
3
- } from "./chunk-Q2FD5IBM.js";
3
+ } from "./chunk-V5KNQVCT.js";
4
4
  import {
5
5
  fromPromise
6
- } from "./chunk-X3YBZCJW.js";
6
+ } from "./chunk-Z5M2LQOZ.js";
7
7
  import {
8
+ ElicitationFailed,
8
9
  McpError,
10
+ McpServerHeader,
9
11
  McpToolMetadata,
10
12
  McpToolResult,
13
+ RouterIcon,
11
14
  ToolResultObservation,
15
+ defaultElicitationLimits,
12
16
  defaultMcpClientLimits,
13
17
  mcpSdkTimerCeilingMs
14
- } from "./chunk-22WRQZT7.js";
15
- import {
16
- ElicitationFailed,
17
- defaultElicitationLimits
18
- } from "./chunk-HP7E42X6.js";
18
+ } from "./chunk-WLE7WX2U.js";
19
19
  import {
20
20
  compileJsonSchemaDecoder,
21
21
  jsonSchemaDecoder
22
- } from "./chunk-BPEFS4YF.js";
22
+ } from "./chunk-5T57N25Q.js";
23
23
  import {
24
24
  JsonObject
25
- } from "./chunk-36DNRFZQ.js";
25
+ } from "./chunk-27F7W2LG.js";
26
26
  import {
27
27
  Clock_exports,
28
28
  Deferred_exports,
@@ -31,54 +31,51 @@ import {
31
31
  Option_exports,
32
32
  Queue_exports,
33
33
  Schema_exports
34
- } from "./chunk-2OTCEKL2.js";
34
+ } from "./chunk-CDL5PM2Q.js";
35
35
 
36
36
  // src/implementation/mcp-tools.ts
37
+ var adaptMcpTool = (client, tool) => Effect_exports.gen(function* () {
38
+ const decoder = yield* jsonSchemaDecoder(tool.inputSchema).pipe(
39
+ Effect_exports.mapError(() => new McpError({ phase: "schema", reason: "invalid_response" }))
40
+ );
41
+ const output = tool.outputSchema === void 0 ? void 0 : yield* Effect_exports.cached(
42
+ compileJsonSchemaDecoder(tool.outputSchema).pipe(
43
+ Effect_exports.mapError(() => new McpError({ phase: "schema", reason: "invalid_response" }))
44
+ )
45
+ );
46
+ const adapted = {
47
+ ...tool,
48
+ description: tool.description ?? tool.title ?? tool.name,
49
+ input: decoder,
50
+ ...tool.annotations?.readOnlyHint === void 0 ? {} : { readOnly: tool.annotations.readOnlyHint },
51
+ run: (context, input) => Effect_exports.gen(function* () {
52
+ const arguments_ = yield* Schema_exports.decodeUnknownEffect(decoder)(input).pipe(
53
+ Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(JsonObject)),
54
+ Effect_exports.mapError(() => new McpError({ phase: "call", reason: "invalid_input" }))
55
+ );
56
+ const outputDecoder = output === void 0 ? void 0 : yield* output;
57
+ const result = yield* client.call(tool.name, arguments_, context);
58
+ if (result.isError === true) {
59
+ (yield* ToolResultObservation).failed();
60
+ yield* Effect_exports.annotateCurrentSpan({
61
+ "executor.outcome": "failed",
62
+ "error.type": "McpToolError"
63
+ });
64
+ }
65
+ if (outputDecoder !== void 0 && !result.isError)
66
+ yield* Schema_exports.decodeUnknownEffect(outputDecoder)(result.structuredContent).pipe(
67
+ Effect_exports.mapError(() => new McpError({ phase: "call", reason: "invalid_response" }))
68
+ );
69
+ return result;
70
+ })
71
+ };
72
+ return adapted;
73
+ });
37
74
  var adaptMcpTools = (client) => Effect_exports.gen(function* () {
38
- const metadata = yield* client.list;
75
+ const { tools: metadata } = yield* client.list;
39
76
  const entries = yield* Effect_exports.forEach(
40
77
  metadata,
41
- (tool) => Effect_exports.gen(function* () {
42
- const decoder = yield* jsonSchemaDecoder(tool.inputSchema).pipe(
43
- Effect_exports.mapError(() => new McpError({ phase: "schema", reason: "invalid_response" }))
44
- );
45
- const output = tool.outputSchema === void 0 ? void 0 : yield* Effect_exports.cached(
46
- compileJsonSchemaDecoder(tool.outputSchema).pipe(
47
- Effect_exports.mapError(
48
- () => new McpError({ phase: "schema", reason: "invalid_response" })
49
- )
50
- )
51
- );
52
- const adapted = {
53
- ...tool,
54
- description: tool.description ?? tool.title ?? tool.name,
55
- input: decoder,
56
- ...tool.annotations?.readOnlyHint === void 0 ? {} : { readOnly: tool.annotations.readOnlyHint },
57
- run: (context, input) => Effect_exports.gen(function* () {
58
- const arguments_ = yield* Schema_exports.decodeUnknownEffect(decoder)(input).pipe(
59
- Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(JsonObject)),
60
- Effect_exports.mapError(() => new McpError({ phase: "call", reason: "invalid_input" }))
61
- );
62
- const outputDecoder = output === void 0 ? void 0 : yield* output;
63
- const result = yield* client.call(tool.name, arguments_, context);
64
- if (result.isError === true) {
65
- (yield* ToolResultObservation).failed();
66
- yield* Effect_exports.annotateCurrentSpan({
67
- "executor.outcome": "failed",
68
- "error.type": "McpToolError"
69
- });
70
- }
71
- if (outputDecoder !== void 0 && !result.isError)
72
- yield* Schema_exports.decodeUnknownEffect(outputDecoder)(result.structuredContent).pipe(
73
- Effect_exports.mapError(
74
- () => new McpError({ phase: "call", reason: "invalid_response" })
75
- )
76
- );
77
- return result;
78
- })
79
- };
80
- return [tool.name, adapted];
81
- })
78
+ (tool) => adaptMcpTool(client, tool).pipe(Effect_exports.map((adapted) => [tool.name, adapted]))
82
79
  );
83
80
  return Object.fromEntries(entries);
84
81
  });
@@ -238,7 +235,7 @@ function mcpClient(withClient, timeoutMs, failure) {
238
235
  do {
239
236
  const page = yield* Effect_exports.tryPromise({
240
237
  // This session only reads metadata. listTools() also eagerly compiles
241
- // every output validator; mcpOperations validates the selected tool on call.
238
+ // every output validator; mcpRouter validates the selected tool on call.
242
239
  try: (signal) => client.request(
243
240
  { method: "tools/list", params: cursor === void 0 ? {} : { cursor } },
244
241
  ListToolsResultSchema,
@@ -268,7 +265,24 @@ function mcpClient(withClient, timeoutMs, failure) {
268
265
  cursors.add(cursor);
269
266
  }
270
267
  } while (cursor !== void 0);
271
- return [...tools.values()];
268
+ const info = client.getServerVersion();
269
+ const instructions = client.getInstructions();
270
+ const icons = info?.icons?.flatMap(
271
+ (icon) => Option_exports.toArray(Schema_exports.decodeUnknownOption(RouterIcon)(icon))
272
+ );
273
+ const server = Schema_exports.decodeUnknownOption(McpServerHeader)({
274
+ ...info?.name === void 0 ? {} : { name: info.name },
275
+ ...info?.title === void 0 ? {} : { title: info.title },
276
+ ...info?.version === void 0 ? {} : { version: info.version },
277
+ ...info?.description === void 0 ? {} : { description: info.description },
278
+ ...info?.websiteUrl === void 0 ? {} : { websiteUrl: info.websiteUrl },
279
+ ...icons === void 0 ? {} : { icons },
280
+ ...instructions === void 0 ? {} : { instructions }
281
+ });
282
+ return {
283
+ tools: [...tools.values()],
284
+ server: Option_exports.getOrElse(server, () => ({}))
285
+ };
272
286
  })
273
287
  ).pipe(Effect_exports.withSpan("provider.mcp.discover"));
274
288
  const call = (name, input, context) => withClient("call", (client) => mcpCall(client, name, input, context, timeoutMs, failure)).pipe(
@@ -278,6 +292,7 @@ function mcpClient(withClient, timeoutMs, failure) {
278
292
  }
279
293
 
280
294
  export {
295
+ adaptMcpTool,
281
296
  adaptMcpTools,
282
297
  mcpJsonSchemaValidator,
283
298
  mcpClient
@@ -0,0 +1,39 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ try {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ } catch (e) {
11
+ throw mod = 0, e;
12
+ }
13
+ };
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
+ // If the importer is in node compatibility mode or this is not an ESM
28
+ // file that has been converted to a CommonJS file using a Babel-
29
+ // compatible transform (i.e. "__esModule" has not been set), then set
30
+ // "default" to the CommonJS "module.exports" for node compatibility.
31
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
+ mod
33
+ ));
34
+
35
+ export {
36
+ __commonJS,
37
+ __export,
38
+ __toESM
39
+ };
@@ -2,54 +2,71 @@ import {
2
2
  adaptMcpTools,
3
3
  mcpClient,
4
4
  mcpJsonSchemaValidator
5
- } from "./chunk-KWTCHVLT.js";
5
+ } from "./chunk-CRDWFA74.js";
6
+ import {
7
+ accountProviderError,
8
+ httpProviderError
9
+ } from "./chunk-MKWZPDR6.js";
6
10
  import {
7
11
  McpError,
8
12
  McpToolsOptions,
9
13
  defaultMcpClientLimits
10
- } from "./chunk-22WRQZT7.js";
14
+ } from "./chunk-WLE7WX2U.js";
15
+ import {
16
+ ProviderError
17
+ } from "./chunk-R3EV5FTO.js";
11
18
  import {
12
19
  captureTelemetry
13
- } from "./chunk-OWD2YICM.js";
20
+ } from "./chunk-ODEIDRGW.js";
14
21
  import {
15
22
  FetchHttpClient_exports
16
- } from "./chunk-VFUZI3NY.js";
23
+ } from "./chunk-57RKNWL2.js";
17
24
  import {
18
25
  HttpClientRequest_exports,
19
26
  HttpClient_exports
20
- } from "./chunk-W7Q5EOTS.js";
27
+ } from "./chunk-UK573G7W.js";
21
28
  import {
29
+ Deferred_exports,
22
30
  Effect_exports,
23
31
  Redacted_exports,
24
32
  Schema_exports,
25
33
  Stream_exports
26
- } from "./chunk-2OTCEKL2.js";
34
+ } from "./chunk-CDL5PM2Q.js";
27
35
 
28
36
  // src/implementation/mcp.ts
29
37
  import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js";
30
38
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
31
- import { ErrorCode, McpError as ProtocolError } from "@modelcontextprotocol/sdk/types.js";
39
+ import {
40
+ ErrorCode,
41
+ McpError as ProtocolError,
42
+ ToolListChangedNotificationSchema
43
+ } from "@modelcontextprotocol/sdk/types.js";
32
44
  import { SSEClientTransport, SseError } from "@modelcontextprotocol/sdk/client/sse.js";
33
45
  import {
34
46
  StreamableHTTPClientTransport,
35
47
  StreamableHTTPError
36
48
  } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
37
49
  var failure = (phase, error) => {
50
+ if (Schema_exports.is(ProviderError)(error) || Schema_exports.is(McpError)(error)) return error;
38
51
  const status = error instanceof UnauthorizedError ? 401 : error instanceof StreamableHTTPError || error instanceof SseError ? error.code : void 0;
52
+ const provider = status === void 0 ? void 0 : httpProviderError(status);
53
+ if (provider !== void 0) return provider;
39
54
  return new McpError({
40
55
  phase,
41
- reason: error instanceof ProtocolError && error.code === ErrorCode.RequestTimeout ? "timeout" : status === 401 || status === 403 ? "unauthorized" : "request",
56
+ reason: error instanceof ProtocolError && error.code === ErrorCode.RequestTimeout ? "timeout" : "request",
42
57
  ...status === void 0 ? {} : { status }
43
58
  });
44
59
  };
45
- var transportFetch = (connection, telemetry) => (url, init) => Effect_exports.runPromiseWith(telemetry.context)(
60
+ var transportFetch = (connection, telemetry, rejected) => (url, init) => Effect_exports.runPromiseWith(telemetry.context)(
46
61
  Effect_exports.gen(function* () {
47
62
  const target = yield* Effect_exports.try({
48
63
  try: () => new URL(url),
49
- catch: () => failure("transport", void 0)
64
+ catch: () => new McpError({ phase: "transport", reason: "invalid_response" })
50
65
  });
66
+ if (connection.url.username || connection.url.password)
67
+ return yield* new McpError({ phase: "transport", reason: "invalid_input" });
51
68
  if (target.origin !== connection.url.origin || target.username || target.password)
52
- return yield* failure("transport", void 0);
69
+ return yield* new McpError({ phase: "transport", reason: "invalid_response" });
53
70
  const headers = new Headers(Redacted_exports.value(connection.headers));
54
71
  new Headers(init?.headers).forEach((value, name) => headers.set(name, value));
55
72
  const request = yield* Effect_exports.try({
@@ -58,6 +75,11 @@ var transportFetch = (connection, telemetry) => (url, init) => Effect_exports.ru
58
75
  });
59
76
  const client = yield* HttpClient_exports.HttpClient;
60
77
  const response = yield* client.execute(request);
78
+ const provider = httpProviderError(response.status, response.headers);
79
+ if (provider !== void 0) {
80
+ yield* Deferred_exports.fail(rejected, provider);
81
+ return yield* provider;
82
+ }
61
83
  return new Response(
62
84
  [204, 205, 304].includes(response.status) ? null : Stream_exports.toReadableStream(response.stream),
63
85
  {
@@ -78,25 +100,40 @@ var transportFetch = (connection, telemetry) => (url, init) => Effect_exports.ru
78
100
  ])
79
101
  })
80
102
  ),
81
- Effect_exports.mapError(() => failure("transport", void 0))
103
+ Effect_exports.mapError((error) => failure("transport", error))
82
104
  ),
83
105
  init?.signal ? { signal: init.signal } : {}
84
106
  );
85
- function withClient(connection, mode, use) {
107
+ function withClient(connection, mode, use, changed) {
86
108
  const attempt = (kind) => Effect_exports.scoped(
87
109
  Effect_exports.gen(function* () {
88
110
  const telemetry = yield* captureTelemetry;
111
+ const rejected = yield* Deferred_exports.make();
112
+ const pending = /* @__PURE__ */ new Set();
89
113
  const { client, transport } = yield* Effect_exports.acquireRelease(
90
114
  Effect_exports.sync(() => {
91
- const fetch = transportFetch(connection, telemetry);
115
+ const fetch = transportFetch(connection, telemetry, rejected);
116
+ const client2 = new Client(
117
+ { name: "executor-apps", version: "0.1.0" },
118
+ {
119
+ jsonSchemaValidator: mcpJsonSchemaValidator,
120
+ capabilities: mode === "call" ? { elicitation: { form: {} } } : {}
121
+ }
122
+ );
123
+ if (changed !== void 0) {
124
+ client2.setNotificationHandler(ToolListChangedNotificationSchema, () => {
125
+ const task = Effect_exports.runPromiseWith(telemetry.context)(
126
+ changed.pipe(
127
+ Effect_exports.timeout("5 seconds"),
128
+ Effect_exports.catchCause(() => Effect_exports.logWarning("MCP catalog invalidation failed"))
129
+ )
130
+ );
131
+ pending.add(task);
132
+ return task.finally(() => pending.delete(task));
133
+ });
134
+ }
92
135
  return {
93
- client: new Client(
94
- { name: "executor-apps", version: "0.1.0" },
95
- {
96
- jsonSchemaValidator: mcpJsonSchemaValidator,
97
- capabilities: mode === "call" ? { elicitation: { form: {} } } : {}
98
- }
99
- ),
136
+ client: client2,
100
137
  transport: kind === "http" ? new StreamableHTTPClientTransport(connection.url, {
101
138
  fetch,
102
139
  reconnectionOptions: {
@@ -109,6 +146,10 @@ function withClient(connection, mode, use) {
109
146
  };
110
147
  }),
111
148
  ({ client: client2, transport: transport2 }) => Effect_exports.gen(function* () {
149
+ client2.removeNotificationHandler("notifications/tools/list_changed");
150
+ yield* Effect_exports.promise(async () => {
151
+ await Promise.allSettled(pending);
152
+ });
112
153
  if (transport2 instanceof StreamableHTTPClientTransport && transport2.sessionId !== void 0) {
113
154
  yield* Effect_exports.tryPromise(() => transport2.terminateSession()).pipe(
114
155
  Effect_exports.timeout(defaultMcpClientLimits.cleanupTimeoutMs),
@@ -125,8 +166,12 @@ function withClient(connection, mode, use) {
125
166
  yield* Effect_exports.tryPromise({
126
167
  try: (signal) => client.connect(wire, { signal, timeout: connection.timeoutMs }),
127
168
  catch: (error) => failure("connect", error)
128
- }).pipe(Effect_exports.timeout(connection.timeoutMs), Effect_exports.withSpan("provider.mcp.connect"));
129
- return yield* use(client);
169
+ }).pipe(
170
+ Effect_exports.raceFirst(Deferred_exports.await(rejected)),
171
+ Effect_exports.timeout(connection.timeoutMs),
172
+ Effect_exports.withSpan("provider.mcp.connect")
173
+ );
174
+ return yield* use(client).pipe(Effect_exports.raceFirst(Deferred_exports.await(rejected)));
130
175
  })
131
176
  ).pipe(
132
177
  Effect_exports.withSpan("provider.mcp.session", {
@@ -149,7 +194,7 @@ function withClient(connection, mode, use) {
149
194
  )
150
195
  );
151
196
  }
152
- var mcpToolsEffect = (input) => Effect_exports.gen(function* () {
197
+ var mcpClientEffect = (input, changed) => Effect_exports.gen(function* () {
153
198
  const options = yield* Schema_exports.decodeUnknownEffect(McpToolsOptions)(input).pipe(
154
199
  Effect_exports.mapError(() => new McpError({ phase: "connect", reason: "invalid_input" }))
155
200
  );
@@ -161,11 +206,19 @@ var mcpToolsEffect = (input) => Effect_exports.gen(function* () {
161
206
  headers: Redacted_exports.make({ ...options.headers }),
162
207
  timeoutMs: options.timeoutMs ?? defaultMcpClientLimits.timeoutMs
163
208
  };
164
- return yield* adaptMcpTools(
165
- mcpClient((mode, use) => withClient(connection, mode, use), connection.timeoutMs, failure)
209
+ return mcpClient(
210
+ (mode, use) => withClient(connection, mode, use, changed).pipe(
211
+ Effect_exports.mapError(
212
+ (error) => options.accountId === void 0 ? error : accountProviderError(error, options.accountId)
213
+ )
214
+ ),
215
+ connection.timeoutMs,
216
+ failure
166
217
  );
167
218
  });
219
+ var mcpToolsEffect = (input) => mcpClientEffect(input).pipe(Effect_exports.flatMap(adaptMcpTools));
168
220
 
169
221
  export {
222
+ mcpClientEffect,
170
223
  mcpToolsEffect
171
224
  };