@apollo/client-ai-apps 0.6.4 → 0.7.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 (272) hide show
  1. package/CHANGELOG.md +100 -0
  2. package/CONTRIBUTING.md +195 -0
  3. package/README.md +74 -0
  4. package/dist/core/AbstractApolloClient.d.ts +33 -0
  5. package/dist/core/AbstractApolloClient.d.ts.map +1 -0
  6. package/dist/core/AbstractApolloClient.js +129 -0
  7. package/dist/core/AbstractApolloClient.js.map +1 -0
  8. package/dist/core/ApolloClient.d.ts +3 -7
  9. package/dist/core/ApolloClient.d.ts.map +1 -1
  10. package/dist/core/ApolloClient.js +5 -4
  11. package/dist/core/ApolloClient.js.map +1 -1
  12. package/dist/core/McpAppManager.d.ts +42 -0
  13. package/dist/core/McpAppManager.d.ts.map +1 -0
  14. package/dist/core/McpAppManager.js +56 -0
  15. package/dist/core/McpAppManager.js.map +1 -0
  16. package/dist/core/typeRegistration.d.ts +0 -14
  17. package/dist/core/typeRegistration.d.ts.map +1 -1
  18. package/dist/core/typeRegistration.js.map +1 -1
  19. package/dist/core/types.d.ts +2 -1
  20. package/dist/core/types.d.ts.map +1 -1
  21. package/dist/core/types.js.map +1 -1
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/index.mcp.d.ts +0 -1
  26. package/dist/index.mcp.d.ts.map +1 -1
  27. package/dist/index.mcp.js +0 -1
  28. package/dist/index.mcp.js.map +1 -1
  29. package/dist/index.openai.d.ts +0 -1
  30. package/dist/index.openai.d.ts.map +1 -1
  31. package/dist/index.openai.js +0 -1
  32. package/dist/index.openai.js.map +1 -1
  33. package/dist/link/ToolCallLink.d.ts +6 -1
  34. package/dist/link/ToolCallLink.d.ts.map +1 -1
  35. package/dist/link/ToolCallLink.js +17 -4
  36. package/dist/link/ToolCallLink.js.map +1 -1
  37. package/dist/link/ToolHydrationLink.d.ts +21 -0
  38. package/dist/link/ToolHydrationLink.d.ts.map +1 -0
  39. package/dist/link/ToolHydrationLink.js +57 -0
  40. package/dist/link/ToolHydrationLink.js.map +1 -0
  41. package/dist/mcp/core/ApolloClient.d.ts +3 -20
  42. package/dist/mcp/core/ApolloClient.d.ts.map +1 -1
  43. package/dist/mcp/core/ApolloClient.js +20 -98
  44. package/dist/mcp/core/ApolloClient.js.map +1 -1
  45. package/dist/mcp/index.d.ts +0 -1
  46. package/dist/mcp/index.d.ts.map +1 -1
  47. package/dist/mcp/index.js +0 -1
  48. package/dist/mcp/index.js.map +1 -1
  49. package/dist/openai/core/ApolloClient.d.ts +3 -20
  50. package/dist/openai/core/ApolloClient.d.ts.map +1 -1
  51. package/dist/openai/core/ApolloClient.js +36 -98
  52. package/dist/openai/core/ApolloClient.js.map +1 -1
  53. package/dist/openai/index.d.ts +0 -1
  54. package/dist/openai/index.d.ts.map +1 -1
  55. package/dist/openai/index.js +0 -1
  56. package/dist/openai/index.js.map +1 -1
  57. package/dist/openai/react/index.d.ts +0 -7
  58. package/dist/openai/react/index.d.ts.map +1 -1
  59. package/dist/openai/react/index.js +0 -7
  60. package/dist/openai/react/index.js.map +1 -1
  61. package/dist/react/ApolloProvider.d.ts.map +1 -1
  62. package/dist/react/ApolloProvider.js +1 -1
  63. package/dist/react/ApolloProvider.js.map +1 -1
  64. package/dist/{mcp/react/hooks → react}/createHydrationUtils.d.ts +1 -1
  65. package/dist/react/createHydrationUtils.d.ts.map +1 -0
  66. package/dist/{mcp/react/hooks → react}/createHydrationUtils.js +7 -9
  67. package/dist/react/createHydrationUtils.js.map +1 -0
  68. package/dist/react/hooks/internal/useApolloClient.d.ts +3 -0
  69. package/dist/react/hooks/internal/useApolloClient.d.ts.map +1 -0
  70. package/dist/{mcp/react/hooks → react/hooks/internal}/useApolloClient.js +3 -3
  71. package/dist/react/hooks/internal/useApolloClient.js.map +1 -0
  72. package/dist/react/hooks/useApp.d.ts.map +1 -0
  73. package/dist/react/hooks/useApp.js +5 -0
  74. package/dist/react/hooks/useApp.js.map +1 -0
  75. package/dist/react/hooks/useHostContext.d.ts.map +1 -0
  76. package/dist/{openai/react → react}/hooks/useHostContext.js +1 -1
  77. package/dist/react/hooks/useHostContext.js.map +1 -0
  78. package/dist/react/hooks/useToolInfo.d.ts +3 -0
  79. package/dist/react/hooks/useToolInfo.d.ts.map +1 -0
  80. package/dist/react/hooks/useToolInfo.js +5 -0
  81. package/dist/react/hooks/useToolInfo.js.map +1 -0
  82. package/dist/react/hooks/useToolMetadata.d.ts +2 -0
  83. package/dist/react/hooks/useToolMetadata.d.ts.map +1 -0
  84. package/dist/react/hooks/useToolMetadata.js +5 -0
  85. package/dist/react/hooks/useToolMetadata.js.map +1 -0
  86. package/dist/react/index.d.ts +5 -16
  87. package/dist/react/index.d.ts.map +1 -1
  88. package/dist/react/index.js +5 -19
  89. package/dist/react/index.js.map +1 -1
  90. package/dist/types/application-manifest.d.ts +1 -0
  91. package/dist/types/application-manifest.d.ts.map +1 -1
  92. package/dist/types/application-manifest.js.map +1 -1
  93. package/dist/utilities/connectToHost.d.ts +3 -0
  94. package/dist/utilities/connectToHost.d.ts.map +1 -0
  95. package/dist/utilities/connectToHost.js +11 -0
  96. package/dist/utilities/connectToHost.js.map +1 -0
  97. package/dist/utilities/index.d.ts +1 -0
  98. package/dist/utilities/index.d.ts.map +1 -1
  99. package/dist/utilities/index.js +1 -0
  100. package/dist/utilities/index.js.map +1 -1
  101. package/dist/vite/apolloClientAiApps.d.ts.map +1 -1
  102. package/dist/vite/apolloClientAiApps.js +2 -0
  103. package/dist/vite/apolloClientAiApps.js.map +1 -1
  104. package/package.json +5 -22
  105. package/src/core/AbstractApolloClient.ts +217 -0
  106. package/src/core/ApolloClient.ts +8 -10
  107. package/src/core/McpAppManager.ts +106 -0
  108. package/src/core/typeRegistration.ts +0 -15
  109. package/src/core/types.ts +2 -1
  110. package/src/index.mcp.ts +0 -1
  111. package/src/index.openai.ts +0 -1
  112. package/src/index.ts +1 -6
  113. package/src/link/ToolCallLink.ts +27 -5
  114. package/src/link/ToolHydrationLink.ts +90 -0
  115. package/src/link/__tests__/ToolCallLink.test.ts +99 -0
  116. package/src/mcp/core/ApolloClient.ts +32 -165
  117. package/src/mcp/core/__tests__/ApolloClient.test.ts +571 -71
  118. package/src/mcp/index.ts +0 -1
  119. package/src/openai/core/ApolloClient.ts +48 -161
  120. package/src/openai/core/__tests__/ApolloClient.test.ts +916 -118
  121. package/src/openai/index.ts +0 -1
  122. package/src/openai/react/index.ts +0 -7
  123. package/src/react/ApolloProvider.tsx +1 -6
  124. package/src/react/__tests__/ApolloProvider/mcp.test.tsx +66 -29
  125. package/src/react/__tests__/ApolloProvider/openai.test.tsx +16 -41
  126. package/src/react/__tests__/createHydrationUtils.test.tsx +1260 -0
  127. package/src/{mcp/react/hooks → react}/createHydrationUtils.ts +7 -10
  128. package/src/react/hooks/__tests__/useApp.test.tsx +46 -0
  129. package/src/react/hooks/__tests__/useHostContext.test.tsx +99 -0
  130. package/src/react/hooks/__tests__/useToolInfo.test.tsx +98 -0
  131. package/src/react/hooks/__tests__/useToolMetadata.test.tsx +58 -0
  132. package/src/{mcp/react/hooks → react/hooks/internal}/useApolloClient.ts +3 -3
  133. package/src/{mcp/react → react}/hooks/useApp.ts +1 -1
  134. package/src/{openai/react → react}/hooks/useHostContext.ts +1 -1
  135. package/src/react/hooks/useToolInfo.ts +6 -0
  136. package/src/react/hooks/useToolMetadata.ts +5 -0
  137. package/src/react/index.ts +5 -36
  138. package/src/testing/internal/graphql/parseManifestOperation.ts +87 -0
  139. package/src/testing/internal/index.ts +3 -0
  140. package/src/testing/internal/matchers/index.ts +1 -0
  141. package/src/testing/internal/matchers/toEmitAnything.ts +43 -0
  142. package/src/testing/internal/matchers/types.ts +1 -0
  143. package/src/testing/internal/mcp/mockMcpHost.ts +25 -4
  144. package/src/testing/internal/tests/eachHostEnv.ts +22 -0
  145. package/src/testing/internal/utilities/createHostEnv.ts +117 -0
  146. package/src/types/application-manifest.ts +1 -0
  147. package/src/utilities/connectToHost.ts +13 -0
  148. package/src/utilities/index.ts +1 -0
  149. package/src/vite/__tests__/apolloClientAiApps.test.ts +56 -0
  150. package/src/vite/apolloClientAiApps.ts +5 -0
  151. package/tsconfig.vite.json +1 -1
  152. package/vitest.config.ts +13 -0
  153. package/dist/mcp/core/McpAppManager.d.ts +0 -30
  154. package/dist/mcp/core/McpAppManager.d.ts.map +0 -1
  155. package/dist/mcp/core/McpAppManager.js +0 -82
  156. package/dist/mcp/core/McpAppManager.js.map +0 -1
  157. package/dist/mcp/link/ToolCallLink.d.ts +0 -28
  158. package/dist/mcp/link/ToolCallLink.d.ts.map +0 -1
  159. package/dist/mcp/link/ToolCallLink.js +0 -35
  160. package/dist/mcp/link/ToolCallLink.js.map +0 -1
  161. package/dist/mcp/react/hooks/createHydrationUtils.d.ts.map +0 -1
  162. package/dist/mcp/react/hooks/createHydrationUtils.js.map +0 -1
  163. package/dist/mcp/react/hooks/useApolloClient.d.ts +0 -3
  164. package/dist/mcp/react/hooks/useApolloClient.d.ts.map +0 -1
  165. package/dist/mcp/react/hooks/useApolloClient.js.map +0 -1
  166. package/dist/mcp/react/hooks/useApp.d.ts.map +0 -1
  167. package/dist/mcp/react/hooks/useApp.js +0 -5
  168. package/dist/mcp/react/hooks/useApp.js.map +0 -1
  169. package/dist/mcp/react/hooks/useHostContext.d.ts.map +0 -1
  170. package/dist/mcp/react/hooks/useHostContext.js +0 -7
  171. package/dist/mcp/react/hooks/useHostContext.js.map +0 -1
  172. package/dist/mcp/react/hooks/useToolInfo.d.ts +0 -3
  173. package/dist/mcp/react/hooks/useToolInfo.d.ts.map +0 -1
  174. package/dist/mcp/react/hooks/useToolInfo.js +0 -10
  175. package/dist/mcp/react/hooks/useToolInfo.js.map +0 -1
  176. package/dist/mcp/react/hooks/useToolInput.d.ts +0 -7
  177. package/dist/mcp/react/hooks/useToolInput.d.ts.map +0 -1
  178. package/dist/mcp/react/hooks/useToolInput.js +0 -9
  179. package/dist/mcp/react/hooks/useToolInput.js.map +0 -1
  180. package/dist/mcp/react/hooks/useToolMetadata.d.ts +0 -2
  181. package/dist/mcp/react/hooks/useToolMetadata.d.ts.map +0 -1
  182. package/dist/mcp/react/hooks/useToolMetadata.js +0 -5
  183. package/dist/mcp/react/hooks/useToolMetadata.js.map +0 -1
  184. package/dist/mcp/react/hooks/useToolName.d.ts +0 -7
  185. package/dist/mcp/react/hooks/useToolName.d.ts.map +0 -1
  186. package/dist/mcp/react/hooks/useToolName.js +0 -9
  187. package/dist/mcp/react/hooks/useToolName.js.map +0 -1
  188. package/dist/mcp/react/index.d.ts +0 -8
  189. package/dist/mcp/react/index.d.ts.map +0 -1
  190. package/dist/mcp/react/index.js +0 -8
  191. package/dist/mcp/react/index.js.map +0 -1
  192. package/dist/openai/core/McpAppManager.d.ts +0 -29
  193. package/dist/openai/core/McpAppManager.d.ts.map +0 -1
  194. package/dist/openai/core/McpAppManager.js +0 -91
  195. package/dist/openai/core/McpAppManager.js.map +0 -1
  196. package/dist/openai/link/ToolCallLink.d.ts +0 -28
  197. package/dist/openai/link/ToolCallLink.d.ts.map +0 -1
  198. package/dist/openai/link/ToolCallLink.js +0 -35
  199. package/dist/openai/link/ToolCallLink.js.map +0 -1
  200. package/dist/openai/react/hooks/createHydrationUtils.d.ts +0 -15
  201. package/dist/openai/react/hooks/createHydrationUtils.d.ts.map +0 -1
  202. package/dist/openai/react/hooks/createHydrationUtils.js +0 -113
  203. package/dist/openai/react/hooks/createHydrationUtils.js.map +0 -1
  204. package/dist/openai/react/hooks/useApp.d.ts +0 -2
  205. package/dist/openai/react/hooks/useApp.d.ts.map +0 -1
  206. package/dist/openai/react/hooks/useApp.js +0 -5
  207. package/dist/openai/react/hooks/useApp.js.map +0 -1
  208. package/dist/openai/react/hooks/useHostContext.d.ts +0 -2
  209. package/dist/openai/react/hooks/useHostContext.d.ts.map +0 -1
  210. package/dist/openai/react/hooks/useHostContext.js.map +0 -1
  211. package/dist/openai/react/hooks/useToolInfo.d.ts +0 -3
  212. package/dist/openai/react/hooks/useToolInfo.d.ts.map +0 -1
  213. package/dist/openai/react/hooks/useToolInfo.js +0 -10
  214. package/dist/openai/react/hooks/useToolInfo.js.map +0 -1
  215. package/dist/openai/react/hooks/useToolInput.d.ts +0 -7
  216. package/dist/openai/react/hooks/useToolInput.d.ts.map +0 -1
  217. package/dist/openai/react/hooks/useToolInput.js +0 -9
  218. package/dist/openai/react/hooks/useToolInput.js.map +0 -1
  219. package/dist/openai/react/hooks/useToolMetadata.d.ts +0 -2
  220. package/dist/openai/react/hooks/useToolMetadata.d.ts.map +0 -1
  221. package/dist/openai/react/hooks/useToolMetadata.js +0 -5
  222. package/dist/openai/react/hooks/useToolMetadata.js.map +0 -1
  223. package/dist/openai/react/hooks/useToolName.d.ts +0 -7
  224. package/dist/openai/react/hooks/useToolName.d.ts.map +0 -1
  225. package/dist/openai/react/hooks/useToolName.js +0 -9
  226. package/dist/openai/react/hooks/useToolName.js.map +0 -1
  227. package/dist/react/index.mcp.d.ts +0 -3
  228. package/dist/react/index.mcp.d.ts.map +0 -1
  229. package/dist/react/index.mcp.js +0 -3
  230. package/dist/react/index.mcp.js.map +0 -1
  231. package/dist/react/index.openai.d.ts +0 -3
  232. package/dist/react/index.openai.d.ts.map +0 -1
  233. package/dist/react/index.openai.js +0 -3
  234. package/dist/react/index.openai.js.map +0 -1
  235. package/dist/react/missingHook.d.ts +0 -2
  236. package/dist/react/missingHook.d.ts.map +0 -1
  237. package/dist/react/missingHook.js +0 -6
  238. package/dist/react/missingHook.js.map +0 -1
  239. package/src/mcp/core/McpAppManager.ts +0 -129
  240. package/src/mcp/link/ToolCallLink.ts +0 -40
  241. package/src/mcp/link/__tests__/ToolCallLink.test.ts +0 -62
  242. package/src/mcp/react/hooks/__tests__/createHydrationUtils.test.tsx +0 -1228
  243. package/src/mcp/react/hooks/__tests__/useApp.test.tsx +0 -46
  244. package/src/mcp/react/hooks/__tests__/useHostContext.test.tsx +0 -95
  245. package/src/mcp/react/hooks/__tests__/useToolInfo.test.tsx +0 -53
  246. package/src/mcp/react/hooks/__tests__/useToolInput.test.tsx +0 -50
  247. package/src/mcp/react/hooks/__tests__/useToolMetadata.test.tsx +0 -53
  248. package/src/mcp/react/hooks/__tests__/useToolName.test.tsx +0 -50
  249. package/src/mcp/react/hooks/useHostContext.ts +0 -14
  250. package/src/mcp/react/hooks/useToolInfo.ts +0 -13
  251. package/src/mcp/react/hooks/useToolInput.ts +0 -10
  252. package/src/mcp/react/hooks/useToolMetadata.ts +0 -5
  253. package/src/mcp/react/hooks/useToolName.ts +0 -10
  254. package/src/mcp/react/index.ts +0 -7
  255. package/src/openai/core/McpAppManager.ts +0 -139
  256. package/src/openai/link/ToolCallLink.ts +0 -40
  257. package/src/openai/react/hooks/__tests__/createHydrationUtils.test.tsx +0 -1333
  258. package/src/openai/react/hooks/__tests__/useToolInfo.test.tsx +0 -92
  259. package/src/openai/react/hooks/__tests__/useToolInput.test.tsx +0 -85
  260. package/src/openai/react/hooks/__tests__/useToolMetadata.test.tsx +0 -86
  261. package/src/openai/react/hooks/__tests__/useToolName.test.tsx +0 -50
  262. package/src/openai/react/hooks/createHydrationUtils.ts +0 -182
  263. package/src/openai/react/hooks/useApp.ts +0 -5
  264. package/src/openai/react/hooks/useToolInfo.ts +0 -13
  265. package/src/openai/react/hooks/useToolInput.ts +0 -10
  266. package/src/openai/react/hooks/useToolMetadata.ts +0 -5
  267. package/src/openai/react/hooks/useToolName.ts +0 -10
  268. package/src/react/index.mcp.ts +0 -10
  269. package/src/react/index.openai.ts +0 -10
  270. package/src/react/missingHook.ts +0 -9
  271. /package/dist/{mcp/react → react}/hooks/useApp.d.ts +0 -0
  272. /package/dist/{mcp/react → react}/hooks/useHostContext.d.ts +0 -0
