@apollo/client-ai-apps 0.5.4 → 0.6.1
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 +180 -0
- package/dist/config/defineConfig.d.ts +1 -0
- package/dist/config/defineConfig.d.ts.map +1 -1
- package/dist/config/schema.d.ts +1 -0
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +1 -0
- package/dist/config/schema.js.map +1 -1
- package/dist/core/typeRegistration.d.ts +33 -0
- package/dist/core/typeRegistration.d.ts.map +1 -0
- package/dist/core/typeRegistration.js +2 -0
- package/dist/core/typeRegistration.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/core/McpAppManager.d.ts +2 -1
- package/dist/mcp/core/McpAppManager.d.ts.map +1 -1
- package/dist/mcp/core/McpAppManager.js +11 -1
- package/dist/mcp/core/McpAppManager.js.map +1 -1
- package/dist/mcp/react/hooks/useHostContext.d.ts +2 -0
- package/dist/mcp/react/hooks/useHostContext.d.ts.map +1 -0
- package/dist/mcp/react/hooks/useHostContext.js +7 -0
- package/dist/mcp/react/hooks/useHostContext.js.map +1 -0
- package/dist/mcp/react/hooks/useToolInfo.d.ts +3 -0
- package/dist/mcp/react/hooks/useToolInfo.d.ts.map +1 -0
- package/dist/mcp/react/hooks/useToolInfo.js +10 -0
- package/dist/mcp/react/hooks/useToolInfo.js.map +1 -0
- package/dist/mcp/react/hooks/useToolInput.d.ts +6 -1
- package/dist/mcp/react/hooks/useToolInput.d.ts.map +1 -1
- package/dist/mcp/react/hooks/useToolInput.js +4 -0
- package/dist/mcp/react/hooks/useToolInput.js.map +1 -1
- package/dist/mcp/react/hooks/useToolName.d.ts +6 -1
- package/dist/mcp/react/hooks/useToolName.d.ts.map +1 -1
- package/dist/mcp/react/hooks/useToolName.js +4 -0
- package/dist/mcp/react/hooks/useToolName.js.map +1 -1
- package/dist/mcp/react/index.d.ts +2 -0
- package/dist/mcp/react/index.d.ts.map +1 -1
- package/dist/mcp/react/index.js +2 -0
- package/dist/mcp/react/index.js.map +1 -1
- package/dist/openai/core/McpAppManager.d.ts +2 -1
- package/dist/openai/core/McpAppManager.d.ts.map +1 -1
- package/dist/openai/core/McpAppManager.js +11 -1
- package/dist/openai/core/McpAppManager.js.map +1 -1
- package/dist/openai/react/hooks/useHostContext.d.ts +2 -0
- package/dist/openai/react/hooks/useHostContext.d.ts.map +1 -0
- package/dist/openai/react/hooks/useHostContext.js +7 -0
- package/dist/openai/react/hooks/useHostContext.js.map +1 -0
- package/dist/openai/react/hooks/useToolInfo.d.ts +3 -0
- package/dist/openai/react/hooks/useToolInfo.d.ts.map +1 -0
- package/dist/openai/react/hooks/useToolInfo.js +10 -0
- package/dist/openai/react/hooks/useToolInfo.js.map +1 -0
- package/dist/openai/react/hooks/useToolInput.d.ts +6 -1
- package/dist/openai/react/hooks/useToolInput.d.ts.map +1 -1
- package/dist/openai/react/hooks/useToolInput.js +4 -0
- package/dist/openai/react/hooks/useToolInput.js.map +1 -1
- package/dist/openai/react/hooks/useToolName.d.ts +6 -1
- package/dist/openai/react/hooks/useToolName.d.ts.map +1 -1
- package/dist/openai/react/hooks/useToolName.js +4 -0
- package/dist/openai/react/hooks/useToolName.js.map +1 -1
- package/dist/openai/react/index.d.ts +2 -0
- package/dist/openai/react/index.d.ts.map +1 -1
- package/dist/openai/react/index.js +2 -0
- package/dist/openai/react/index.js.map +1 -1
- package/dist/react/index.d.ts +10 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +10 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mcp.d.ts +1 -1
- package/dist/react/index.mcp.d.ts.map +1 -1
- package/dist/react/index.mcp.js +1 -1
- package/dist/react/index.mcp.js.map +1 -1
- package/dist/react/index.openai.d.ts +1 -1
- package/dist/react/index.openai.d.ts.map +1 -1
- package/dist/react/index.openai.js +1 -1
- package/dist/react/index.openai.js.map +1 -1
- package/dist/tsconfig/core/tsconfig.json +2 -0
- package/dist/tsconfig/mcp/tsconfig.json +2 -0
- package/dist/tsconfig/openai/tsconfig.json +2 -0
- 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/vite/__tests__/utilities/build.d.ts.map +1 -1
- package/dist/vite/__tests__/utilities/build.js +0 -1
- package/dist/vite/__tests__/utilities/build.js.map +1 -1
- package/dist/vite/apolloClientAiApps.d.ts +2 -0
- package/dist/vite/apolloClientAiApps.d.ts.map +1 -1
- package/dist/vite/apolloClientAiApps.js +362 -53
- package/dist/vite/apolloClientAiApps.js.map +1 -1
- package/dist/vite/utilities/recast.d.ts +54 -0
- package/dist/vite/utilities/recast.d.ts.map +1 -0
- package/dist/vite/utilities/recast.js +71 -0
- package/dist/vite/utilities/recast.js.map +1 -0
- package/package.json +7 -6
- package/src/config/schema.ts +1 -0
- package/src/core/typeRegistration.ts +32 -0
- package/src/index.ts +7 -0
- package/src/mcp/core/McpAppManager.ts +23 -1
- package/src/mcp/react/hooks/__tests__/useHostContext.test.tsx +95 -0
- package/src/mcp/react/hooks/__tests__/useToolInfo.test.tsx +53 -0
- package/src/mcp/react/hooks/useHostContext.ts +14 -0
- package/src/mcp/react/hooks/useToolInfo.ts +13 -0
- package/src/mcp/react/hooks/useToolInput.ts +6 -1
- package/src/mcp/react/hooks/useToolName.ts +6 -1
- package/src/mcp/react/index.ts +2 -0
- package/src/openai/core/McpAppManager.ts +22 -1
- package/src/openai/react/hooks/__tests__/useToolInfo.test.tsx +92 -0
- package/src/openai/react/hooks/useHostContext.ts +14 -0
- package/src/openai/react/hooks/useToolInfo.ts +13 -0
- package/src/openai/react/hooks/useToolInput.ts +6 -1
- package/src/openai/react/hooks/useToolName.ts +6 -1
- package/src/openai/react/index.ts +2 -0
- package/src/react/index.mcp.ts +2 -0
- package/src/react/index.openai.ts +2 -0
- package/src/react/index.ts +14 -0
- package/src/testing/internal/mcp/mockMcpHost.ts +12 -0
- package/src/testing/internal/utilities/mockApplicationManifest.ts +1 -0
- package/src/tsconfig/core/tsconfig.json +2 -0
- package/src/tsconfig/mcp/tsconfig.json +2 -0
- package/src/tsconfig/openai/tsconfig.json +2 -0
- package/src/types/application-manifest.ts +1 -0
- package/src/vite/__tests__/apolloClientAiApps.test.ts +1022 -66
- package/src/vite/__tests__/utilities/build.ts +0 -1
- package/src/vite/apolloClientAiApps.ts +604 -81
- package/src/vite/utilities/recast.ts +100 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { test, expect } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
disableActEnvironment,
|
|
4
|
+
renderHookToSnapshotStream,
|
|
5
|
+
} from "@testing-library/react-render-stream";
|
|
6
|
+
import { Suspense } from "react";
|
|
7
|
+
import { InMemoryCache } from "@apollo/client";
|
|
8
|
+
|
|
9
|
+
import { useToolInfo } from "../useToolInfo.js";
|
|
10
|
+
import { ApolloClient } from "../../../core/ApolloClient.js";
|
|
11
|
+
import {
|
|
12
|
+
graphqlToolResult,
|
|
13
|
+
minimalHostContextWithToolName,
|
|
14
|
+
mockApplicationManifest,
|
|
15
|
+
mockMcpHost,
|
|
16
|
+
spyOnConsole,
|
|
17
|
+
} from "../../../../testing/internal/index.js";
|
|
18
|
+
import { ApolloProvider } from "../../../../react/ApolloProvider.js";
|
|
19
|
+
|
|
20
|
+
test("returns tool name and input combined", async () => {
|
|
21
|
+
using _ = spyOnConsole("debug");
|
|
22
|
+
const client = new ApolloClient({
|
|
23
|
+
cache: new InMemoryCache(),
|
|
24
|
+
manifest: mockApplicationManifest(),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
using host = await mockMcpHost({
|
|
28
|
+
hostContext: minimalHostContextWithToolName("GetProduct"),
|
|
29
|
+
});
|
|
30
|
+
host.onCleanup(() => client.stop());
|
|
31
|
+
|
|
32
|
+
host.sendToolInput({ arguments: { id: "1" } });
|
|
33
|
+
host.sendToolResult(graphqlToolResult({ data: { product: null } }));
|
|
34
|
+
|
|
35
|
+
using _disabledAct = disableActEnvironment();
|
|
36
|
+
const { takeSnapshot } = await renderHookToSnapshotStream(
|
|
37
|
+
() => useToolInfo(),
|
|
38
|
+
{
|
|
39
|
+
wrapper: ({ children }) => (
|
|
40
|
+
<Suspense>
|
|
41
|
+
<ApolloProvider client={client}>{children}</ApolloProvider>
|
|
42
|
+
</Suspense>
|
|
43
|
+
),
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
await expect(takeSnapshot()).resolves.toEqual({
|
|
48
|
+
toolName: "GetProduct",
|
|
49
|
+
toolInput: { id: "1" },
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
await expect(takeSnapshot).not.toRerender();
|
|
53
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useCallback, useSyncExternalStore } from "react";
|
|
2
|
+
import { useApolloClient } from "./useApolloClient";
|
|
3
|
+
|
|
4
|
+
export function useHostContext() {
|
|
5
|
+
const appManager = useApolloClient()["appManager"];
|
|
6
|
+
|
|
7
|
+
return useSyncExternalStore(
|
|
8
|
+
useCallback(
|
|
9
|
+
(update) => appManager.onHostContextChanged(update),
|
|
10
|
+
[appManager]
|
|
11
|
+
),
|
|
12
|
+
() => appManager.app.getHostContext()
|
|
13
|
+
);
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ToolInfo } from "../../../core/typeRegistration.js";
|
|
2
|
+
import { useApolloClient } from "./useApolloClient.js";
|
|
3
|
+
|
|
4
|
+
export function useToolInfo(): ToolInfo | undefined {
|
|
5
|
+
const appManager = useApolloClient()["appManager"];
|
|
6
|
+
const toolName = appManager.toolName;
|
|
7
|
+
|
|
8
|
+
if (!toolName) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return { toolName, toolInput: appManager.toolInput };
|
|
13
|
+
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import type { ToolInput } from "../../../core/typeRegistration.js";
|
|
1
2
|
import { useApolloClient } from "./useApolloClient.js";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Please use the `useToolInfo` hook. `useToolInput` will be removed
|
|
6
|
+
* in the next major version.
|
|
7
|
+
*/
|
|
8
|
+
export function useToolInput(): ToolInput | undefined {
|
|
4
9
|
return useApolloClient()["appManager"].toolInput;
|
|
5
10
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import type { ToolName } from "../../../core/typeRegistration.js";
|
|
1
2
|
import { useApolloClient } from "./useApolloClient.js";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Please use the `useToolInfo` hook. `useToolName` will be removed
|
|
6
|
+
* in the next major version.
|
|
7
|
+
*/
|
|
8
|
+
export function useToolName(): ToolName | undefined {
|
|
4
9
|
return useApolloClient()["appManager"].toolName;
|
|
5
10
|
}
|
package/src/mcp/react/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { useApp } from "./hooks/useApp.js";
|
|
2
|
+
export { useHostContext } from "./hooks/useHostContext.js";
|
|
2
3
|
export { useToolName } from "./hooks/useToolName.js";
|
|
3
4
|
export { useToolMetadata } from "./hooks/useToolMetadata.js";
|
|
4
5
|
export { useToolInput } from "./hooks/useToolInput.js";
|
|
6
|
+
export { useToolInfo } from "./hooks/useToolInfo.js";
|
|
5
7
|
export { createHydrationUtils } from "./hooks/createHydrationUtils.js";
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
App,
|
|
3
|
+
PostMessageTransport,
|
|
4
|
+
type McpUiHostContextChangedNotification,
|
|
5
|
+
} from "@modelcontextprotocol/ext-apps";
|
|
2
6
|
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
3
7
|
import type { ApplicationManifest } from "../../types/application-manifest";
|
|
4
8
|
import type { FormattedExecutionResult } from "graphql";
|
|
@@ -19,6 +23,10 @@ export class McpAppManager {
|
|
|
19
23
|
#toolMetadata: Record<string, unknown> | null = null;
|
|
20
24
|
#toolInput: Record<string, unknown> | undefined;
|
|
21
25
|
|
|
26
|
+
#hostContextCallbacks = new Set<
|
|
27
|
+
(params: McpUiHostContextChangedNotification["params"]) => void
|
|
28
|
+
>();
|
|
29
|
+
|
|
22
30
|
constructor(manifest: ApplicationManifest) {
|
|
23
31
|
this.app = new App({ name: manifest.name, version: manifest.appVersion });
|
|
24
32
|
}
|
|
@@ -35,6 +43,15 @@ export class McpAppManager {
|
|
|
35
43
|
return this.#toolInput;
|
|
36
44
|
}
|
|
37
45
|
|
|
46
|
+
onHostContextChanged(
|
|
47
|
+
cb: (params: McpUiHostContextChangedNotification["params"]) => void
|
|
48
|
+
) {
|
|
49
|
+
this.#hostContextCallbacks.add(cb);
|
|
50
|
+
return () => {
|
|
51
|
+
this.#hostContextCallbacks.delete(cb);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
38
55
|
connect = cacheAsync(async () => {
|
|
39
56
|
let toolResult = promiseWithResolvers<ApolloMcpServerApps.CallToolResult>();
|
|
40
57
|
|
|
@@ -44,6 +61,10 @@ export class McpAppManager {
|
|
|
44
61
|
);
|
|
45
62
|
};
|
|
46
63
|
|
|
64
|
+
this.app.onhostcontextchanged = (params) => {
|
|
65
|
+
this.#hostContextCallbacks.forEach((cb) => cb(params));
|
|
66
|
+
};
|
|
67
|
+
|
|
47
68
|
await this.connectToHost();
|
|
48
69
|
|
|
49
70
|
const { structuredContent } = await toolResult.promise;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { afterEach, expect, test, vi } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
graphqlToolResult,
|
|
4
|
+
minimalHostContextWithToolName,
|
|
5
|
+
mockApplicationManifest,
|
|
6
|
+
mockMcpHost,
|
|
7
|
+
spyOnConsole,
|
|
8
|
+
stubOpenAiGlobals,
|
|
9
|
+
} from "../../../../testing/internal/index.js";
|
|
10
|
+
import {
|
|
11
|
+
disableActEnvironment,
|
|
12
|
+
renderHookToSnapshotStream,
|
|
13
|
+
} from "@testing-library/react-render-stream";
|
|
14
|
+
import { useToolInfo } from "../useToolInfo.js";
|
|
15
|
+
import { ApolloClient } from "../../../core/ApolloClient.js";
|
|
16
|
+
import { InMemoryCache } from "@apollo/client";
|
|
17
|
+
import { Suspense } from "react";
|
|
18
|
+
import { ApolloProvider } from "../../../../react/ApolloProvider.js";
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
vi.unstubAllGlobals();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("returns tool name and input combined", async () => {
|
|
25
|
+
using _ = spyOnConsole("debug");
|
|
26
|
+
stubOpenAiGlobals({ toolResponseMetadata: {}, toolInput: { id: "1" } });
|
|
27
|
+
const client = new ApolloClient({
|
|
28
|
+
cache: new InMemoryCache(),
|
|
29
|
+
manifest: mockApplicationManifest(),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
using host = await mockMcpHost({
|
|
33
|
+
hostContext: minimalHostContextWithToolName("GetProduct"),
|
|
34
|
+
});
|
|
35
|
+
host.onCleanup(() => client.stop());
|
|
36
|
+
|
|
37
|
+
host.sendToolInput({ arguments: { id: "1" } });
|
|
38
|
+
host.sendToolResult(graphqlToolResult({ data: { product: null } }));
|
|
39
|
+
|
|
40
|
+
using _disabledAct = disableActEnvironment();
|
|
41
|
+
const { takeSnapshot } = await renderHookToSnapshotStream(
|
|
42
|
+
() => useToolInfo(),
|
|
43
|
+
{
|
|
44
|
+
wrapper: ({ children }) => (
|
|
45
|
+
<Suspense>
|
|
46
|
+
<ApolloProvider client={client}>{children}</ApolloProvider>
|
|
47
|
+
</Suspense>
|
|
48
|
+
),
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
await expect(takeSnapshot()).resolves.toEqual({
|
|
53
|
+
toolName: "GetProduct",
|
|
54
|
+
toolInput: { id: "1" },
|
|
55
|
+
});
|
|
56
|
+
await expect(takeSnapshot).not.toRerender();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("returns undefined toolInput when toolInput is not provided", async () => {
|
|
60
|
+
using _ = spyOnConsole("debug");
|
|
61
|
+
stubOpenAiGlobals({ toolResponseMetadata: {} });
|
|
62
|
+
const client = new ApolloClient({
|
|
63
|
+
cache: new InMemoryCache(),
|
|
64
|
+
manifest: mockApplicationManifest(),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
using host = await mockMcpHost({
|
|
68
|
+
hostContext: minimalHostContextWithToolName("GetProduct"),
|
|
69
|
+
});
|
|
70
|
+
host.onCleanup(() => client.stop());
|
|
71
|
+
|
|
72
|
+
host.sendToolInput({ arguments: {} });
|
|
73
|
+
host.sendToolResult(graphqlToolResult({ data: { product: null } }));
|
|
74
|
+
|
|
75
|
+
using _disabledAct = disableActEnvironment();
|
|
76
|
+
const { takeSnapshot } = await renderHookToSnapshotStream(
|
|
77
|
+
() => useToolInfo(),
|
|
78
|
+
{
|
|
79
|
+
wrapper: ({ children }) => (
|
|
80
|
+
<Suspense>
|
|
81
|
+
<ApolloProvider client={client}>{children}</ApolloProvider>
|
|
82
|
+
</Suspense>
|
|
83
|
+
),
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
await expect(takeSnapshot()).resolves.toEqual({
|
|
88
|
+
toolName: "GetProduct",
|
|
89
|
+
toolInput: undefined,
|
|
90
|
+
});
|
|
91
|
+
await expect(takeSnapshot).not.toRerender();
|
|
92
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useCallback, useSyncExternalStore } from "react";
|
|
2
|
+
import { useApolloClient } from "./useApolloClient";
|
|
3
|
+
|
|
4
|
+
export function useHostContext() {
|
|
5
|
+
const appManager = useApolloClient()["appManager"];
|
|
6
|
+
|
|
7
|
+
return useSyncExternalStore(
|
|
8
|
+
useCallback(
|
|
9
|
+
(update) => appManager.onHostContextChanged(update),
|
|
10
|
+
[appManager]
|
|
11
|
+
),
|
|
12
|
+
() => appManager.app.getHostContext()
|
|
13
|
+
);
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ToolInfo } from "../../../core/typeRegistration.js";
|
|
2
|
+
import { useApolloClient } from "./useApolloClient.js";
|
|
3
|
+
|
|
4
|
+
export function useToolInfo(): ToolInfo | undefined {
|
|
5
|
+
const appManager = useApolloClient()["appManager"];
|
|
6
|
+
const toolName = appManager.toolName;
|
|
7
|
+
|
|
8
|
+
if (!toolName) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return { toolName, toolInput: appManager.toolInput };
|
|
13
|
+
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import type { ToolInput } from "../../../core/typeRegistration.js";
|
|
1
2
|
import { useApolloClient } from "./useApolloClient.js";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Please use the `useToolInfo` hook. `useToolInput` will be removed
|
|
6
|
+
* in the next major version.
|
|
7
|
+
*/
|
|
8
|
+
export function useToolInput(): ToolInput | undefined {
|
|
4
9
|
return useApolloClient()["appManager"].toolInput;
|
|
5
10
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import type { ToolName } from "../../../core/typeRegistration.js";
|
|
1
2
|
import { useApolloClient } from "./useApolloClient.js";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Please use the `useToolInfo` hook. `useToolName` will be removed
|
|
6
|
+
* in the next major version.
|
|
7
|
+
*/
|
|
8
|
+
export const useToolName = (): ToolName | undefined => {
|
|
4
9
|
return useApolloClient()["appManager"].toolName;
|
|
5
10
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { useApp } from "./hooks/useApp.js";
|
|
2
|
+
export { useHostContext } from "./hooks/useHostContext.js";
|
|
2
3
|
export { useToolName } from "./hooks/useToolName.js";
|
|
3
4
|
export { useToolMetadata } from "./hooks/useToolMetadata.js";
|
|
4
5
|
export { useToolInput } from "./hooks/useToolInput.js";
|
|
6
|
+
export { useToolInfo } from "./hooks/useToolInfo.js";
|
|
5
7
|
export { createHydrationUtils } from "./hooks/createHydrationUtils.js";
|
|
6
8
|
export { useWidgetState } from "./hooks/useWidgetState.js";
|
package/src/react/index.mcp.ts
CHANGED
package/src/react/index.ts
CHANGED
|
@@ -9,6 +9,13 @@ export type { Reactive } from "./reactive.js";
|
|
|
9
9
|
export const useApp =
|
|
10
10
|
missingHook<typeof import("./index.mcp.js").useApp>("useApp");
|
|
11
11
|
|
|
12
|
+
export const useHostContext =
|
|
13
|
+
missingHook<typeof import("./index.mcp.js").useHostContext>("useHostContext");
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Please use the `useToolInfo` hook. `useToolInput` will be removed
|
|
17
|
+
* in the next major version.
|
|
18
|
+
*/
|
|
12
19
|
export const useToolInput =
|
|
13
20
|
missingHook<typeof import("./index.mcp.js").useToolInput>("useToolInput");
|
|
14
21
|
|
|
@@ -17,9 +24,16 @@ export const useToolMetadata =
|
|
|
17
24
|
"useToolMetadata"
|
|
18
25
|
);
|
|
19
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated Please use the `useToolInfo` hook. `useToolName` will be removed
|
|
29
|
+
* in the next major version.
|
|
30
|
+
*/
|
|
20
31
|
export const useToolName =
|
|
21
32
|
missingHook<typeof import("./index.mcp.js").useToolName>("useToolName");
|
|
22
33
|
|
|
34
|
+
export const useToolInfo =
|
|
35
|
+
missingHook<typeof import("./index.mcp.js").useToolInfo>("useToolInfo");
|
|
36
|
+
|
|
23
37
|
/** @experimental */
|
|
24
38
|
export const createHydrationUtils = missingHook<
|
|
25
39
|
typeof import("./index.mcp.js").createHydrationUtils
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
LATEST_PROTOCOL_VERSION,
|
|
3
3
|
type McpUiHostCapabilities,
|
|
4
4
|
type McpUiHostContext,
|
|
5
|
+
type McpUiHostContextChangedNotification,
|
|
5
6
|
type McpUiToolResultNotification,
|
|
6
7
|
type McpUiToolInputNotification,
|
|
7
8
|
} from "@modelcontextprotocol/ext-apps";
|
|
@@ -15,6 +16,9 @@ import { invariant, promiseWithResolvers } from "../../../utilities/index.js";
|
|
|
15
16
|
export interface MockMcpHost extends Disposable {
|
|
16
17
|
sendToolResult(params: McpUiToolResultNotification["params"]): Promise<void>;
|
|
17
18
|
sendToolInput(params: McpUiToolInputNotification["params"]): Promise<void>;
|
|
19
|
+
sendHostContextChanged(
|
|
20
|
+
params: McpUiHostContextChangedNotification["params"]
|
|
21
|
+
): Promise<void>;
|
|
18
22
|
mockToolCall(
|
|
19
23
|
name: string,
|
|
20
24
|
handler: (params: CallToolRequest["params"]) => CallToolResult
|
|
@@ -166,6 +170,14 @@ export async function mockMcpHost(
|
|
|
166
170
|
params,
|
|
167
171
|
});
|
|
168
172
|
},
|
|
173
|
+
async sendHostContextChanged(params) {
|
|
174
|
+
await initialized;
|
|
175
|
+
window.postMessage({
|
|
176
|
+
jsonrpc: "2.0",
|
|
177
|
+
method: "ui/notifications/host-context-changed",
|
|
178
|
+
params,
|
|
179
|
+
});
|
|
180
|
+
},
|
|
169
181
|
mockToolCall(name, handler) {
|
|
170
182
|
if (toolCallHandlers.has(name)) {
|
|
171
183
|
console.warn(
|