@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.
- package/CHANGELOG.md +100 -0
- package/CONTRIBUTING.md +195 -0
- package/README.md +74 -0
- package/dist/core/AbstractApolloClient.d.ts +33 -0
- package/dist/core/AbstractApolloClient.d.ts.map +1 -0
- package/dist/core/AbstractApolloClient.js +129 -0
- package/dist/core/AbstractApolloClient.js.map +1 -0
- package/dist/core/ApolloClient.d.ts +3 -7
- package/dist/core/ApolloClient.d.ts.map +1 -1
- package/dist/core/ApolloClient.js +5 -4
- package/dist/core/ApolloClient.js.map +1 -1
- package/dist/core/McpAppManager.d.ts +42 -0
- package/dist/core/McpAppManager.d.ts.map +1 -0
- package/dist/core/McpAppManager.js +56 -0
- package/dist/core/McpAppManager.js.map +1 -0
- package/dist/core/typeRegistration.d.ts +0 -14
- package/dist/core/typeRegistration.d.ts.map +1 -1
- package/dist/core/typeRegistration.js.map +1 -1
- package/dist/core/types.d.ts +2 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mcp.d.ts +0 -1
- package/dist/index.mcp.d.ts.map +1 -1
- package/dist/index.mcp.js +0 -1
- package/dist/index.mcp.js.map +1 -1
- package/dist/index.openai.d.ts +0 -1
- package/dist/index.openai.d.ts.map +1 -1
- package/dist/index.openai.js +0 -1
- package/dist/index.openai.js.map +1 -1
- package/dist/link/ToolCallLink.d.ts +6 -1
- package/dist/link/ToolCallLink.d.ts.map +1 -1
- package/dist/link/ToolCallLink.js +17 -4
- package/dist/link/ToolCallLink.js.map +1 -1
- package/dist/link/ToolHydrationLink.d.ts +21 -0
- package/dist/link/ToolHydrationLink.d.ts.map +1 -0
- package/dist/link/ToolHydrationLink.js +57 -0
- package/dist/link/ToolHydrationLink.js.map +1 -0
- package/dist/mcp/core/ApolloClient.d.ts +3 -20
- package/dist/mcp/core/ApolloClient.d.ts.map +1 -1
- package/dist/mcp/core/ApolloClient.js +20 -98
- package/dist/mcp/core/ApolloClient.js.map +1 -1
- package/dist/mcp/index.d.ts +0 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +0 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/openai/core/ApolloClient.d.ts +3 -20
- package/dist/openai/core/ApolloClient.d.ts.map +1 -1
- package/dist/openai/core/ApolloClient.js +36 -98
- package/dist/openai/core/ApolloClient.js.map +1 -1
- package/dist/openai/index.d.ts +0 -1
- package/dist/openai/index.d.ts.map +1 -1
- package/dist/openai/index.js +0 -1
- package/dist/openai/index.js.map +1 -1
- package/dist/openai/react/index.d.ts +0 -7
- package/dist/openai/react/index.d.ts.map +1 -1
- package/dist/openai/react/index.js +0 -7
- package/dist/openai/react/index.js.map +1 -1
- package/dist/react/ApolloProvider.d.ts.map +1 -1
- package/dist/react/ApolloProvider.js +1 -1
- package/dist/react/ApolloProvider.js.map +1 -1
- package/dist/{mcp/react/hooks → react}/createHydrationUtils.d.ts +1 -1
- package/dist/react/createHydrationUtils.d.ts.map +1 -0
- package/dist/{mcp/react/hooks → react}/createHydrationUtils.js +7 -9
- package/dist/react/createHydrationUtils.js.map +1 -0
- package/dist/react/hooks/internal/useApolloClient.d.ts +3 -0
- package/dist/react/hooks/internal/useApolloClient.d.ts.map +1 -0
- package/dist/{mcp/react/hooks → react/hooks/internal}/useApolloClient.js +3 -3
- package/dist/react/hooks/internal/useApolloClient.js.map +1 -0
- package/dist/react/hooks/useApp.d.ts.map +1 -0
- package/dist/react/hooks/useApp.js +5 -0
- package/dist/react/hooks/useApp.js.map +1 -0
- package/dist/react/hooks/useHostContext.d.ts.map +1 -0
- package/dist/{openai/react → react}/hooks/useHostContext.js +1 -1
- package/dist/react/hooks/useHostContext.js.map +1 -0
- package/dist/react/hooks/useToolInfo.d.ts +3 -0
- package/dist/react/hooks/useToolInfo.d.ts.map +1 -0
- package/dist/react/hooks/useToolInfo.js +5 -0
- package/dist/react/hooks/useToolInfo.js.map +1 -0
- package/dist/react/hooks/useToolMetadata.d.ts +2 -0
- package/dist/react/hooks/useToolMetadata.d.ts.map +1 -0
- package/dist/react/hooks/useToolMetadata.js +5 -0
- package/dist/react/hooks/useToolMetadata.js.map +1 -0
- package/dist/react/index.d.ts +5 -16
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +5 -19
- package/dist/react/index.js.map +1 -1
- package/dist/types/application-manifest.d.ts +1 -0
- package/dist/types/application-manifest.d.ts.map +1 -1
- package/dist/types/application-manifest.js.map +1 -1
- package/dist/utilities/connectToHost.d.ts +3 -0
- package/dist/utilities/connectToHost.d.ts.map +1 -0
- package/dist/utilities/connectToHost.js +11 -0
- package/dist/utilities/connectToHost.js.map +1 -0
- package/dist/utilities/index.d.ts +1 -0
- package/dist/utilities/index.d.ts.map +1 -1
- package/dist/utilities/index.js +1 -0
- package/dist/utilities/index.js.map +1 -1
- package/dist/vite/apolloClientAiApps.d.ts.map +1 -1
- package/dist/vite/apolloClientAiApps.js +2 -0
- package/dist/vite/apolloClientAiApps.js.map +1 -1
- package/package.json +5 -22
- package/src/core/AbstractApolloClient.ts +217 -0
- package/src/core/ApolloClient.ts +8 -10
- package/src/core/McpAppManager.ts +106 -0
- package/src/core/typeRegistration.ts +0 -15
- package/src/core/types.ts +2 -1
- package/src/index.mcp.ts +0 -1
- package/src/index.openai.ts +0 -1
- package/src/index.ts +1 -6
- package/src/link/ToolCallLink.ts +27 -5
- package/src/link/ToolHydrationLink.ts +90 -0
- package/src/link/__tests__/ToolCallLink.test.ts +99 -0
- package/src/mcp/core/ApolloClient.ts +32 -165
- package/src/mcp/core/__tests__/ApolloClient.test.ts +571 -71
- package/src/mcp/index.ts +0 -1
- package/src/openai/core/ApolloClient.ts +48 -161
- package/src/openai/core/__tests__/ApolloClient.test.ts +916 -118
- package/src/openai/index.ts +0 -1
- package/src/openai/react/index.ts +0 -7
- package/src/react/ApolloProvider.tsx +1 -6
- package/src/react/__tests__/ApolloProvider/mcp.test.tsx +66 -29
- package/src/react/__tests__/ApolloProvider/openai.test.tsx +16 -41
- package/src/react/__tests__/createHydrationUtils.test.tsx +1260 -0
- package/src/{mcp/react/hooks → react}/createHydrationUtils.ts +7 -10
- package/src/react/hooks/__tests__/useApp.test.tsx +46 -0
- package/src/react/hooks/__tests__/useHostContext.test.tsx +99 -0
- package/src/react/hooks/__tests__/useToolInfo.test.tsx +98 -0
- package/src/react/hooks/__tests__/useToolMetadata.test.tsx +58 -0
- package/src/{mcp/react/hooks → react/hooks/internal}/useApolloClient.ts +3 -3
- package/src/{mcp/react → react}/hooks/useApp.ts +1 -1
- package/src/{openai/react → react}/hooks/useHostContext.ts +1 -1
- package/src/react/hooks/useToolInfo.ts +6 -0
- package/src/react/hooks/useToolMetadata.ts +5 -0
- package/src/react/index.ts +5 -36
- package/src/testing/internal/graphql/parseManifestOperation.ts +87 -0
- package/src/testing/internal/index.ts +3 -0
- package/src/testing/internal/matchers/index.ts +1 -0
- package/src/testing/internal/matchers/toEmitAnything.ts +43 -0
- package/src/testing/internal/matchers/types.ts +1 -0
- package/src/testing/internal/mcp/mockMcpHost.ts +25 -4
- package/src/testing/internal/tests/eachHostEnv.ts +22 -0
- package/src/testing/internal/utilities/createHostEnv.ts +117 -0
- package/src/types/application-manifest.ts +1 -0
- package/src/utilities/connectToHost.ts +13 -0
- package/src/utilities/index.ts +1 -0
- package/src/vite/__tests__/apolloClientAiApps.test.ts +56 -0
- package/src/vite/apolloClientAiApps.ts +5 -0
- package/tsconfig.vite.json +1 -1
- package/vitest.config.ts +13 -0
- package/dist/mcp/core/McpAppManager.d.ts +0 -30
- package/dist/mcp/core/McpAppManager.d.ts.map +0 -1
- package/dist/mcp/core/McpAppManager.js +0 -82
- package/dist/mcp/core/McpAppManager.js.map +0 -1
- package/dist/mcp/link/ToolCallLink.d.ts +0 -28
- package/dist/mcp/link/ToolCallLink.d.ts.map +0 -1
- package/dist/mcp/link/ToolCallLink.js +0 -35
- package/dist/mcp/link/ToolCallLink.js.map +0 -1
- package/dist/mcp/react/hooks/createHydrationUtils.d.ts.map +0 -1
- package/dist/mcp/react/hooks/createHydrationUtils.js.map +0 -1
- package/dist/mcp/react/hooks/useApolloClient.d.ts +0 -3
- package/dist/mcp/react/hooks/useApolloClient.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useApolloClient.js.map +0 -1
- package/dist/mcp/react/hooks/useApp.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useApp.js +0 -5
- package/dist/mcp/react/hooks/useApp.js.map +0 -1
- package/dist/mcp/react/hooks/useHostContext.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useHostContext.js +0 -7
- package/dist/mcp/react/hooks/useHostContext.js.map +0 -1
- package/dist/mcp/react/hooks/useToolInfo.d.ts +0 -3
- package/dist/mcp/react/hooks/useToolInfo.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useToolInfo.js +0 -10
- package/dist/mcp/react/hooks/useToolInfo.js.map +0 -1
- package/dist/mcp/react/hooks/useToolInput.d.ts +0 -7
- package/dist/mcp/react/hooks/useToolInput.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useToolInput.js +0 -9
- package/dist/mcp/react/hooks/useToolInput.js.map +0 -1
- package/dist/mcp/react/hooks/useToolMetadata.d.ts +0 -2
- package/dist/mcp/react/hooks/useToolMetadata.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useToolMetadata.js +0 -5
- package/dist/mcp/react/hooks/useToolMetadata.js.map +0 -1
- package/dist/mcp/react/hooks/useToolName.d.ts +0 -7
- package/dist/mcp/react/hooks/useToolName.d.ts.map +0 -1
- package/dist/mcp/react/hooks/useToolName.js +0 -9
- package/dist/mcp/react/hooks/useToolName.js.map +0 -1
- package/dist/mcp/react/index.d.ts +0 -8
- package/dist/mcp/react/index.d.ts.map +0 -1
- package/dist/mcp/react/index.js +0 -8
- package/dist/mcp/react/index.js.map +0 -1
- package/dist/openai/core/McpAppManager.d.ts +0 -29
- package/dist/openai/core/McpAppManager.d.ts.map +0 -1
- package/dist/openai/core/McpAppManager.js +0 -91
- package/dist/openai/core/McpAppManager.js.map +0 -1
- package/dist/openai/link/ToolCallLink.d.ts +0 -28
- package/dist/openai/link/ToolCallLink.d.ts.map +0 -1
- package/dist/openai/link/ToolCallLink.js +0 -35
- package/dist/openai/link/ToolCallLink.js.map +0 -1
- package/dist/openai/react/hooks/createHydrationUtils.d.ts +0 -15
- package/dist/openai/react/hooks/createHydrationUtils.d.ts.map +0 -1
- package/dist/openai/react/hooks/createHydrationUtils.js +0 -113
- package/dist/openai/react/hooks/createHydrationUtils.js.map +0 -1
- package/dist/openai/react/hooks/useApp.d.ts +0 -2
- package/dist/openai/react/hooks/useApp.d.ts.map +0 -1
- package/dist/openai/react/hooks/useApp.js +0 -5
- package/dist/openai/react/hooks/useApp.js.map +0 -1
- package/dist/openai/react/hooks/useHostContext.d.ts +0 -2
- package/dist/openai/react/hooks/useHostContext.d.ts.map +0 -1
- package/dist/openai/react/hooks/useHostContext.js.map +0 -1
- package/dist/openai/react/hooks/useToolInfo.d.ts +0 -3
- package/dist/openai/react/hooks/useToolInfo.d.ts.map +0 -1
- package/dist/openai/react/hooks/useToolInfo.js +0 -10
- package/dist/openai/react/hooks/useToolInfo.js.map +0 -1
- package/dist/openai/react/hooks/useToolInput.d.ts +0 -7
- package/dist/openai/react/hooks/useToolInput.d.ts.map +0 -1
- package/dist/openai/react/hooks/useToolInput.js +0 -9
- package/dist/openai/react/hooks/useToolInput.js.map +0 -1
- package/dist/openai/react/hooks/useToolMetadata.d.ts +0 -2
- package/dist/openai/react/hooks/useToolMetadata.d.ts.map +0 -1
- package/dist/openai/react/hooks/useToolMetadata.js +0 -5
- package/dist/openai/react/hooks/useToolMetadata.js.map +0 -1
- package/dist/openai/react/hooks/useToolName.d.ts +0 -7
- package/dist/openai/react/hooks/useToolName.d.ts.map +0 -1
- package/dist/openai/react/hooks/useToolName.js +0 -9
- package/dist/openai/react/hooks/useToolName.js.map +0 -1
- package/dist/react/index.mcp.d.ts +0 -3
- package/dist/react/index.mcp.d.ts.map +0 -1
- package/dist/react/index.mcp.js +0 -3
- package/dist/react/index.mcp.js.map +0 -1
- package/dist/react/index.openai.d.ts +0 -3
- package/dist/react/index.openai.d.ts.map +0 -1
- package/dist/react/index.openai.js +0 -3
- package/dist/react/index.openai.js.map +0 -1
- package/dist/react/missingHook.d.ts +0 -2
- package/dist/react/missingHook.d.ts.map +0 -1
- package/dist/react/missingHook.js +0 -6
- package/dist/react/missingHook.js.map +0 -1
- package/src/mcp/core/McpAppManager.ts +0 -129
- package/src/mcp/link/ToolCallLink.ts +0 -40
- package/src/mcp/link/__tests__/ToolCallLink.test.ts +0 -62
- package/src/mcp/react/hooks/__tests__/createHydrationUtils.test.tsx +0 -1228
- package/src/mcp/react/hooks/__tests__/useApp.test.tsx +0 -46
- package/src/mcp/react/hooks/__tests__/useHostContext.test.tsx +0 -95
- package/src/mcp/react/hooks/__tests__/useToolInfo.test.tsx +0 -53
- package/src/mcp/react/hooks/__tests__/useToolInput.test.tsx +0 -50
- package/src/mcp/react/hooks/__tests__/useToolMetadata.test.tsx +0 -53
- package/src/mcp/react/hooks/__tests__/useToolName.test.tsx +0 -50
- package/src/mcp/react/hooks/useHostContext.ts +0 -14
- package/src/mcp/react/hooks/useToolInfo.ts +0 -13
- package/src/mcp/react/hooks/useToolInput.ts +0 -10
- package/src/mcp/react/hooks/useToolMetadata.ts +0 -5
- package/src/mcp/react/hooks/useToolName.ts +0 -10
- package/src/mcp/react/index.ts +0 -7
- package/src/openai/core/McpAppManager.ts +0 -139
- package/src/openai/link/ToolCallLink.ts +0 -40
- package/src/openai/react/hooks/__tests__/createHydrationUtils.test.tsx +0 -1333
- package/src/openai/react/hooks/__tests__/useToolInfo.test.tsx +0 -92
- package/src/openai/react/hooks/__tests__/useToolInput.test.tsx +0 -85
- package/src/openai/react/hooks/__tests__/useToolMetadata.test.tsx +0 -86
- package/src/openai/react/hooks/__tests__/useToolName.test.tsx +0 -50
- package/src/openai/react/hooks/createHydrationUtils.ts +0 -182
- package/src/openai/react/hooks/useApp.ts +0 -5
- package/src/openai/react/hooks/useToolInfo.ts +0 -13
- package/src/openai/react/hooks/useToolInput.ts +0 -10
- package/src/openai/react/hooks/useToolMetadata.ts +0 -5
- package/src/openai/react/hooks/useToolName.ts +0 -10
- package/src/react/index.mcp.ts +0 -10
- package/src/react/index.openai.ts +0 -10
- package/src/react/missingHook.ts +0 -9
- /package/dist/{mcp/react → react}/hooks/useApp.d.ts +0 -0
- /package/dist/{mcp/react → react}/hooks/useHostContext.d.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,103 @@
|
|
|
1
|
+
## 0.7.0 (2026-03-31)
|
|
2
|
+
|
|
3
|
+
### Breaking Changes
|
|
4
|
+
|
|
5
|
+
#### Remove deprecated hooks
|
|
6
|
+
|
|
7
|
+
The deprecated `useToolInput` and `useToolName` hooks have been removed along with their corresponding `ToolInput` and `ToolName` types. Use `useToolInfo` instead:
|
|
8
|
+
|
|
9
|
+
```diff
|
|
10
|
+
- import { useToolInput, useToolName } from "@apollo/client-ai-apps/react";
|
|
11
|
+
+ import { useToolInfo } from "@apollo/client-ai-apps/react";
|
|
12
|
+
|
|
13
|
+
function MyComponent() {
|
|
14
|
+
- const toolName = useToolName();
|
|
15
|
+
- const toolInput = useToolInput();
|
|
16
|
+
+ const { toolName, toolInput } = useToolInfo();
|
|
17
|
+
|
|
18
|
+
// ...
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
#### Simplified React entry points
|
|
23
|
+
|
|
24
|
+
The React entry points have now been simplified to encourage the use of the shared `/react` entry point. This means all React symbols shared between the `@apollo/client-ai-apps/mcp/react` and `@apollo/client-ai-apps/openai/react` entry points are only available in `@apollo/client-ai-apps/react`.
|
|
25
|
+
|
|
26
|
+
As part of this consolidation, the `@apollo/client-ai-apps/mcp/react` entry point was removed because there were no unique symbols exported from this entry point. The `@apollo/client-ai-apps/openai/react` entry point now exports only the `useWidgetState` hook. All other symbols should be imported from `@apollo/client-ai-apps/react`.
|
|
27
|
+
|
|
28
|
+
If you are already importing React symbols from `@apollo/client-ai-apps/react`, you do not need to do anything.
|
|
29
|
+
|
|
30
|
+
If you are importing React symbols from platform-specific entry points, you will need to update your imports to use the top-level `/react` entry point.
|
|
31
|
+
|
|
32
|
+
```diff
|
|
33
|
+
- import {
|
|
34
|
+
- useApp,
|
|
35
|
+
- useHostContext,
|
|
36
|
+
- useToolInfo,
|
|
37
|
+
- createHydrationUtils
|
|
38
|
+
- } from "@apollo/client-ai-apps/mcp/react";
|
|
39
|
+
- import {
|
|
40
|
+
- useApp,
|
|
41
|
+
- useHostContext,
|
|
42
|
+
- useToolInfo,
|
|
43
|
+
- createHydrationUtils
|
|
44
|
+
- } from "@apollo/client-ai-apps/openai/react";
|
|
45
|
+
+ import {
|
|
46
|
+
+ useApp,
|
|
47
|
+
+ useHostContext,
|
|
48
|
+
+ useToolInfo,
|
|
49
|
+
+ createHydrationUtils
|
|
50
|
+
+ } from "@apollo/client-ai-apps/react";
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Fixes
|
|
54
|
+
|
|
55
|
+
#### Honor no-cache queries when hydrating query
|
|
56
|
+
|
|
57
|
+
The `no-cache` fetch policy is now properly honored when hydrating a `no-cache` query initiated by a tool call. Previously, all tool calls wrote the query to the cache regardless of the configured fetch policy.
|
|
58
|
+
|
|
59
|
+
#### Hydrate `network-only`, `cache-and-network`, and `no-cache` queries from tool result data
|
|
60
|
+
|
|
61
|
+
Queries using `network-only`, `cache-and-network`, or `no-cache` fetch policies previously called the `execute` tool to fetch data, even when the result was already available from the tool call that initiated the app. These queries are now served directly from the tool result on first load, avoiding a redundant `execute` call. Subsequent queries will continue to call `execute` using the configured fetch policy as expected.
|
|
62
|
+
|
|
63
|
+
## 0.6.5 (2026-03-23)
|
|
64
|
+
|
|
65
|
+
### Features
|
|
66
|
+
|
|
67
|
+
#### Add support for `extraOutputs` to the `@tool` directive
|
|
68
|
+
|
|
69
|
+
The `@tool` directive now supports an `extraOutputs` argument. This is a free-form object (any shape) that is written to the manifest under each tool's config. Values provided to `extraOutputs` are returned by Apollo MCP Server for the tool result in `structuredContent` to make it accessible to the LLM.
|
|
70
|
+
|
|
71
|
+
```graphql
|
|
72
|
+
query MyQuery
|
|
73
|
+
@tool(
|
|
74
|
+
name: "my-tool",
|
|
75
|
+
description: "My tool",
|
|
76
|
+
extraOutputs: { "follow-up-instructions": "Perform a feat of magic" }
|
|
77
|
+
) {
|
|
78
|
+
myField
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
#### Support `@private` in operations to hide parts of a query result from LLMs
|
|
83
|
+
|
|
84
|
+
In MCP Apps, you may have data that you want made available to your app but hidden from the LLM. A new `@private` directive is now supported that hides these fields from LLMs:
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
query ProductsQuery {
|
|
88
|
+
topProducts {
|
|
89
|
+
sku
|
|
90
|
+
title
|
|
91
|
+
meta @private {
|
|
92
|
+
createdAt
|
|
93
|
+
barcode
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`@private` directs Apollo MCP Server to remove those fields in `structuredContent` so that the field data is not available to the LLM. The full result is instead added to `_meta`. `@apollo/client-ai-apps` handles reading the query result from the proper location when `@private` is used.
|
|
100
|
+
|
|
1
101
|
## 0.6.4 (2026-03-13)
|
|
2
102
|
|
|
3
103
|
### Fixes
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# Apollo Contributor Guide
|
|
2
|
+
|
|
3
|
+
Excited about Apollo and want to make it better? We're excited too!
|
|
4
|
+
|
|
5
|
+
Apollo is a community of developers just like you, striving to create the best tools and libraries around GraphQL. We welcome anyone who wants to contribute or provide constructive feedback, no matter the age or level of experience. If you want to help but don't know where to start, let us know, and we'll find something for you.
|
|
6
|
+
|
|
7
|
+
Oh, and if you haven't already, join our [community forums](https://community.apollographql.com).
|
|
8
|
+
|
|
9
|
+
Here are some ways to contribute to the project, from easiest to most difficult:
|
|
10
|
+
|
|
11
|
+
- [Apollo Client](#apollo-client)
|
|
12
|
+
- [Issues](#issues)
|
|
13
|
+
- [Reporting bugs](#reporting-bugs)
|
|
14
|
+
- [Improving the documentation](#improving-the-documentation)
|
|
15
|
+
- [Responding to issues](#responding-to-issues)
|
|
16
|
+
- [Changesets](#changesets)
|
|
17
|
+
- [Small bug fixes](#small-bug-fixes)
|
|
18
|
+
- [Suggesting features](#suggesting-features)
|
|
19
|
+
- [Big PRs](#big-prs)
|
|
20
|
+
- [Code review guidelines](#code-review-guidelines)
|
|
21
|
+
- [Development](#development)
|
|
22
|
+
- [Building](#building)
|
|
23
|
+
- [Testing](#testing)
|
|
24
|
+
- [Testing with the AI Apps Template](#testing-with-the-ai-apps-template)
|
|
25
|
+
|
|
26
|
+
## Apollo Client
|
|
27
|
+
|
|
28
|
+
This package is an integration layer built on top of [Apollo Client](https://github.com/apollographql/apollo-client). If you encounter an issue that appears to be in the core Apollo Client library rather than the MCP Apps integration, please open an issue or contribute directly in the [apollographql/apollo-client](https://github.com/apollographql/apollo-client) repository. See Apollo Client's own [CONTRIBUTING.md](https://github.com/apollographql/apollo-client/blob/main/CONTRIBUTING.md) for guidance on contributing there.
|
|
29
|
+
|
|
30
|
+
If you're unsure whether an issue belongs here or in the core library, feel free to open an issue here and we'll help triage it.
|
|
31
|
+
|
|
32
|
+
## Issues
|
|
33
|
+
|
|
34
|
+
### Reporting bugs
|
|
35
|
+
|
|
36
|
+
If you encounter a bug, please file an issue on GitHub via the repository of the sub-project you think contains the bug. If an issue you have is already reported, please add additional information or add a 👍 reaction to indicate your agreement.
|
|
37
|
+
|
|
38
|
+
While we will try to be as helpful as we can on any issue reported, please include the following to maximize the chances of a quick fix:
|
|
39
|
+
|
|
40
|
+
1. **Intended outcome:** What you were trying to accomplish when the bug occurred, and as much code as possible related to the source of the problem.
|
|
41
|
+
2. **Actual outcome:** A description of what actually happened, including a screenshot or copy-paste of any related error messages, logs, or other output that might be related. Places to look for information include your browser console, server console, and network logs. Please avoid non-specific phrases like "didn't work" or "broke".
|
|
42
|
+
3. **How to reproduce the issue:** Instructions for how the issue can be reproduced by a maintainer or contributor. Be as specific as possible, and only mention what is necessary to reproduce the bug. If possible, isolate the exact circumstances in which the bug occurs. Avoid speculation over what the cause might be.
|
|
43
|
+
|
|
44
|
+
Creating a good reproduction really helps contributors investigate and resolve your issue quickly. In many cases, the act of creating a minimal reproduction illuminates that the source of the bug was somewhere outside the library in question, saving time and effort for everyone.
|
|
45
|
+
|
|
46
|
+
### Improving the documentation
|
|
47
|
+
|
|
48
|
+
Improving the documentation, examples, and other open source content can be the easiest way to contribute to the library. If you see a piece of content that can be better, open a PR with an improvement, no matter how small! If you would like to suggest a big change or major rewrite, we'd love to hear your ideas! Please open a feature request for discussion before writing the PR.
|
|
49
|
+
|
|
50
|
+
### Responding to issues
|
|
51
|
+
|
|
52
|
+
In addition to reporting issues, a great way to contribute to Apollo is to respond to other peoples' issues and try to identify the problem or help them work around it. If you're interested in taking a more active role in this process, please go ahead and respond to issues. And don't forget to say "Hi" in our [community forums](https://community.apollographql.com)!
|
|
53
|
+
|
|
54
|
+
### Changesets
|
|
55
|
+
|
|
56
|
+
This package uses [knope](https://knope.tech/) to automate its versioning and release process. When contributing, your PR should contain a "changeset" that can be generated by running `npm run changeset` from your branch locally.
|
|
57
|
+
|
|
58
|
+
The changeset CLI will ask you to enter the corresponding [semver bump type](https://semver.org/) and a short summary of your changes: feel free to enter a brief description via the command line and continue editing the generated Markdown file found inside of `.changeset` in your editor of choice. When editing your changeset's Markdown file, you can leverage any of the features of GitHub flavored markdown! The description you provide in your changeset will be used to generate an entry in `CHANGELOG.md` and the release notes in a future release, so the more complete and descriptive the better. Include code samples where necessary.
|
|
59
|
+
|
|
60
|
+
### Small bug fixes
|
|
61
|
+
|
|
62
|
+
For a small bug fix change (less than 20 lines of code changed), feel free to open a pull request. We'll try to merge it as fast as possible and ideally publish a new release on the same day. The only requirement is, make sure you also add a test that verifies the bug you are trying to fix.
|
|
63
|
+
|
|
64
|
+
### Suggesting features
|
|
65
|
+
|
|
66
|
+
Most of the features in this package came from suggestions by you, the community! We welcome any ideas about how to make the MCP Apps integration better for your use case. Please open an issue with your details.
|
|
67
|
+
|
|
68
|
+
## Big PRs
|
|
69
|
+
|
|
70
|
+
This includes:
|
|
71
|
+
|
|
72
|
+
- Big bug fixes
|
|
73
|
+
- New features
|
|
74
|
+
|
|
75
|
+
For significant changes to a repository, it's important to settle on a design before starting on the implementation. This way, we can make sure that major improvements get the care and attention they deserve. Since big changes can be risky and might not always get merged, it's good to reduce the amount of possible wasted effort by agreeing on an implementation design/plan first.
|
|
76
|
+
|
|
77
|
+
1. **Open an issue.** Open an issue about your bug or feature request.
|
|
78
|
+
2. **Reach consensus.** Some contributors and community members should reach an agreement that this feature or bug is important, and that someone should work on implementing or fixing it.
|
|
79
|
+
3. **Agree on intended behavior.** On the issue, reach an agreement about the desired behavior. In the case of a bug fix, it should be clear what it means for the bug to be fixed, and in the case of a feature, it should be clear what it will be like for developers to use the new feature.
|
|
80
|
+
4. **Agree on implementation plan.** Write a plan for how this feature or bug fix should be implemented. What modules need to be added or rewritten? Should this be one pull request or multiple incremental improvements? Who is going to do each part?
|
|
81
|
+
5. **Submit PR.** In the case where multiple dependent patches need to be made to implement the change, only submit one at a time. Otherwise, the others might get stale while the first is reviewed and merged. Make sure to avoid "while we're here" type changes - if something isn't relevant to the improvement at hand, it should be in a separate PR; this especially includes code style changes of unrelated code.
|
|
82
|
+
6. **Review.** At least one core contributor should sign off on the change before it's merged. Look at the "code review" section below to learn about factors are important in the code review. If you want to expedite the code being merged, try to review your own code first!
|
|
83
|
+
7. **Merge and release!**
|
|
84
|
+
|
|
85
|
+
### Code review guidelines
|
|
86
|
+
|
|
87
|
+
It's important that every piece of code in Apollo packages is reviewed by at least one core contributor familiar with that codebase. Here are some things we look for:
|
|
88
|
+
|
|
89
|
+
1. **Required CI checks pass.** This is a prerequisite for the review, and it is the PR author's responsibility. As long as the tests don't pass, the PR won't get reviewed.
|
|
90
|
+
2. **Simplicity.** Is this the simplest way to achieve the intended goal? If there are too many files, redundant functions, or complex lines of code, suggest a simpler way to do the same thing. In particular, avoid implementing an overly general solution when a simple, small, and pragmatic fix will do.
|
|
91
|
+
3. **Testing.** Do the tests ensure this code won't break when other stuff changes around it? When it does break, will the tests added help us identify which part of the library has the problem? Did we cover an appropriate set of edge cases? Look at the test coverage report if there is one. Are all significant code paths in the new code exercised at least once?
|
|
92
|
+
4. **No unnecessary or unrelated changes.** PRs shouldn't come with random formatting changes, especially in unrelated parts of the code. If there is some refactoring that needs to be done, it should be in a separate PR from a bug fix or feature, if possible.
|
|
93
|
+
5. **Code has appropriate comments.** Code should be commented, or written in a clear "self-documenting" way.
|
|
94
|
+
6. **Idiomatic use of the language.** In TypeScript, make sure the typings are specific and correct. In ES2015, make sure to use imports rather than require and const instead of var, etc. Ideally a linter enforces a lot of this, but use your common sense and follow the style of the surrounding code.
|
|
95
|
+
|
|
96
|
+
## Development
|
|
97
|
+
|
|
98
|
+
### Building
|
|
99
|
+
|
|
100
|
+
**Build the package once:**
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
npm run build
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Testing
|
|
107
|
+
|
|
108
|
+
**Run all tests once:**
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
npm run test
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Run all tests in watch mode:**
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
npm run test:watch
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Testing with the AI Apps Template
|
|
121
|
+
|
|
122
|
+
It can be useful to test your local changes against a real MCP app. The [Apollo AI Apps Template](https://github.com/apollographql/ai-apps-template) provides a complete setup for this purpose.
|
|
123
|
+
|
|
124
|
+
#### Step 1: Build and pack this package
|
|
125
|
+
|
|
126
|
+
From the root of this repository, build the package and create a local `.tgz` tarball:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
npm run build && npm pack
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
This creates a file like `apollo-client-ai-apps-0.6.5.tgz` in the root of the repo. Note the path to this file — you'll need it in the next step.
|
|
133
|
+
|
|
134
|
+
#### Step 2: Set up the template
|
|
135
|
+
|
|
136
|
+
Scaffold a new project from the template:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
npx tiged apollographql/ai-apps-template mcp-apps-reproduction
|
|
140
|
+
cd mcp-apps-reproduction
|
|
141
|
+
./install.sh
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
#### Step 3: Point the template at your local build
|
|
145
|
+
|
|
146
|
+
In the template's React app (`dev/the-store/package.json`), replace the published `@apollo/client-ai-apps` version with the path to your local `.tgz`:
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"dependencies": {
|
|
151
|
+
"@apollo/client-ai-apps": "file:/path/to/apollo-client-ai-apps-0.6.5.tgz"
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Then reinstall dependencies in that directory:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
cd dev/the-store
|
|
160
|
+
npm install
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
#### Step 4: Start the services
|
|
164
|
+
|
|
165
|
+
You'll need three terminal windows:
|
|
166
|
+
|
|
167
|
+
**Terminal 1 — GraphQL API:**
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
cd ecommerce-graph
|
|
171
|
+
npm run dev
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**Terminal 2 — React app:**
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
cd dev/the-store
|
|
178
|
+
npm run dev:mcp
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
**Terminal 3 — MCP server:**
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
./start_mcp.sh
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
#### Step 5: Iterate
|
|
188
|
+
|
|
189
|
+
When you make changes to this package:
|
|
190
|
+
|
|
191
|
+
1. Rebuild and repack: `npm run build && npm pack`
|
|
192
|
+
2. Reinstall in the template: `cd dev/the-store && npm update @apollo/client-ai-apps`
|
|
193
|
+
3. Restart the React app dev server
|
|
194
|
+
|
|
195
|
+
Refer to the [MCP Apps Quickstart Guide](https://www.apollographql.com/docs/apollo-mcp-server/mcp-apps-quickstart) for more details on configuring the template, setting up tunneling for end-to-end testing with a host like ChatGPT, and other development workflows.
|
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
<header>
|
|
2
|
+
<div align="center">
|
|
3
|
+
<a href="https://www.apollographql.com?utm_medium=github&utm_source=apollographql_apollo-client-ai-apps&utm_campaign=readme"><img src="https://raw.githubusercontent.com/apollographql/apollo-client-devtools/main/assets/apollo-wordmark.svg" height="100" alt="Apollo Logo"></a>
|
|
4
|
+
</div>
|
|
5
|
+
<h1 align="center">Apollo Client - MCP Apps Integration</h1>
|
|
6
|
+
|
|
7
|
+
**The industry-leading GraphQL client for TypeScript, JavaScript, React, Vue, Angular, and more.** Apollo Client delivers powerful caching, intuitive APIs, and comprehensive developer tools to accelerate your app development.
|
|
8
|
+
|
|
9
|
+
➡️ [**Get Started with Apollo Client's MCP Apps Integration→**](https://www.apollographql.com/docs/apollo-mcp-server/mcp-apps?utm_source=github&utm_medium=apollographql_apollo-client-ai-apps&utm_campaign=readme)
|
|
10
|
+
|
|
11
|
+
<div align="center">
|
|
12
|
+
|
|
13
|
+
[](https://img.shields.io/npm/v/%40apollo%2Fclient-ai-apps) [](https://community.apollographql.com)
|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
</header>
|
|
17
|
+
|
|
18
|
+
## 🚀 Quick Start
|
|
19
|
+
|
|
20
|
+
Use our [MCP Apps template](https://github.com/apollographql/ai-apps-template) with a working application:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
npx tiged apollographql/ai-apps-template my-awesome-app
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Apollo Client Skill
|
|
27
|
+
|
|
28
|
+
Give your AI agent specialized Apollo Client knowledge and setup guidance:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
npx skills add apollographql/skills --skill apollo-client
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 💡 Resources
|
|
35
|
+
|
|
36
|
+
| Resource | Description | Link |
|
|
37
|
+
| ------------------------------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
38
|
+
| **Getting Started Guide** | MCP Apps quickstart guide | [Start Here →](https://www.apollographql.com/docs/apollo-mcp-server/mcp-apps-quickstart?utm_source=github&utm_medium=apollographql_apollo-client-ai-apps&utm_campaign=readme) |
|
|
39
|
+
| **Documentation** | MCP Apps documentation | [Read Docs →](https://www.apollographql.com/docs/apollo-mcp-server/mcp-apps?utm_source=github&utm_medium=apollographql_apollo-client-ai-apps&utm_campaign=readme) |
|
|
40
|
+
| **Apollo Client Documentation** | Comprehensive documentation for Apollo Client | [Apollo Client →](https://www.apollographql.com/docs/react?utm_source=github&utm_medium=apollographql_apollo-client-ai-apps&utm_campaign=readme) |
|
|
41
|
+
| **VS Code Extension** | Enhanced development experience | [Install Extension →](https://marketplace.visualstudio.com/items?itemName=apollographql.vscode-apollo) |
|
|
42
|
+
| **DevTools** | Debug your GraphQL apps | [Chrome](https://chrome.google.com/webstore/detail/apollo-client-devtools/jdkknkkbebbapilgoeccciglkfbmbnfm) \| [Firefox](https://addons.mozilla.org/en-US/firefox/addon/apollo-developer-tools/) |
|
|
43
|
+
|
|
44
|
+
## 🧑🚀 About Apollo
|
|
45
|
+
|
|
46
|
+
Deliver tomorrow's roadmap today with our comprehensive suite of API orchestration tools:
|
|
47
|
+
|
|
48
|
+
- [**Apollo Client MCP Apps Integration**](https://www.apollographql.com/docs/apollo-mcp-server/mcp-apps?utm_source=github&utm_medium=apollographql_apollo-client-ai-apps&utm_campaign=readme) \- Apollo Client and Apollo MCP Server powered MCP Apps
|
|
49
|
+
- [**Apollo Client**](https://www.apollographql.com/docs/react?utm_source=github&utm_medium=apollographql_apollo-client-ai-apps&utm_campaign=readme) \- Type-safe apps with GraphQL-powered on-device caching
|
|
50
|
+
- [**Apollo Connectors**](https://www.apollographql.com/graphos/apollo-connectors?utm_source=github&utm_medium=apollographql_apollo-client-ai-apps&utm_campaign=readme) \- Compose all your GraphQL and REST APIs into one GraphQL endpoint
|
|
51
|
+
- [**Apollo MCP Server**](https://www.apollographql.com/apollo-mcp-server?utm_source=github&utm_medium=apollographql_apollo-client-ai-apps&utm_campaign=readme) \- AI needs APIs. The fastest way to ship reliable AI experiences
|
|
52
|
+
- [**Apollo Router**](https://www.apollographql.com/docs/router?utm_source=github&utm_medium=apollographql_apollo-client-ai-apps&utm_campaign=readme) \- Scale your APIs seamlessly with GraphQL Federation, Security, Auth, and more
|
|
53
|
+
- [**GraphOS**](https://www.apollographql.com/graphos?utm_source=github&utm_medium=apollographql_apollo-client-ai-apps&utm_campaign=readme) \- Deploy, manage, govern, and explore your APIs ([start for free, no credit card needed](https://www.apollographql.com/pricing?utm_medium=github&utm_source=apollographql_apollo-client-ai-apps&utm_campaign=readme))
|
|
54
|
+
|
|
55
|
+
[**Explore the Complete Apollo Platform →**](https://www.apollographql.com/?utm_source=github&utm_medium=apollographql-_apollo-client-ai-apps&utm_campaign=readme)
|
|
56
|
+
|
|
57
|
+
## 🛠️ Maintained by
|
|
58
|
+
|
|
59
|
+
| Name | Username |
|
|
60
|
+
| --------------- | ---------------------------------------------------- |
|
|
61
|
+
| Jerel Miller | [@jerelmiller](https://github.com/jerelmiller) |
|
|
62
|
+
| Andrew McGivery | [@andrewmcgivery](https://github.com/andrewmcgivery) |
|
|
63
|
+
|
|
64
|
+
## 🏆 Contributing
|
|
65
|
+
|
|
66
|
+
Thank you for your interest in submitting a Pull Request to Apollo Client! Read our [guidelines](https://github.com/apollographql/apollo-client-ai-apps/blob/main/CONTRIBUTING.md) first, and don't hesitate to get in touch.
|
|
67
|
+
|
|
68
|
+
## 🤝 Code of Conduct
|
|
69
|
+
|
|
70
|
+
Please read our [Code of Conduct](https://community.apollographql.com/faq). This applies to any space run by Apollo, including our GitHub repositories, the Apollo GraphOS Discord, the Apollo GraphQL Forum. The Code of Conduct reflects our commitment to making the Apollo Community a welcoming and safe space in which individuals can interact.
|
|
71
|
+
|
|
72
|
+
## 🪪 License
|
|
73
|
+
|
|
74
|
+
Source code in this repository is available under the terms of the MIT License. Read the full text [here](https://github.com/apollographql/apollo-client-ai-apps/blob/main/LICENSE).
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ApolloLink, ApolloClient as NativeApolloClient, ObservableQuery, type OperationVariables, type WatchQueryOptions } from "@apollo/client";
|
|
2
|
+
import type { ApplicationManifest } from "../types/application-manifest.js";
|
|
3
|
+
import { aiClientSymbol } from "../utilities/constants.js";
|
|
4
|
+
import { type ConnectToHostImplementation } from "./McpAppManager.js";
|
|
5
|
+
import type { ApolloMcpServerApps } from "./types.js";
|
|
6
|
+
export declare namespace AbstractApolloClient {
|
|
7
|
+
interface Options extends Omit<NativeApolloClient.Options, "link"> {
|
|
8
|
+
link?: NativeApolloClient.Options["link"];
|
|
9
|
+
manifest: ApplicationManifest;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export declare class AbstractApolloClient extends NativeApolloClient {
|
|
13
|
+
#private;
|
|
14
|
+
manifest: ApplicationManifest;
|
|
15
|
+
private readonly appManager;
|
|
16
|
+
/** @internal */
|
|
17
|
+
readonly [aiClientSymbol] = true;
|
|
18
|
+
constructor(options: AbstractApolloClient.Options, connectToHost: ConnectToHostImplementation);
|
|
19
|
+
get toolInfo(): {
|
|
20
|
+
toolName: string;
|
|
21
|
+
toolInput: Record<string, unknown> | undefined;
|
|
22
|
+
} | undefined;
|
|
23
|
+
get toolMetadata(): ApolloMcpServerApps.Meta | undefined;
|
|
24
|
+
setLink(newLink: ApolloLink): void;
|
|
25
|
+
stop(): void;
|
|
26
|
+
protected get hydratedToolInput(): Record<string, unknown> | undefined;
|
|
27
|
+
protected clearHydratedToolInput(): void;
|
|
28
|
+
watchQuery<T = any, TVariables extends OperationVariables = OperationVariables>(options: WatchQueryOptions<TVariables, T>): ObservableQuery<T, TVariables>;
|
|
29
|
+
connect: (() => Promise<void>) & {
|
|
30
|
+
reset: () => void;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=AbstractApolloClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractApolloClient.d.ts","sourceRoot":"","sources":["../../src/core/AbstractApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,YAAY,IAAI,kBAAkB,EAElC,eAAe,EACf,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACvB,MAAM,gBAAgB,CAAC;AAKxB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAEL,KAAK,2BAA2B,EACjC,MAAM,oBAAoB,CAAC;AAU5B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAGtD,MAAM,CAAC,OAAO,WAAW,oBAAoB,CAAC;IAC5C,UAAiB,OAAQ,SAAQ,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,CAAC;QACvE,IAAI,CAAC,EAAE,kBAAkB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC1C,QAAQ,EAAE,mBAAmB,CAAC;KAC/B;CACF;AAED,qBAAa,oBAAqB,SAAQ,kBAAkB;;IAC1D,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAE3C,gBAAgB;IAChB,QAAQ,CAAC,CAAC,cAAc,CAAC,QAAQ;gBAS/B,OAAO,EAAE,oBAAoB,CAAC,OAAO,EACrC,aAAa,EAAE,2BAA2B;IAgC5C,IAAI,QAAQ;;;kBAEX;IAED,IAAI,YAAY,yCAEf;IAED,OAAO,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI;IAIlC,IAAI;IAKJ,SAAS,KAAK,iBAAiB,wCAE9B;IAED,SAAS,CAAC,sBAAsB;IAIhC,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;;MAyCJ;CACJ"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { ApolloLink, ApolloClient as NativeApolloClient, DocumentTransform, ObservableQuery, } from "@apollo/client";
|
|
2
|
+
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
3
|
+
import { removeDirectivesFromDocument } from "@apollo/client/utilities/internal";
|
|
4
|
+
import { parse, visit } from "graphql";
|
|
5
|
+
import { equal } from "@wry/equality";
|
|
6
|
+
import { aiClientSymbol } from "../utilities/constants.js";
|
|
7
|
+
import { McpAppManager, } from "./McpAppManager.js";
|
|
8
|
+
import { ToolHydrationLink } from "../link/ToolHydrationLink.js";
|
|
9
|
+
import { ToolCallLink } from "../link/ToolCallLink.js";
|
|
10
|
+
import { cacheAsync, getToolNamesFromDocument, getVariableNamesFromDocument, getVariablesForOperationFromToolInput, warnOnVariableMismatch, } from "../utilities/index.js";
|
|
11
|
+
export class AbstractApolloClient extends NativeApolloClient {
|
|
12
|
+
manifest;
|
|
13
|
+
appManager;
|
|
14
|
+
/** @internal */
|
|
15
|
+
[aiClientSymbol] = true;
|
|
16
|
+
#hydratedToolInput;
|
|
17
|
+
#toolHydrationLink;
|
|
18
|
+
#toolInfo;
|
|
19
|
+
#toolMetadata;
|
|
20
|
+
constructor(options, connectToHost) {
|
|
21
|
+
const toolHydrationLink = new ToolHydrationLink();
|
|
22
|
+
const link = options.link ?? new ToolCallLink();
|
|
23
|
+
if (__DEV__) {
|
|
24
|
+
validateTerminatingLink(link);
|
|
25
|
+
}
|
|
26
|
+
super({
|
|
27
|
+
...options,
|
|
28
|
+
link: toolHydrationLink.concat(link),
|
|
29
|
+
// Strip out the prefetch/tool directives so they don't get sent with the operation to the server
|
|
30
|
+
documentTransform: new DocumentTransform((document) => {
|
|
31
|
+
const serverDocument = removeDirectivesFromDocument([{ name: "prefetch" }, { name: "tool" }], document);
|
|
32
|
+
return visit(serverDocument, {
|
|
33
|
+
OperationDefinition(node) {
|
|
34
|
+
return { ...node, description: undefined };
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}).concat(options.documentTransform ?? DocumentTransform.identity()),
|
|
38
|
+
});
|
|
39
|
+
this.#toolHydrationLink = toolHydrationLink;
|
|
40
|
+
this.manifest = options.manifest;
|
|
41
|
+
this.appManager = new McpAppManager(this.manifest, connectToHost);
|
|
42
|
+
}
|
|
43
|
+
get toolInfo() {
|
|
44
|
+
return this.#toolInfo;
|
|
45
|
+
}
|
|
46
|
+
get toolMetadata() {
|
|
47
|
+
return this.#toolMetadata;
|
|
48
|
+
}
|
|
49
|
+
setLink(newLink) {
|
|
50
|
+
super.setLink(this.#toolHydrationLink.concat(newLink));
|
|
51
|
+
}
|
|
52
|
+
stop() {
|
|
53
|
+
super.stop();
|
|
54
|
+
this.appManager.close().catch(() => { });
|
|
55
|
+
}
|
|
56
|
+
get hydratedToolInput() {
|
|
57
|
+
return this.#hydratedToolInput;
|
|
58
|
+
}
|
|
59
|
+
clearHydratedToolInput() {
|
|
60
|
+
this.#hydratedToolInput = undefined;
|
|
61
|
+
}
|
|
62
|
+
watchQuery(options) {
|
|
63
|
+
if (__DEV__) {
|
|
64
|
+
const toolInput = this.#hydratedToolInput;
|
|
65
|
+
if (toolInput) {
|
|
66
|
+
const toolName = this.toolInfo?.toolName;
|
|
67
|
+
const hasMatchingTool = !!toolName && getToolNamesFromDocument(options.query).has(toolName);
|
|
68
|
+
if (hasMatchingTool) {
|
|
69
|
+
// Clear after first matching comparison so this only fires once and
|
|
70
|
+
// remounting doesn't produce spurious warnings.
|
|
71
|
+
this.#hydratedToolInput = undefined;
|
|
72
|
+
const variableNames = getVariableNamesFromDocument(options.query);
|
|
73
|
+
if (variableNames.size > 0) {
|
|
74
|
+
const { variables } = options;
|
|
75
|
+
const toolInputVariables = Object.entries(toolInput).filter(([key]) => variableNames.has(key));
|
|
76
|
+
const hasToolInputMismatch = toolInputVariables.some(([key, value]) => !equal(value, variables?.[key]));
|
|
77
|
+
if (hasToolInputMismatch) {
|
|
78
|
+
warnOnVariableMismatch(options.query, Object.fromEntries(toolInputVariables), variables);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return super.watchQuery(options);
|
|
85
|
+
}
|
|
86
|
+
connect = cacheAsync(async () => {
|
|
87
|
+
const { structuredContent, toolName, toolInput, _meta } = await this.appManager.connect();
|
|
88
|
+
this.#hydratedToolInput = toolInput;
|
|
89
|
+
this.#toolMetadata = _meta;
|
|
90
|
+
if (toolName != null) {
|
|
91
|
+
this.#toolInfo = { toolName, toolInput };
|
|
92
|
+
}
|
|
93
|
+
this.manifest.operations.forEach((operation) => {
|
|
94
|
+
if (operation.prefetchID &&
|
|
95
|
+
structuredContent.prefetch?.[operation.prefetchID]) {
|
|
96
|
+
this.writeQuery({
|
|
97
|
+
query: parse(operation.body),
|
|
98
|
+
data: structuredContent.prefetch[operation.prefetchID].data,
|
|
99
|
+
});
|
|
100
|
+
this.#toolHydrationLink.hydrate(operation, {
|
|
101
|
+
result: structuredContent.prefetch[operation.prefetchID],
|
|
102
|
+
variables: {},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (structuredContent.result &&
|
|
106
|
+
operation.tools.find((tool) => tool.name === toolName)) {
|
|
107
|
+
this.#toolHydrationLink.hydrate(operation, {
|
|
108
|
+
result: structuredContent.result,
|
|
109
|
+
variables: getVariablesForOperationFromToolInput(operation, toolInput),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
this.#toolHydrationLink.complete();
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function validateTerminatingLink(link) {
|
|
117
|
+
let terminatingLink = link;
|
|
118
|
+
while (terminatingLink.right) {
|
|
119
|
+
terminatingLink = terminatingLink.right;
|
|
120
|
+
}
|
|
121
|
+
if (!isNamedLink(terminatingLink) ||
|
|
122
|
+
terminatingLink.name !== "ToolCallLink") {
|
|
123
|
+
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.");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function isNamedLink(link) {
|
|
127
|
+
return "name" in link;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=AbstractApolloClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractApolloClient.js","sourceRoot":"","sources":["../../src/core/AbstractApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,YAAY,IAAI,kBAAkB,EAClC,iBAAiB,EACjB,eAAe,GAGhB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAC/D,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,KAAK,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IAC1C,CAAC;IAED,IACE,CAAC,WAAW,CAAC,eAAe,CAAC;QAC7B,eAAe,CAAC,IAAI,KAAK,cAAc,EACvC,CAAC;QACD,MAAM,IAAI,KAAK,CACb,0JAA0J,CAC3J,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,IAAgB;IACnC,OAAO,MAAM,IAAI,IAAI,CAAC;AACxB,CAAC","sourcesContent":["import {\n ApolloLink,\n ApolloClient as NativeApolloClient,\n DocumentTransform,\n ObservableQuery,\n type OperationVariables,\n type WatchQueryOptions,\n} from \"@apollo/client\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport { removeDirectivesFromDocument } from \"@apollo/client/utilities/internal\";\nimport { parse, visit } from \"graphql\";\nimport { equal } from \"@wry/equality\";\nimport type { ApplicationManifest } from \"../types/application-manifest.js\";\nimport { aiClientSymbol } from \"../utilities/constants.js\";\nimport {\n McpAppManager,\n type ConnectToHostImplementation,\n} from \"./McpAppManager.js\";\nimport { ToolHydrationLink } from \"../link/ToolHydrationLink.js\";\nimport { ToolCallLink } from \"../link/ToolCallLink.js\";\nimport {\n cacheAsync,\n getToolNamesFromDocument,\n getVariableNamesFromDocument,\n getVariablesForOperationFromToolInput,\n warnOnVariableMismatch,\n} from \"../utilities/index.js\";\nimport type { ApolloMcpServerApps } from \"./types.js\";\nimport type { ToolInfo } from \"./typeRegistration.js\";\n\nexport declare namespace AbstractApolloClient {\n export interface Options extends Omit<NativeApolloClient.Options, \"link\"> {\n link?: NativeApolloClient.Options[\"link\"];\n manifest: ApplicationManifest;\n }\n}\n\nexport class AbstractApolloClient extends NativeApolloClient {\n manifest: ApplicationManifest;\n private readonly appManager: McpAppManager;\n\n /** @internal */\n readonly [aiClientSymbol] = true;\n\n #hydratedToolInput: Record<string, unknown> | undefined;\n #toolHydrationLink: ToolHydrationLink;\n\n #toolInfo: ToolInfo | undefined;\n #toolMetadata: ApolloMcpServerApps.CallToolResult[\"_meta\"] | undefined;\n\n constructor(\n options: AbstractApolloClient.Options,\n connectToHost: ConnectToHostImplementation\n ) {\n const toolHydrationLink = new ToolHydrationLink();\n const link = options.link ?? new ToolCallLink();\n\n if (__DEV__) {\n validateTerminatingLink(link);\n }\n\n super({\n ...options,\n link: toolHydrationLink.concat(link),\n // Strip out the prefetch/tool directives so they don't get sent with the operation to the server\n documentTransform: new DocumentTransform((document) => {\n const serverDocument = removeDirectivesFromDocument(\n [{ name: \"prefetch\" }, { name: \"tool\" }],\n document\n )!;\n\n return visit(serverDocument, {\n OperationDefinition(node) {\n return { ...node, description: undefined };\n },\n });\n }).concat(options.documentTransform ?? DocumentTransform.identity()),\n });\n\n this.#toolHydrationLink = toolHydrationLink;\n this.manifest = options.manifest;\n this.appManager = new McpAppManager(this.manifest, connectToHost);\n }\n\n get toolInfo() {\n return this.#toolInfo;\n }\n\n get toolMetadata() {\n return this.#toolMetadata;\n }\n\n setLink(newLink: ApolloLink): void {\n super.setLink(this.#toolHydrationLink.concat(newLink));\n }\n\n stop() {\n super.stop();\n this.appManager.close().catch(() => {});\n }\n\n protected get hydratedToolInput() {\n return this.#hydratedToolInput;\n }\n\n protected clearHydratedToolInput() {\n this.#hydratedToolInput = undefined;\n }\n\n watchQuery<\n T = any,\n TVariables extends OperationVariables = OperationVariables,\n >(options: WatchQueryOptions<TVariables, T>): ObservableQuery<T, TVariables> {\n if (__DEV__) {\n const toolInput = this.#hydratedToolInput;\n\n if (toolInput) {\n const toolName = this.toolInfo?.toolName;\n const hasMatchingTool =\n !!toolName && getToolNamesFromDocument(options.query).has(toolName);\n\n if (hasMatchingTool) {\n // Clear after first matching comparison so this only fires once and\n // remounting doesn't produce spurious warnings.\n this.#hydratedToolInput = undefined;\n\n const variableNames = getVariableNamesFromDocument(options.query);\n\n if (variableNames.size > 0) {\n const { variables } = options;\n const toolInputVariables = Object.entries(toolInput).filter(\n ([key]) => variableNames.has(key)\n );\n\n const hasToolInputMismatch = toolInputVariables.some(\n ([key, value]) => !equal(value, variables?.[key])\n );\n\n if (hasToolInputMismatch) {\n warnOnVariableMismatch(\n options.query,\n Object.fromEntries(toolInputVariables),\n variables\n );\n }\n }\n }\n }\n }\n\n return super.watchQuery(options);\n }\n\n connect = cacheAsync(async () => {\n const { structuredContent, toolName, toolInput, _meta } =\n await this.appManager.connect();\n\n this.#hydratedToolInput = toolInput;\n this.#toolMetadata = _meta;\n\n if (toolName != null) {\n this.#toolInfo = { toolName, toolInput };\n }\n\n this.manifest.operations.forEach((operation) => {\n if (\n operation.prefetchID &&\n structuredContent.prefetch?.[operation.prefetchID]\n ) {\n this.writeQuery({\n query: parse(operation.body),\n data: structuredContent.prefetch[operation.prefetchID].data,\n });\n this.#toolHydrationLink.hydrate(operation, {\n result: structuredContent.prefetch[operation.prefetchID],\n variables: {},\n });\n }\n\n if (\n structuredContent.result &&\n operation.tools.find((tool) => tool.name === toolName)\n ) {\n this.#toolHydrationLink.hydrate(operation, {\n result: structuredContent.result,\n variables: getVariablesForOperationFromToolInput(\n operation,\n toolInput\n ),\n });\n }\n });\n\n this.#toolHydrationLink.complete();\n });\n}\n\nfunction validateTerminatingLink(link: ApolloLink) {\n let terminatingLink = link;\n\n while (terminatingLink.right) {\n terminatingLink = terminatingLink.right;\n }\n\n if (\n !isNamedLink(terminatingLink) ||\n terminatingLink.name !== \"ToolCallLink\"\n ) {\n throw new Error(\n \"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.\"\n );\n }\n}\n\nfunction isNamedLink(link: ApolloLink): link is ApolloLink & { name: string } {\n return \"name\" in link;\n}\n"]}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { ApplicationManifest } from "../types/application-manifest.js";
|
|
1
|
+
import { AbstractApolloClient } from "./AbstractApolloClient.js";
|
|
3
2
|
import { aiClientSymbol } from "../utilities/constants.js";
|
|
4
3
|
export declare namespace ApolloClient {
|
|
5
|
-
interface Options extends
|
|
6
|
-
link?: BaseApolloClient.Options["link"];
|
|
7
|
-
manifest: ApplicationManifest;
|
|
4
|
+
interface Options extends AbstractApolloClient.Options {
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
export declare class ApolloClient extends
|
|
7
|
+
export declare class ApolloClient extends AbstractApolloClient {
|
|
11
8
|
/** @internal */
|
|
12
9
|
readonly [aiClientSymbol] = true;
|
|
13
10
|
constructor(options: ApolloClient.Options);
|
|
14
|
-
connect(): Promise<void>;
|
|
15
11
|
}
|
|
16
12
|
//# sourceMappingURL=ApolloClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApolloClient.d.ts","sourceRoot":"","sources":["../../src/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ApolloClient.d.ts","sourceRoot":"","sources":["../../src/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,MAAM,CAAC,OAAO,WAAW,YAAY,CAAC;IACpC,UAAiB,OAAQ,SAAQ,oBAAoB,CAAC,OAAO;KAAG;CACjE;AAED,qBAAa,YAAa,SAAQ,oBAAoB;IACpD,gBAAgB;IAChB,QAAQ,CAAC,CAAC,cAAc,CAAC,QAAQ;gBAErB,OAAO,EAAE,YAAY,CAAC,OAAO;CAW1C"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbstractApolloClient } from "./AbstractApolloClient.js";
|
|
2
2
|
import { aiClientSymbol } from "../utilities/constants.js";
|
|
3
|
-
export class ApolloClient extends
|
|
3
|
+
export class ApolloClient extends AbstractApolloClient {
|
|
4
4
|
/** @internal */
|
|
5
5
|
[aiClientSymbol] = true;
|
|
6
6
|
constructor(options) {
|
|
7
|
-
super(options)
|
|
7
|
+
super(options, () => {
|
|
8
|
+
throw new Error("Cannot connect an `ApolloClient` instance from `@apollo/client-ai-apps` without export conditions. Please set conditions or import from the `/openai` or `/mcp` subpath directly.");
|
|
9
|
+
});
|
|
8
10
|
throw new Error("Cannot construct an `ApolloClient` instance from `@apollo/client-ai-apps` without export conditions. Please set conditions or import from the `/openai` or `/mcp` subpath directly.");
|
|
9
11
|
}
|
|
10
|
-
async connect() { }
|
|
11
12
|
}
|
|
12
13
|
//# sourceMappingURL=ApolloClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApolloClient.js","sourceRoot":"","sources":["../../src/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ApolloClient.js","sourceRoot":"","sources":["../../src/core/ApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAM3D,MAAM,OAAO,YAAa,SAAQ,oBAAoB;IACpD,gBAAgB;IACP,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;IAEjC,YAAY,OAA6B;QACvC,KAAK,CAAC,OAAc,EAAE,GAAG,EAAE;YACzB,MAAM,IAAI,KAAK,CACb,mLAAmL,CACpL,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,MAAM,IAAI,KAAK,CACb,qLAAqL,CACtL,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { AbstractApolloClient } from \"./AbstractApolloClient.js\";\nimport { aiClientSymbol } from \"../utilities/constants.js\";\n\nexport declare namespace ApolloClient {\n export interface Options extends AbstractApolloClient.Options {}\n}\n\nexport class ApolloClient extends AbstractApolloClient {\n /** @internal */\n readonly [aiClientSymbol] = true;\n\n constructor(options: ApolloClient.Options) {\n super(options as any, () => {\n throw new Error(\n \"Cannot connect an `ApolloClient` instance from `@apollo/client-ai-apps` without export conditions. Please set conditions or import from the `/openai` or `/mcp` subpath directly.\"\n );\n });\n\n throw new Error(\n \"Cannot construct an `ApolloClient` instance from `@apollo/client-ai-apps` without export conditions. Please set conditions or import from the `/openai` or `/mcp` subpath directly.\"\n );\n }\n}\n"]}
|