@@ -0,0 +1,42 @@
1
+ import { App, type McpUiHostContextChangedNotification } from "@modelcontextprotocol/ext-apps";
2
+ import type { ApplicationManifest } from "../types/application-manifest.js";
3
+ import type { FormattedExecutionResult } from "graphql";
4
+ import type { DocumentNode, OperationVariables } from "@apollo/client";
5
+ import type { ApolloMcpServerApps } from "./types.js";
6
+ interface ConnectToHostResult {
7
+ structuredContent: ApolloMcpServerApps.StructuredContent;
8
+ toolInput: Record<string, unknown> | undefined;
9
+ _meta: ApolloMcpServerApps.Meta | undefined;
10
+ }
11
+ export type ConnectToHostImplementation = (app: App) => Promise<ConnectToHostResult>;
12
+ /** @internal */
13
+ export declare class McpAppManager {
14
+ #private;
15
+ readonly app: App;
16
+ constructor(manifest: ApplicationManifest, connectToHost: ConnectToHostImplementation);
17
+ onHostContextChanged(cb: (params: McpUiHostContextChangedNotification["params"]) => void): () => void;
18
+ connect: (() => Promise<{
19
+ structuredContent: {
20
+ [x: string]: unknown;
21
+ result?: FormattedExecutionResult;
22
+ prefetch?: Record<string, FormattedExecutionResult>;
23
+ toolName?: string;
24
+ };
25
+ toolInput: Record<string, unknown> | undefined;
26
+ toolName: string | undefined;
27
+ _meta: ApolloMcpServerApps.Meta | undefined;
28
+ }>) & {
29
+ reset: () => void;
30
+ };
31
+ close(): Promise<void>;
32
+ executeQuery({ query, variables, }: {
33
+ query: DocumentNode;
34
+ variables: OperationVariables | undefined;
35
+ }): Promise<{
36
+ errors?: ReadonlyArray<import("graphql").GraphQLFormattedError>;
37
+ data?: import("graphql/jsutils/ObjMap.js").ObjMap<unknown> | null;
38
+ extensions?: import("graphql/jsutils/ObjMap.js").ObjMap<unknown>;
39
+ }>;
40
+ }
41
+ export {};
42
+ //# sourceMappingURL=McpAppManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"McpAppManager.d.ts","sourceRoot":"","sources":["../../src/core/McpAppManager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,KAAK,mCAAmC,EACzC,MAAM,gCAAgC,CAAC;AAExC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAGvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAOtD,UAAU,mBAAmB;IAC3B,iBAAiB,EAAE,mBAAmB,CAAC,iBAAiB,CAAC;IACzD,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAC/C,KAAK,EAAE,mBAAmB,CAAC,IAAI,GAAG,SAAS,CAAC;CAC7C;AAED,MAAM,MAAM,2BAA2B,GAAG,CACxC,GAAG,EAAE,GAAG,KACL,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAElC,gBAAgB;AAChB,qBAAa,aAAa;;IACxB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;gBAShB,QAAQ,EAAE,mBAAmB,EAC7B,aAAa,EAAE,2BAA2B;IAM5C,oBAAoB,CAClB,EAAE,EAAE,CAAC,MAAM,EAAE,mCAAmC,CAAC,QAAQ,CAAC,KAAK,IAAI;IASrE,OAAO;;;;;;;;;;;;MA2BJ;IAEH,KAAK;IAIC,YAAY,CAAC,EACjB,KAAK,EACL,SAAS,GACV,EAAE;QACD,KAAK,EAAE,YAAY,CAAC;QACpB,SAAS,EAAE,kBAAkB,GAAG,SAAS,CAAC;KAC3C;;;;;CAWF"}
@@ -0,0 +1,56 @@
1
+ import { App, } from "@modelcontextprotocol/ext-apps";
2
+ import { print } from "@apollo/client/utilities";
3
+ import { cacheAsync } from "../utilities/index.js";
4
+ /** @internal */
5
+ export class McpAppManager {
6
+ app;
7
+ #connectToHost;
8
+ #hostContextCallbacks = new Set();
9
+ constructor(manifest, connectToHost) {
10
+ this.app = new App({ name: manifest.name, version: manifest.appVersion });
11
+ this.#connectToHost = connectToHost;
12
+ }
13
+ onHostContextChanged(cb) {
14
+ this.#hostContextCallbacks.add(cb);
15
+ return () => {
16
+ this.#hostContextCallbacks.delete(cb);
17
+ };
18
+ }
19
+ connect = cacheAsync(async () => {
20
+ this.app.onhostcontextchanged = (params) => {
21
+ this.#hostContextCallbacks.forEach((cb) => cb(params));
22
+ };
23
+ const { structuredContent, _meta, toolInput } = await this.#connectToHost(this.app);
24
+ return {
25
+ structuredContent: {
26
+ ...structuredContent,
27
+ ..._meta?.structuredContent,
28
+ },
29
+ toolInput,
30
+ // Some hosts do not provide toolInfo in the ui/initialize response, so we
31
+ // fallback to `_meta.toolName` provided by Apollo MCP server if the value
32
+ // is not available.
33
+ toolName: this.app.getHostContext()?.toolInfo?.tool.name ??
34
+ _meta?.toolName ??
35
+ // Some hosts do not forward `_meta` nor do they provide `toolInfo`. Our
36
+ // MCP server provides `toolName` in `structuredContent` as a workaround
37
+ // that we can use if all else fails
38
+ structuredContent.toolName,
39
+ _meta,
40
+ };
41
+ });
42
+ close() {
43
+ return this.app.close();
44
+ }
45
+ async executeQuery({ query, variables, }) {
46
+ const result = (await this.app.callServerTool({
47
+ name: "execute",
48
+ arguments: { query: print(query), variables },
49
+ }));
50
+ return {
51
+ ...result.structuredContent,
52
+ ...result._meta?.structuredContent,
53
+ };
54
+ }
55
+ }
56
+ //# sourceMappingURL=McpAppManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"McpAppManager.js","sourceRoot":"","sources":["../../src/core/McpAppManager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,GAEJ,MAAM,gCAAgC,CAAC;AAKxC,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAkBnD,gBAAgB;AAChB,MAAM,OAAO,aAAa;IACf,GAAG,CAAM;IAElB,cAAc,CAA8B;IAE5C,qBAAqB,GAAG,IAAI,GAAG,EAE5B,CAAC;IAEJ,YACE,QAA6B,EAC7B,aAA0C;QAE1C,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;QAC1E,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;IACtC,CAAC;IAED,oBAAoB,CAClB,EAAmE;QAEnE,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAEnC,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACxC,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,GAAG,UAAU,CAAC,KAAK,IAAI,EAAE;QAC9B,IAAI,CAAC,GAAG,CAAC,oBAAoB,GAAG,CAAC,MAAM,EAAE,EAAE;YACzC,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;QACzD,CAAC,CAAC;QAEF,MAAM,EAAE,iBAAiB,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,MAAM,IAAI,CAAC,cAAc,CACvE,IAAI,CAAC,GAAG,CACT,CAAC;QAEF,OAAO;YACL,iBAAiB,EAAE;gBACjB,GAAG,iBAAiB;gBACpB,GAAG,KAAK,EAAE,iBAAiB;aAC5B;YACD,SAAS;YACT,0EAA0E;YAC1E,0EAA0E;YAC1E,oBAAoB;YACpB,QAAQ,EACN,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI;gBAC9C,KAAK,EAAE,QAAQ;gBACf,wEAAwE;gBACxE,wEAAwE;gBACxE,oCAAoC;gBACpC,iBAAiB,CAAC,QAAQ;YAC5B,KAAK;SACN,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,KAAK;QACH,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,EACjB,KAAK,EACL,SAAS,GAIV;QACC,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC;YAC5C,IAAI,EAAE,SAAS;YACf,SAAS,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE;SAC9C,CAAC,CAA+B,CAAC;QAElC,OAAO;YACL,GAAG,MAAM,CAAC,iBAAiB;YAC3B,GAAG,MAAM,CAAC,KAAK,EAAE,iBAAiB;SACnC,CAAC;IACJ,CAAC;CACF","sourcesContent":["import {\n App,\n type McpUiHostContextChangedNotification,\n} from \"@modelcontextprotocol/ext-apps\";\nimport type { CallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { ApplicationManifest } from \"../types/application-manifest.js\";\nimport type { FormattedExecutionResult } from \"graphql\";\nimport type { DocumentNode, OperationVariables } from \"@apollo/client\";\nimport { print } from \"@apollo/client/utilities\";\nimport { cacheAsync } from \"../utilities/index.js\";\nimport type { ApolloMcpServerApps } from \"./types.js\";\n\ntype ExecuteQueryCallToolResult = Omit<CallToolResult, \"structuredContent\"> & {\n structuredContent: FormattedExecutionResult;\n _meta?: { structuredContent?: FormattedExecutionResult };\n};\n\ninterface ConnectToHostResult {\n structuredContent: ApolloMcpServerApps.StructuredContent;\n toolInput: Record<string, unknown> | undefined;\n _meta: ApolloMcpServerApps.Meta | undefined;\n}\n\nexport type ConnectToHostImplementation = (\n app: App\n) => Promise<ConnectToHostResult>;\n\n/** @internal */\nexport class McpAppManager {\n readonly app: App;\n\n #connectToHost: ConnectToHostImplementation;\n\n #hostContextCallbacks = new Set<\n (params: McpUiHostContextChangedNotification[\"params\"]) => void\n >();\n\n constructor(\n manifest: ApplicationManifest,\n connectToHost: ConnectToHostImplementation\n ) {\n this.app = new App({ name: manifest.name, version: manifest.appVersion });\n this.#connectToHost = connectToHost;\n }\n\n onHostContextChanged(\n cb: (params: McpUiHostContextChangedNotification[\"params\"]) => void\n ) {\n this.#hostContextCallbacks.add(cb);\n\n return () => {\n this.#hostContextCallbacks.delete(cb);\n };\n }\n\n connect = cacheAsync(async () => {\n this.app.onhostcontextchanged = (params) => {\n this.#hostContextCallbacks.forEach((cb) => cb(params));\n };\n\n const { structuredContent, _meta, toolInput } = await this.#connectToHost(\n this.app\n );\n\n return {\n structuredContent: {\n ...structuredContent,\n ..._meta?.structuredContent,\n },\n toolInput,\n // Some hosts do not provide toolInfo in the ui/initialize response, so we\n // fallback to `_meta.toolName` provided by Apollo MCP server if the value\n // is not available.\n toolName:\n this.app.getHostContext()?.toolInfo?.tool.name ??\n _meta?.toolName ??\n // Some hosts do not forward `_meta` nor do they provide `toolInfo`. Our\n // MCP server provides `toolName` in `structuredContent` as a workaround\n // that we can use if all else fails\n structuredContent.toolName,\n _meta,\n };\n });\n\n close() {\n return this.app.close();\n }\n\n async executeQuery({\n query,\n variables,\n }: {\n query: DocumentNode;\n variables: OperationVariables | undefined;\n }) {\n const result = (await this.app.callServerTool({\n name: \"execute\",\n arguments: { query: print(query), variables },\n })) as ExecuteQueryCallToolResult;\n\n return {\n ...result.structuredContent,\n ...result._meta?.structuredContent,\n };\n }\n}\n"]}
@@ -1,22 +1,8 @@
1
1
  export interface Register {
2
2
  }
