@apollo/client-ai-apps 0.6.5 → 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 +62 -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/{mcp/core → core}/McpAppManager.d.ts +14 -10
- 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/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 -101
- 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 -101
- 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/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/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/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 -170
- package/src/mcp/core/__tests__/ApolloClient.test.ts +398 -140
- package/src/mcp/index.ts +0 -1
- package/src/openai/core/ApolloClient.ts +48 -166
- package/src/openai/core/__tests__/ApolloClient.test.ts +680 -185
- 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/utilities/connectToHost.ts +13 -0
- package/src/utilities/index.ts +1 -0
- package/tsconfig.vite.json +1 -1
- package/vitest.config.ts +13 -0
- package/dist/mcp/core/McpAppManager.d.ts.map +0 -1
- package/dist/mcp/core/McpAppManager.js +0 -88
- 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 -37
- package/dist/openai/core/McpAppManager.d.ts.map +0 -1
- package/dist/openai/core/McpAppManager.js +0 -97
- 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 -136
- package/src/mcp/link/ToolCallLink.ts +0 -40
- package/src/mcp/link/__tests__/ToolCallLink.test.ts +0 -113
- 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 -148
- 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
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { gql, InMemoryCache } from "@apollo/client";
|
|
3
|
+
import { execute } from "@apollo/client/link";
|
|
4
|
+
import {
|
|
5
|
+
eachHostEnv,
|
|
6
|
+
mockApplicationManifest,
|
|
7
|
+
ObservableStream,
|
|
8
|
+
spyOnConsole,
|
|
9
|
+
} from "../../testing/internal/index.js";
|
|
10
|
+
import { ToolCallLink } from "../ToolCallLink.js";
|
|
11
|
+
|
|
12
|
+
eachHostEnv((setupHost, ApolloClient) => {
|
|
13
|
+
test("merges _meta.structuredContent into result for @private fields", async () => {
|
|
14
|
+
using _ = spyOnConsole("debug");
|
|
15
|
+
const query = gql`
|
|
16
|
+
query GreetingQuery {
|
|
17
|
+
greeting @private
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
const client = new ApolloClient({
|
|
22
|
+
cache: new InMemoryCache(),
|
|
23
|
+
manifest: mockApplicationManifest(),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
using env = await setupHost({
|
|
27
|
+
client,
|
|
28
|
+
toolCall: {
|
|
29
|
+
name: "GetProduct",
|
|
30
|
+
result: { structuredContent: { result: { data: { product: null } } } },
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
const { host, params } = env;
|
|
34
|
+
|
|
35
|
+
host.sendToolInput(params.toolInput);
|
|
36
|
+
host.sendToolResult(params.toolResult);
|
|
37
|
+
|
|
38
|
+
host.mockToolCall("execute", () => ({
|
|
39
|
+
structuredContent: {},
|
|
40
|
+
_meta: {
|
|
41
|
+
structuredContent: { data: { greeting: "Hello, private world" } },
|
|
42
|
+
},
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
await client.connect();
|
|
46
|
+
|
|
47
|
+
const observable = execute(new ToolCallLink(), { query }, { client });
|
|
48
|
+
const stream = new ObservableStream(observable);
|
|
49
|
+
|
|
50
|
+
await expect(stream).toEmitValue({
|
|
51
|
+
data: { greeting: "Hello, private world" },
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
await expect(stream).toComplete();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("delegates query execution to MCP host", async () => {
|
|
58
|
+
using _ = spyOnConsole("debug");
|
|
59
|
+
const query = gql`
|
|
60
|
+
query GreetingQuery {
|
|
61
|
+
greeting
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
const client = new ApolloClient({
|
|
66
|
+
cache: new InMemoryCache(),
|
|
67
|
+
manifest: mockApplicationManifest(),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
using env = await setupHost({
|
|
71
|
+
client,
|
|
72
|
+
toolCall: {
|
|
73
|
+
name: "GetProduct",
|
|
74
|
+
result: { structuredContent: { result: { data: { product: null } } } },
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
const { host, params } = env;
|
|
78
|
+
|
|
79
|
+
host.sendToolInput(params.toolInput);
|
|
80
|
+
host.sendToolResult(params.toolResult);
|
|
81
|
+
|
|
82
|
+
host.mockToolCall("execute", () => ({
|
|
83
|
+
structuredContent: {
|
|
84
|
+
data: { greeting: "Hello, world" },
|
|
85
|
+
},
|
|
86
|
+
}));
|
|
87
|
+
|
|
88
|
+
await client.connect();
|
|
89
|
+
|
|
90
|
+
const observable = execute(new ToolCallLink(), { query }, { client });
|
|
91
|
+
const stream = new ObservableStream(observable);
|
|
92
|
+
|
|
93
|
+
await expect(stream).toEmitValue({
|
|
94
|
+
data: { greeting: "Hello, world" },
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
await expect(stream).toComplete();
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -1,178 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from "@apollo/client";
|
|
6
|
-
import type {
|
|
7
|
-
WatchQueryOptions,
|
|
8
|
-
ObservableQuery,
|
|
9
|
-
OperationVariables,
|
|
10
|
-
} from "@apollo/client";
|
|
11
|
-
import { removeDirectivesFromDocument } from "@apollo/client/utilities/internal";
|
|
12
|
-
import { parse, visit } from "graphql";
|
|
13
|
-
import { equal } from "@wry/equality";
|
|
14
|
-
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
15
|
-
import type { ApplicationManifest } from "../../types/application-manifest.js";
|
|
16
|
-
import { ToolCallLink } from "../link/ToolCallLink.js";
|
|
17
|
-
import {
|
|
18
|
-
aiClientSymbol,
|
|
19
|
-
cacheAsync,
|
|
20
|
-
getToolNamesFromDocument,
|
|
21
|
-
getVariableNamesFromDocument,
|
|
22
|
-
getVariablesForOperationFromToolInput,
|
|
23
|
-
warnOnVariableMismatch,
|
|
24
|
-
} from "../../utilities/index.js";
|
|
25
|
-
import { McpAppManager } from "./McpAppManager.js";
|
|
1
|
+
import type { App } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import { AbstractApolloClient } from "../../core/AbstractApolloClient.js";
|
|
3
|
+
import { connectToHost, promiseWithResolvers } from "../../utilities/index.js";
|
|
4
|
+
import type { ApolloMcpServerApps } from "../../core/types.js";
|
|
26
5
|
|
|
27
6
|
export declare namespace ApolloClient {
|
|
28
|
-
export interface Options extends
|
|
29
|
-
link?: BaseApolloClient.Options["link"];
|
|
30
|
-
manifest: ApplicationManifest;
|
|
31
|
-
}
|
|
7
|
+
export interface Options extends AbstractApolloClient.Options {}
|
|
32
8
|
}
|
|
33
9
|
|
|
34
|
-
export class ApolloClient extends
|
|
35
|
-
manifest: ApplicationManifest;
|
|
36
|
-
private readonly appManager: McpAppManager;
|
|
37
|
-
|
|
38
|
-
/** @internal */
|
|
39
|
-
readonly [aiClientSymbol] = true;
|
|
40
|
-
|
|
41
|
-
#toolInput: Record<string, unknown> | undefined;
|
|
42
|
-
|
|
10
|
+
export class ApolloClient extends AbstractApolloClient {
|
|
43
11
|
constructor(options: ApolloClient.Options) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
stop() {
|
|
73
|
-
super.stop();
|
|
74
|
-
this.appManager.close().catch(() => {});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
get toolInput() {
|
|
78
|
-
return this.#toolInput;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
clearToolInput() {
|
|
82
|
-
this.#toolInput = undefined;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
watchQuery<
|
|
86
|
-
T = any,
|
|
87
|
-
TVariables extends OperationVariables = OperationVariables,
|
|
88
|
-
>(options: WatchQueryOptions<TVariables, T>): ObservableQuery<T, TVariables> {
|
|
89
|
-
if (__DEV__) {
|
|
90
|
-
const toolInput = this.#toolInput;
|
|
91
|
-
|
|
92
|
-
if (toolInput) {
|
|
93
|
-
const toolName = this.appManager.toolName;
|
|
94
|
-
const hasMatchingTool =
|
|
95
|
-
!!toolName && getToolNamesFromDocument(options.query).has(toolName);
|
|
96
|
-
|
|
97
|
-
if (hasMatchingTool) {
|
|
98
|
-
// Clear after first matching comparison so this only fires once and
|
|
99
|
-
// remounting doesn't produce spurious warnings.
|
|
100
|
-
this.#toolInput = undefined;
|
|
101
|
-
|
|
102
|
-
const variableNames = getVariableNamesFromDocument(options.query);
|
|
103
|
-
|
|
104
|
-
if (variableNames.size > 0) {
|
|
105
|
-
const { variables } = options;
|
|
106
|
-
const toolInputVariables = Object.entries(toolInput).filter(
|
|
107
|
-
([key]) => variableNames.has(key)
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
const hasToolInputMismatch = toolInputVariables.some(
|
|
111
|
-
([key, value]) => !equal(value, variables?.[key])
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
if (hasToolInputMismatch) {
|
|
115
|
-
warnOnVariableMismatch(
|
|
116
|
-
options.query,
|
|
117
|
-
Object.fromEntries(toolInputVariables),
|
|
118
|
-
variables
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return super.watchQuery(options);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
connect = cacheAsync(async () => {
|
|
130
|
-
const { structuredContent, toolName, args } =
|
|
131
|
-
await this.appManager.connect();
|
|
132
|
-
|
|
133
|
-
this.#toolInput = args;
|
|
134
|
-
|
|
135
|
-
this.manifest.operations.forEach((operation) => {
|
|
136
|
-
if (
|
|
137
|
-
operation.prefetchID &&
|
|
138
|
-
structuredContent.prefetch?.[operation.prefetchID]
|
|
139
|
-
) {
|
|
140
|
-
this.writeQuery({
|
|
141
|
-
query: parse(operation.body),
|
|
142
|
-
data: structuredContent.prefetch[operation.prefetchID].data,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (operation.tools.find((tool) => tool.name === toolName)) {
|
|
147
|
-
if (structuredContent.result?.data) {
|
|
148
|
-
this.writeQuery({
|
|
149
|
-
query: parse(operation.body),
|
|
150
|
-
data: structuredContent.result.data,
|
|
151
|
-
variables: getVariablesForOperationFromToolInput(operation, args),
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
}
|
|
12
|
+
super(options, async (app) => {
|
|
13
|
+
const toolResult =
|
|
14
|
+
promiseWithResolvers<ApolloMcpServerApps.CallToolResult>();
|
|
15
|
+
const toolInput =
|
|
16
|
+
promiseWithResolvers<Parameters<App["ontoolinput"]>[0]>();
|
|
17
|
+
|
|
18
|
+
app.ontoolresult = (params) => {
|
|
19
|
+
toolResult.resolve(
|
|
20
|
+
params as unknown as ApolloMcpServerApps.CallToolResult
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
app.ontoolinput = (params) => {
|
|
25
|
+
toolInput.resolve(params);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
await connectToHost(app);
|
|
29
|
+
|
|
30
|
+
const { structuredContent, _meta } = await toolResult.promise;
|
|
31
|
+
const { arguments: args } = await toolInput.promise;
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
structuredContent,
|
|
35
|
+
toolInput: args,
|
|
36
|
+
_meta,
|
|
37
|
+
};
|
|
155
38
|
});
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function validateTerminatingLink(link: ApolloLink) {
|
|
160
|
-
let terminatingLink = link;
|
|
161
|
-
|
|
162
|
-
while (terminatingLink.right) {
|
|
163
|
-
terminatingLink = terminatingLink.right;
|
|
164
39
|
}
|
|
165
|
-
|
|
166
|
-
if (
|
|
167
|
-
!isNamedLink(terminatingLink) ||
|
|
168
|
-
terminatingLink.name !== "ToolCallLink"
|
|
169
|
-
) {
|
|
170
|
-
throw new Error(
|
|
171
|
-
"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."
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function isNamedLink(link: ApolloLink): link is ApolloLink & { name: string } {
|
|
177
|
-
return "name" in link;
|
|
178
40
|
}
|