3
- /**
4
- * @deprecated Please use the `ToolInfo` type instead. `ToolName` will be
5
- * removed in the next major version.
6
- */
7
- export type ToolName = Register extends {
8
- toolName: infer T extends string;
9
- } ? T : string;
10
3
  type RegisteredToolInputs = Register extends {
11
4
  toolInputs: infer T extends Record<string, unknown>;
12
5
  } ? T : never;
13
- /**
14
- * @deprecated Please use the `ToolInfo` type instead. `ToolInput` will be
15
- * removed in the next major version.
16
- */
17
- export type ToolInput = [
18
- RegisteredToolInputs
19
- ] extends [never] ? Record<string, unknown> : RegisteredToolInputs[keyof RegisteredToolInputs];
20
6
  type ToolInfoFromInputs<T extends Record<string, unknown>> = {
21
7
  [K in keyof T]: {
22
8
  toolName: K;
@@ -1 +1 @@
1
- {"version":3,"file":"typeRegistration.d.ts","sourceRoot":"","sources":["../../src/core/typeRegistration.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;CAAG;AAE5B;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAClB,QAAQ,SAAS;IAAE,QAAQ,EAAE,MAAM,CAAC,SAAS,MAAM,CAAA;CAAE,GAAG,CAAC,GAAG,MAAM,CAAC;AAErE,KAAK,oBAAoB,GACvB,QAAQ,SAAS;IAAE,UAAU,EAAE,MAAM,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GAAG,CAAC,GAC1E,KAAK,CAAC;AAEV;;;GAGG;AACH,MAAM,MAAM,SAAS,GACnB;IAAC,oBAAoB;CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9D,oBAAoB,CAAC,MAAM,oBAAoB,CAAC,CAAC;AAErD,KAAK,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;KAC1D,CAAC,IAAI,MAAM,CAAC,GAAG;QACd,QAAQ,EAAE,CAAC,CAAC;QACZ,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;KACzE;CACF,CAAC,MAAM,CAAC,CAAC,CAAC;AAEX,MAAM,MAAM,QAAQ,GAClB;IAAC,oBAAoB;CAAC,SAAS,CAAC,KAAK,CAAC,GACpC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;CAAE,GACpE,kBAAkB,CAAC,oBAAoB,CAAC,CAAC"}
1
+ {"version":3,"file":"typeRegistration.d.ts","sourceRoot":"","sources":["../../src/core/typeRegistration.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;CAAG;AAE5B,KAAK,oBAAoB,GACvB,QAAQ,SAAS;IAAE,UAAU,EAAE,MAAM,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GAAG,CAAC,GAC1E,KAAK,CAAC;AAEV,KAAK,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;KAC1D,CAAC,IAAI,MAAM,CAAC,GAAG;QACd,QAAQ,EAAE,CAAC,CAAC;QACZ,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;KACzE;CACF,CAAC,MAAM,CAAC,CAAC,CAAC;AAEX,MAAM,MAAM,QAAQ,GAClB;IAAC,oBAAoB;CAAC,SAAS,CAAC,KAAK,CAAC,GACpC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;CAAE,GACpE,kBAAkB,CAAC,oBAAoB,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"typeRegistration.js","sourceRoot":"","sources":["../../src/core/typeRegistration.ts"],"names":[],"mappings":"","sourcesContent":["export interface Register {}\n\n/**\n * @deprecated Please use the `ToolInfo` type instead. `ToolName` will be\n * removed in the next major version.\n */\nexport type ToolName =\n Register extends { toolName: infer T extends string } ? T : string;\n\ntype RegisteredToolInputs =\n Register extends { toolInputs: infer T extends Record<string, unknown> } ? T\n : never;\n\n/**\n * @deprecated Please use the `ToolInfo` type instead. `ToolInput` will be\n * removed in the next major version.\n */\nexport type ToolInput =\n [RegisteredToolInputs] extends [never] ? Record<string, unknown>\n : RegisteredToolInputs[keyof RegisteredToolInputs];\n\ntype ToolInfoFromInputs<T extends Record<string, unknown>> = {\n [K in keyof T]: {\n toolName: K;\n toolInput: T[K] extends Record<string, never> ? T[K] | undefined : T[K];\n };\n}[keyof T];\n\nexport type ToolInfo =\n [RegisteredToolInputs] extends [never] ?\n { toolName: string; toolInput: Record<string, unknown> | undefined }\n : ToolInfoFromInputs<RegisteredToolInputs>;\n"]}
1
+ {"version":3,"file":"typeRegistration.js","sourceRoot":"","sources":["../../src/core/typeRegistration.ts"],"names":[],"mappings":"","sourcesContent":["export interface Register {}\n\ntype RegisteredToolInputs =\n Register extends { toolInputs: infer T extends Record<string, unknown> } ? T\n : never;\n\ntype ToolInfoFromInputs<T extends Record<string, unknown>> = {\n [K in keyof T]: {\n toolName: K;\n toolInput: T[K] extends Record<string, never> ? T[K] | undefined : T[K];\n };\n}[keyof T];\n\nexport type ToolInfo =\n [RegisteredToolInputs] extends [never] ?\n { toolName: string; toolInput: Record<string, unknown> | undefined }\n : ToolInfoFromInputs<RegisteredToolInputs>;\n"]}
@@ -3,10 +3,11 @@ import type { FormattedExecutionResult } from "graphql";
3
3
  export declare namespace ApolloMcpServerApps {
4
4
  interface Meta {
5
5
  toolName: string;
6
+ structuredContent?: ApolloMcpServerApps.StructuredContent;
6
7
  [x: string]: unknown;
7
8
  }
8
9
  interface StructuredContent {
9
- result: FormattedExecutionResult;
10
+ result?: FormattedExecutionResult;
10
11
  prefetch?: Record<string, FormattedExecutionResult>;
11
12
  toolName?: string;
12
13
  [x: string]: unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,IAAI,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAC9F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAExD,yBAAiB,mBAAmB,CAAC;IACnC,UAAiB,IAAI;QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACtB;IAED,UAAiB,iBAAiB;QAChC,MAAM,EAAE,wBAAwB,CAAC;QACjC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;QACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACtB;IAED,UAAiB,cAAe,SAAQ,iBAAiB;QACvD,KAAK,CAAC,EAAE,mBAAmB,CAAC,IAAI,CAAC;QACjC,iBAAiB,EAAE,mBAAmB,CAAC,iBAAiB,CAAC;KAC1D;CACF"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,IAAI,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAC9F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAExD,yBAAiB,mBAAmB,CAAC;IACnC,UAAiB,IAAI;QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,iBAAiB,CAAC,EAAE,mBAAmB,CAAC,iBAAiB,CAAC;QAC1D,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACtB;IAED,UAAiB,iBAAiB;QAChC,MAAM,CAAC,EAAE,wBAAwB,CAAC;QAClC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;QACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACtB;IAED,UAAiB,cAAe,SAAQ,iBAAiB;QACvD,KAAK,CAAC,EAAE,mBAAmB,CAAC,IAAI,CAAC;QACjC,iBAAiB,EAAE,mBAAmB,CAAC,iBAAiB,CAAC;KAC1D;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { CallToolResult as McpCallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { FormattedExecutionResult } from \"graphql\";\n\nexport namespace ApolloMcpServerApps {\n export interface Meta {\n toolName: string;\n [x: string]: unknown;\n }\n\n export interface StructuredContent {\n result: FormattedExecutionResult;\n prefetch?: Record<string, FormattedExecutionResult>;\n toolName?: string;\n [x: string]: unknown;\n }\n\n export interface CallToolResult extends McpCallToolResult {\n _meta?: ApolloMcpServerApps.Meta;\n structuredContent: ApolloMcpServerApps.StructuredContent;\n }\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { CallToolResult as McpCallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { FormattedExecutionResult } from \"graphql\";\n\nexport namespace ApolloMcpServerApps {\n export interface Meta {\n toolName: string;\n structuredContent?: ApolloMcpServerApps.StructuredContent;\n [x: string]: unknown;\n }\n\n export interface StructuredContent {\n result?: FormattedExecutionResult;\n prefetch?: Record<string, FormattedExecutionResult>;\n toolName?: string;\n [x: string]: unknown;\n }\n\n export interface CallToolResult extends McpCallToolResult {\n _meta?: ApolloMcpServerApps.Meta;\n structuredContent: ApolloMcpServerApps.StructuredContent;\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export type { ApplicationManifest, ManifestOperation, ManifestTool, ManifestExtraInput, ManifestCsp, ManifestLabels, ManifestWidgetSettings, } from "./types/application-manifest.js";
2
- export type { Register, ToolInfo, ToolInput, ToolName, } from "./core/typeRegistration.js";
2
+ export type { Register, ToolInfo } from "./core/typeRegistration.js";
3
3
  export { ApolloClient } from "./core/ApolloClient.js";
4
4
  export { ToolCallLink } from "./link/ToolCallLink.js";
5
5
  export { Platform } from "./core/Platform.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,sBAAsB,GACvB,MAAM,iCAAiC,CAAC;AAEzC,YAAY,EACV,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,QAAQ,GACT,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,sBAAsB,GACvB,MAAM,iCAAiC,CAAC;AAEzC,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAErE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export type {\n ApplicationManifest,\n ManifestOperation,\n ManifestTool,\n ManifestExtraInput,\n ManifestCsp,\n ManifestLabels,\n ManifestWidgetSettings,\n} from \"./types/application-manifest.js\";\n\nexport type {\n Register,\n ToolInfo,\n ToolInput,\n ToolName,\n} from \"./core/typeRegistration.js\";\n\nexport { ApolloClient } from \"./core/ApolloClient.js\";\nexport { ToolCallLink } from \"./link/ToolCallLink.js\";\n\nexport { Platform } from \"./core/Platform.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export type {\n ApplicationManifest,\n ManifestOperation,\n ManifestTool,\n ManifestExtraInput,\n ManifestCsp,\n ManifestLabels,\n ManifestWidgetSettings,\n} from \"./types/application-manifest.js\";\n\nexport type { Register, ToolInfo } from \"./core/typeRegistration.js\";\n\nexport { ApolloClient } from \"./core/ApolloClient.js\";\nexport { ToolCallLink } from \"./link/ToolCallLink.js\";\n\nexport { Platform } from \"./core/Platform.js\";\n"]}
@@ -1,5 +1,4 @@
1
1
  export * from "./index.js";
2
2
  export { Platform } from "./mcp/core/Platform.js";
3
3
  export { ApolloClient } from "./mcp/core/ApolloClient.js";
4
- export { ToolCallLink } from "./mcp/link/ToolCallLink.js";
5
4
  //# sourceMappingURL=index.mcp.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mcp.d.ts","sourceRoot":"","sources":["../src/index.mcp.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.mcp.d.ts","sourceRoot":"","sources":["../src/index.mcp.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC"}
package/dist/index.mcp.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from "./index.js";
2
2
  export { Platform } from "./mcp/core/Platform.js";
3
3
  export { ApolloClient } from "./mcp/core/ApolloClient.js";
4
- export { ToolCallLink } from "./mcp/link/ToolCallLink.js";
5
4
  //# sourceMappingURL=index.mcp.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mcp.js","sourceRoot":"","sources":["../src/index.mcp.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC","sourcesContent":["export * from \"./index.js\";\n\nexport { Platform } from \"./mcp/core/Platform.js\";\nexport { ApolloClient } from \"./mcp/core/ApolloClient.js\";\nexport { ToolCallLink } from \"./mcp/link/ToolCallLink.js\";\n"]}
1
+ {"version":3,"file":"index.mcp.js","sourceRoot":"","sources":["../src/index.mcp.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC","sourcesContent":["export * from \"./index.js\";\n\nexport { Platform } from \"./mcp/core/Platform.js\";\nexport { ApolloClient } from \"./mcp/core/ApolloClient.js\";\n"]}
@@ -1,5 +1,4 @@
1
1
  export * from "./index.js";
2
2
  export { Platform } from "./openai/core/Platform.js";
3
3
  export { ApolloClient } from "./openai/core/ApolloClient.js";
4
- export { ToolCallLink } from "./openai/link/ToolCallLink.js";
5
4
  //# sourceMappingURL=index.openai.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.openai.d.ts","sourceRoot":"","sources":["../src/index.openai.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.openai.d.ts","sourceRoot":"","sources":["../src/index.openai.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC"}
@@ -1,5 +1,4 @@
1
1
  export * from "./index.js";
2
2
  export { Platform } from "./openai/core/Platform.js";
3
3
  export { ApolloClient } from "./openai/core/ApolloClient.js";
4
- export { ToolCallLink } from "./openai/link/ToolCallLink.js";
5
4
  //# sourceMappingURL=index.openai.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.openai.js","sourceRoot":"","sources":["../src/index.openai.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC","sourcesContent":["export * from \"./index.js\";\n\nexport { Platform } from \"./openai/core/Platform.js\";\nexport { ApolloClient } from \"./openai/core/ApolloClient.js\";\nexport { ToolCallLink } from \"./openai/link/ToolCallLink.js\";\n"]}
1
+ {"version":3,"file":"index.openai.js","sourceRoot":"","sources":["../src/index.openai.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC","sourcesContent":["export * from \"./index.js\";\n\nexport { Platform } from \"./openai/core/Platform.js\";\nexport { ApolloClient } from \"./openai/core/ApolloClient.js\";\n"]}
@@ -22,6 +22,11 @@ import { ApolloLink } from "@apollo/client";
22
22
  * ```
23
23
  */
24
24
  export declare class ToolCallLink extends ApolloLink {
25
- constructor();
25
+ readonly name = "ToolCallLink";
26
+ request(operation: ApolloLink.Operation): import("rxjs").Observable<{
27
+ errors?: ReadonlyArray<import("graphql").GraphQLFormattedError>;
28
+ data?: import("graphql/jsutils/ObjMap").ObjMap<unknown> | null;
29
+ extensions?: import("graphql/jsutils/ObjMap").ObjMap<unknown>;
30
+ }>;
26
31
  }
27
32
  //# sourceMappingURL=ToolCallLink.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ToolCallLink.d.ts","sourceRoot":"","sources":["../../src/link/ToolCallLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,YAAa,SAAQ,UAAU;;CAQ3C"}
1
+ {"version":3,"file":"ToolCallLink.d.ts","sourceRoot":"","sources":["../../src/link/ToolCallLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAO1D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,YAAa,SAAQ,UAAU;IAC1C,QAAQ,CAAC,IAAI,kBAAkB;IAC/B,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,SAAS;;;;;CAUxC"}
@@ -1,4 +1,7 @@
1
- import { ApolloLink } from "@apollo/client";
1
+ import { ApolloClient, ApolloLink } from "@apollo/client";
2
+ import { __DEV__ } from "@apollo/client/utilities/environment";
3
+ import { from } from "rxjs";
4
+ import { aiClientSymbol, invariant } from "../utilities/index.js";
2
5
  /**
3
6
  * A terminating link that sends a GraphQL request through an agent tool call.
4
7
  * When providing a custom link chain to `ApolloClient`, `ApolloClient` will
@@ -22,9 +25,19 @@ import { ApolloLink } from "@apollo/client";
22
25
  * ```
23
26
  */
24
27
  export class ToolCallLink extends ApolloLink {
25
- constructor() {
26
- super();
27
- throw new Error("Cannot construct a `ToolCallLink` from `@apollo/client-ai-apps` without export conditions. Please set export conditions or import from the `/openai` or `/mcp` subpath directly.");
28
+ name = "ToolCallLink";
29
+ request(operation) {
30
+ const client = getPrivateAccess(operation.client);
31
+ return from(client.appManager.executeQuery({
32
+ query: operation.query,
33
+ variables: operation.variables,
34
+ }));
28
35
  }
29
36
  }
37
+ function getPrivateAccess(client) {
38
+ if (__DEV__) {
39
+ invariant(client[aiClientSymbol], 'The "client" instance used with `ToolCallLink` is the wrong instance. You might have imported `ApolloClient` from `@apollo/client`. Please import `ApolloClient` from `@apollo/client-ai-apps` instead.');
40
+ }
41
+ return client;
42
+ }
30
43
  //# sourceMappingURL=ToolCallLink.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ToolCallLink.js","sourceRoot":"","sources":["../../src/link/ToolCallLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,YAAa,SAAQ,UAAU;IAC1C;QACE,KAAK,EAAE,CAAC;QAER,MAAM,IAAI,KAAK,CACb,mLAAmL,CACpL,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { ApolloLink } from \"@apollo/client\";\n\n/**\n * A terminating link that sends a GraphQL request through an agent tool call.\n * When providing a custom link chain to `ApolloClient`, `ApolloClient` will\n * validate that the terminating link is an instance of this link.\n *\n * @example Providing a custom link chain\n *\n * ```ts\n * import { ApolloLink } from \"@apollo/client\";\n * import { ApolloClient, ToolCallLink } from \"@apollo/client-ai-apps\";\n *\n * const link = ApolloLink.from([\n * ...otherLinks,\n * new ToolCallLink()\n * ]);\n *\n * const client = new ApolloClient({\n * link,\n * // ...\n * });\n * ```\n */\nexport class ToolCallLink extends ApolloLink {\n constructor() {\n super();\n\n throw new Error(\n \"Cannot construct a `ToolCallLink` from `@apollo/client-ai-apps` without export conditions. Please set export conditions or import from the `/openai` or `/mcp` subpath directly.\"\n );\n }\n}\n"]}
1
+ {"version":3,"file":"ToolCallLink.js","sourceRoot":"","sources":["../../src/link/ToolCallLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAG5B,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,YAAa,SAAQ,UAAU;IACjC,IAAI,GAAG,cAAc,CAAC;IAC/B,OAAO,CAAC,SAA+B;QACrC,MAAM,MAAM,GAAG,gBAAgB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAElD,OAAO,IAAI,CACT,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC;YAC7B,KAAK,EAAE,SAAS,CAAC,KAAK;YACtB,SAAS,EAAE,SAAS,CAAC,SAAS;SAC/B,CAAC,CACH,CAAC;IACJ,CAAC;CACF;AAED,SAAS,gBAAgB,CACvB,MAAoB;IAEpB,IAAI,OAAO,EAAE,CAAC;QACZ,SAAS,CACN,MAAc,CAAC,cAAc,CAAC,EAC/B,yMAAyM,CAC1M,CAAC;IACJ,CAAC;IAED,OAAO,MAAa,CAAC;AACvB,CAAC","sourcesContent":["import { ApolloClient, ApolloLink } from \"@apollo/client\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport { from } from \"rxjs\";\n\nimport type { McpAppManager } from \"../core/McpAppManager\";\nimport { aiClientSymbol, invariant } from \"../utilities/index.js\";\n\n/**\n * A terminating link that sends a GraphQL request through an agent tool call.\n * When providing a custom link chain to `ApolloClient`, `ApolloClient` will\n * validate that the terminating link is an instance of this link.\n *\n * @example Providing a custom link chain\n *\n * ```ts\n * import { ApolloLink } from \"@apollo/client\";\n * import { ApolloClient, ToolCallLink } from \"@apollo/client-ai-apps\";\n *\n * const link = ApolloLink.from([\n * ...otherLinks,\n * new ToolCallLink()\n * ]);\n *\n * const client = new ApolloClient({\n * link,\n * // ...\n * });\n * ```\n */\nexport class ToolCallLink extends ApolloLink {\n readonly name = \"ToolCallLink\";\n request(operation: ApolloLink.Operation) {\n const client = getPrivateAccess(operation.client);\n\n return from(\n client.appManager.executeQuery({\n query: operation.query,\n variables: operation.variables,\n })\n );\n }\n}\n\nfunction getPrivateAccess(\n client: ApolloClient\n): ApolloClient & { appManager: McpAppManager } {\n if (__DEV__) {\n invariant(\n (client as any)[aiClientSymbol],\n 'The \"client\" instance used with `ToolCallLink` is the wrong instance. You might have imported `ApolloClient` from `@apollo/client`. Please import `ApolloClient` from `@apollo/client-ai-apps` instead.'\n );\n }\n\n return client as any;\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import { ApolloLink, Observable } from "@apollo/client";
2
+ import type { OperationVariables } from "@apollo/client";
3
+ import type { FormattedExecutionResult } from "graphql";
4
+ import type { ManifestOperation } from "../types/application-manifest.js";
5
+ /**
6
+ * @internal
7
+ * Holds requests until the client is fully hydrated after a tool call. It is
8
+ * particularly useful for `network-only` and `cache-and-network` fetch policies
9
+ * where the request makes it to the link chain because it prevents a followup
10
+ * tool call to the MCP server for the just fetched data from the MCP server.
11
+ */
12
+ export declare class ToolHydrationLink extends ApolloLink {
13
+ #private;
14
+ hydrate(operation: ManifestOperation, { result, variables, }: {
15
+ result: FormattedExecutionResult;
16
+ variables: OperationVariables;
17
+ }): void;
18
+ complete(): void;
19
+ request(operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction): Observable<ApolloLink.Result>;
20
+ }
21
+ //# sourceMappingURL=ToolHydrationLink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToolHydrationLink.d.ts","sourceRoot":"","sources":["../../src/link/ToolHydrationLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAExD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAK1E;;;;;;GAMG;AACH,qBAAa,iBAAkB,SAAQ,UAAU;;IAK/C,OAAO,CACL,SAAS,EAAE,iBAAiB,EAC5B,EACE,MAAM,EACN,SAAS,GACV,EAAE;QAAE,MAAM,EAAE,wBAAwB,CAAC;QAAC,SAAS,EAAE,kBAAkB,CAAA;KAAE;IAQxE,QAAQ,IAAI,IAAI;IAQhB,OAAO,CACL,SAAS,EAAE,UAAU,CAAC,SAAS,EAC/B,OAAO,EAAE,UAAU,CAAC,eAAe,GAClC,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC;CAiCjC"}
@@ -0,0 +1,57 @@
1
+ import { ApolloLink, Observable } from "@apollo/client";
2
+ import { canonicalStringify } from "@apollo/client/utilities";
3
+ import { of } from "rxjs";
4
+ /**
5
+ * @internal
6
+ * Holds requests until the client is fully hydrated after a tool call. It is
7
+ * particularly useful for `network-only` and `cache-and-network` fetch policies
8
+ * where the request makes it to the link chain because it prevents a followup
9
+ * tool call to the MCP server for the just fetched data from the MCP server.
10
+ */
11
+ export class ToolHydrationLink extends ApolloLink {
12
+ #hydrated = false;
13
+ #pending = [];
14
+ #operations = new Map();
15
+ hydrate(operation, { result, variables, }) {
16
+ this.#operations.set(getKey({ operationName: operation.name, variables }), result);
17
+ }
18
+ complete() {
19
+ this.#hydrated = true;
20
+ for (const resolve of this.#pending.splice(0)) {
21
+ resolve();
22
+ }
23
+ }
24
+ request(operation, forward) {
25
+ const maybeSendToTerminatingLink = () => {
26
+ const key = getKey(operation);
27
+ const result = this.#operations.get(key);
28
+ if (result) {
29
+ this.#operations.delete(key);
30
+ return of(result);
31
+ }
32
+ return forward(operation);
33
+ };
34
+ if (this.#hydrated) {
35
+ return maybeSendToTerminatingLink();
36
+ }
37
+ return new Observable((observer) => {
38
+ let active = true;
39
+ const resolve = () => {
40
+ if (!active)
41
+ return;
42
+ maybeSendToTerminatingLink().subscribe(observer);
43
+ };
44
+ this.#pending.push(resolve);
45
+ return () => {
46
+ active = false;
47
+ const idx = this.#pending.indexOf(resolve);
48
+ if (idx !== -1)
49
+ this.#pending.splice(idx, 1);
50
+ };
51
+ });
52
+ }
53
+ }
54
+ function getKey({ operationName, variables, }) {
55
+ return `${operationName}:${canonicalStringify(variables ?? {})}`;
56
+ }
57
+ //# sourceMappingURL=ToolHydrationLink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToolHydrationLink.js","sourceRoot":"","sources":["../../src/link/ToolHydrationLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAM1B;;;;;;GAMG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAU;IAC/C,SAAS,GAAG,KAAK,CAAC;IAClB,QAAQ,GAAgB,EAAE,CAAC;IAC3B,WAAW,GAAG,IAAI,GAAG,EAA0C,CAAC;IAEhE,OAAO,CACL,SAA4B,EAC5B,EACE,MAAM,EACN,SAAS,GAC2D;QAEtE,IAAI,CAAC,WAAW,CAAC,GAAG,CAClB,MAAM,CAAC,EAAE,aAAa,EAAE,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,EACpD,MAAM,CACP,CAAC;IACJ,CAAC;IAED,QAAQ;QACN,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QAEtB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9C,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAED,OAAO,CACL,SAA+B,EAC/B,OAAmC;QAEnC,MAAM,0BAA0B,GAAG,GAAkC,EAAE;YACrE,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;YAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAEzC,IAAI,MAAM,EAAE,CAAC;gBACX,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC7B,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC;YACpB,CAAC;YAED,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC,CAAC;QAEF,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,OAAO,0BAA0B,EAAE,CAAC;QACtC,CAAC;QAED,OAAO,IAAI,UAAU,CAAC,CAAC,QAAQ,EAAE,EAAE;YACjC,IAAI,MAAM,GAAG,IAAI,CAAC;YAElB,MAAM,OAAO,GAAG,GAAG,EAAE;gBACnB,IAAI,CAAC,MAAM;oBAAE,OAAO;gBACpB,0BAA0B,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YACnD,CAAC,CAAC;YACF,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAE5B,OAAO,GAAG,EAAE;gBACV,MAAM,GAAG,KAAK,CAAC;gBACf,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBAC3C,IAAI,GAAG,KAAK,CAAC,CAAC;oBAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAC/C,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,SAAS,MAAM,CAAC,EACd,aAAa,EACb,SAAS,GAIV;IACC,OAAO,GAAG,aAAa,IAAI,kBAAkB,CAAC,SAAS,IAAI,EAAE,CAAC,EAAkB,CAAC;AACnF,CAAC","sourcesContent":["import { ApolloLink, Observable } from \"@apollo/client\";\nimport type { OperationVariables } from \"@apollo/client\";\nimport { canonicalStringify } from \"@apollo/client/utilities\";\nimport type { FormattedExecutionResult } from \"graphql\";\nimport { of } from \"rxjs\";\nimport type { ManifestOperation } from \"../types/application-manifest.js\";\n\ntype ResolveFn = () => void;\ntype OperationKey = string & { __type: \"PendingKey\" };\n\n/**\n * @internal\n * Holds requests until the client is fully hydrated after a tool call. It is\n * particularly useful for `network-only` and `cache-and-network` fetch policies\n * where the request makes it to the link chain because it prevents a followup\n * tool call to the MCP server for the just fetched data from the MCP server.\n */\nexport class ToolHydrationLink extends ApolloLink {\n #hydrated = false;\n #pending: ResolveFn[] = [];\n #operations = new Map<OperationKey, FormattedExecutionResult>();\n\n hydrate(\n operation: ManifestOperation,\n {\n result,\n variables,\n }: { result: FormattedExecutionResult; variables: OperationVariables }\n ) {\n this.#operations.set(\n getKey({ operationName: operation.name, variables }),\n result\n );\n }\n\n complete(): void {\n this.#hydrated = true;\n\n for (const resolve of this.#pending.splice(0)) {\n resolve();\n }\n }\n\n request(\n operation: ApolloLink.Operation,\n forward: ApolloLink.ForwardFunction\n ): Observable<ApolloLink.Result> {\n const maybeSendToTerminatingLink = (): Observable<ApolloLink.Result> => {\n const key = getKey(operation);\n const result = this.#operations.get(key);\n\n if (result) {\n this.#operations.delete(key);\n return of(result);\n }\n\n return forward(operation);\n };\n\n if (this.#hydrated) {\n return maybeSendToTerminatingLink();\n }\n\n return new Observable((observer) => {\n let active = true;\n\n const resolve = () => {\n if (!active) return;\n maybeSendToTerminatingLink().subscribe(observer);\n };\n this.#pending.push(resolve);\n\n return () => {\n active = false;\n const idx = this.#pending.indexOf(resolve);\n if (idx !== -1) this.#pending.splice(idx, 1);\n };\n });\n }\n}\n\nfunction getKey({\n operationName,\n variables,\n}: {\n operationName: string | undefined;\n variables?: OperationVariables;\n}): OperationKey {\n return `${operationName}:${canonicalStringify(variables ?? {})}` as OperationKey;\n}\n"]}
@@ -1,26 +1,9 @@
1
- import { ApolloClient as BaseApolloClient } from "@apollo/client";
2
- import type { WatchQueryOptions, ObservableQuery, OperationVariables } from "@apollo/client";
3
- import type { ApplicationManifest } from "../../types/application-manifest.js";
4
- import { aiClientSymbol } from "../../utilities/index.js";
1
+ import { AbstractApolloClient } from "../../core/AbstractApolloClient.js";
5
2
  export declare namespace ApolloClient {
6
- interface Options extends Omit<BaseApolloClient.Options, "link"> {
7
- link?: BaseApolloClient.Options["link"];
8
- manifest: ApplicationManifest;
3
+ interface Options extends AbstractApolloClient.Options {
9
4
  }
10
5
  }
11
- export declare class ApolloClient extends BaseApolloClient {
12
- #private;
13
- manifest: ApplicationManifest;
14
- private readonly appManager;
15
- /** @internal */
16
- readonly [aiClientSymbol] = true;
6
+ export declare class ApolloClient extends AbstractApolloClient {
17
7
  constructor(options: ApolloClient.Options);
18
- stop(): void;
19
- get toolInput(): Record<string, unknown> | undefined;
20
- clearToolInput(): void;
21
- watchQuery<T = any, TVariables extends OperationVariables = OperationVariables>(options: WatchQueryOptions<TVariables, T>): ObservableQuery<T, TVariables>;
22
- connect: (() => Promise<void>) & {
23
- reset: () => void;
24
- };
25
8
  }
26
9
  //# sourceMappingURL=ApolloClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ApolloClient.d.ts","sourceRoot":"","sources":["../../../src/mcp/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,IAAI,gBAAgB,EAEjC,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EACnB,MAAM,gBAAgB,CAAC;AAKxB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE/E,OAAO,EACL,cAAc,EAMf,MAAM,0BAA0B,CAAC;AAGlC,MAAM,CAAC,OAAO,WAAW,YAAY,CAAC;IACpC,UAAiB,OAAQ,SAAQ,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC;QACrE,IAAI,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACxC,QAAQ,EAAE,mBAAmB,CAAC;KAC/B;CACF;AAED,qBAAa,YAAa,SAAQ,gBAAgB;;IAChD,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAE3C,gBAAgB;IAChB,QAAQ,CAAC,CAAC,cAAc,CAAC,QAAQ;gBAIrB,OAAO,EAAE,YAAY,CAAC,OAAO;IA6BzC,IAAI;IAKJ,IAAI,SAAS,wCAEZ;IAED,cAAc;IAId,UAAU,CACR,CAAC,GAAG,GAAG,EACP,UAAU,SAAS,kBAAkB,GAAG,kBAAkB,EAC1D,OAAO,EAAE,iBAAiB,CAAC,UAAU,EAAE,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,EAAE,UAAU,CAAC;IAyC5E,OAAO;;MAsBJ;CACJ"}
1
+ {"version":3,"file":"ApolloClient.d.ts","sourceRoot":"","sources":["../../../src/mcp/core/ApolloClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAI1E,MAAM,CAAC,OAAO,WAAW,YAAY,CAAC;IACpC,UAAiB,OAAQ,SAAQ,oBAAoB,CAAC,OAAO;KAAG;CACjE;AAED,qBAAa,YAAa,SAAQ,oBAAoB;gBACxC,OAAO,EAAE,YAAY,CAAC,OAAO;CA6B1C"}
@@ -1,103 +1,25 @@
1
- import { ApolloLink, ApolloClient as BaseApolloClient, DocumentTransform, } from "@apollo/client";
2
- import { removeDirectivesFromDocument } from "@apollo/client/utilities/internal";
3
- import { parse, visit } from "graphql";
4
- import { equal } from "@wry/equality";
5
- import { __DEV__ } from "@apollo/client/utilities/environment";
6
- import { ToolCallLink } from "../link/ToolCallLink.js";
7
- import { aiClientSymbol, cacheAsync, getToolNamesFromDocument, getVariableNamesFromDocument, getVariablesForOperationFromToolInput, warnOnVariableMismatch, } from "../../utilities/index.js";
8
- import { McpAppManager } from "./McpAppManager.js";
9
- export class ApolloClient extends BaseApolloClient {
10
- manifest;
11
- appManager;
12
- /** @internal */
13
- [aiClientSymbol] = true;
14
- #toolInput;
1
+ import { AbstractApolloClient } from "../../core/AbstractApolloClient.js";
2
+ import { connectToHost, promiseWithResolvers } from "../../utilities/index.js";
3
+ export class ApolloClient extends AbstractApolloClient {
15
4
  constructor(options) {
16
- const link = options.link ?? new ToolCallLink();
17
- if (__DEV__) {
18
- validateTerminatingLink(link);
19
- }
20
- super({
21
- ...options,
22
- link,
23
- // Strip out the prefetch/tool directives so they don't get sent with the operation to the server
24
- documentTransform: new DocumentTransform((document) => {
25
- const serverDocument = removeDirectivesFromDocument([{ name: "prefetch" }, { name: "tool" }], document);
26
- return visit(serverDocument, {
27
- OperationDefinition(node) {
28
- return { ...node, description: undefined };
29
- },
30
- });
31
- }).concat(options.documentTransform ?? DocumentTransform.identity()),
5
+ super(options, async (app) => {
6
+ const toolResult = promiseWithResolvers();
7
+ const toolInput = promiseWithResolvers();
8
+ app.ontoolresult = (params) => {
9
+ toolResult.resolve(params);
10
+ };
11
+ app.ontoolinput = (params) => {
12
+ toolInput.resolve(params);
13
+ };
14
+ await connectToHost(app);
15
+ const { structuredContent, _meta } = await toolResult.promise;
16
+ const { arguments: args } = await toolInput.promise;
17
+ return {
18
+ structuredContent,
19
+ toolInput: args,
20
+ _meta,
21
+ };
32
22
  });
33
- this.manifest = options.manifest;
34
- this.appManager = new McpAppManager(this.manifest);
35
23
  }
36
- stop() {
37
- super.stop();
38
- this.appManager.close().catch(() => { });
39
- }
40
- get toolInput() {
41
- return this.#toolInput;
42
- }
43
- clearToolInput() {
44
- this.#toolInput = undefined;
45
- }
46
- watchQuery(options) {
47
- if (__DEV__) {
48
- const toolInput = this.#toolInput;
49
- if (toolInput) {
50
- const toolName = this.appManager.toolName;
51
- const hasMatchingTool = !!toolName && getToolNamesFromDocument(options.query).has(toolName);
52
- if (hasMatchingTool) {
53
- // Clear after first matching comparison so this only fires once and
54
- // remounting doesn't produce spurious warnings.
55
- this.#toolInput = undefined;
56
- const variableNames = getVariableNamesFromDocument(options.query);
57
- if (variableNames.size > 0) {
58
- const { variables } = options;
59
- const toolInputVariables = Object.entries(toolInput).filter(([key]) => variableNames.has(key));
60
- const hasToolInputMismatch = toolInputVariables.some(([key, value]) => !equal(value, variables?.[key]));
61
- if (hasToolInputMismatch) {
62
- warnOnVariableMismatch(options.query, Object.fromEntries(toolInputVariables), variables);
63
- }
64
- }
65
- }
66
- }
67
- }
68
- return super.watchQuery(options);
69
- }
70
- connect = cacheAsync(async () => {
71
- const { prefetch, result, toolName, args } = await this.appManager.connect();
72
- this.#toolInput = args;
73
- this.manifest.operations.forEach((operation) => {
74
- if (operation.prefetchID && prefetch?.[operation.prefetchID]) {
75
- this.writeQuery({
76
- query: parse(operation.body),
77
- data: prefetch[operation.prefetchID].data,
78
- });
79
- }
80
- if (operation.tools.find((tool) => tool.name === toolName)) {
81
- this.writeQuery({
82
- query: parse(operation.body),
83
- data: result.data,
84
- variables: getVariablesForOperationFromToolInput(operation, args),
85
- });
86
- }
87
- });
88
- });
89
- }
90
- function validateTerminatingLink(link) {
91
- let terminatingLink = link;
92
- while (terminatingLink.right) {
93
- terminatingLink = terminatingLink.right;
94
- }
95
- if (!isNamedLink(terminatingLink) ||
96
- terminatingLink.name !== "ToolCallLink") {
97
- throw new Error("The terminating link must be a `ToolCallLink`. If you are using a `split` link, ensure the `right` branch uses a `ToolCallLink` as the terminating link.");
98
- }
99
- }
100
- function isNamedLink(link) {
101
- return "name" in link;
102
24
  }
103
25
  //# sourceMappingURL=ApolloClient.js.map