@assistant-ui/react-mcp 0.1.14 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/auth/createOAuthProvider.d.ts +7 -1
  2. package/dist/auth/createOAuthProvider.d.ts.map +1 -1
  3. package/dist/auth/createOAuthProvider.js +115 -31
  4. package/dist/auth/createOAuthProvider.js.map +1 -1
  5. package/dist/auth/types.d.ts +1 -0
  6. package/dist/auth/types.d.ts.map +1 -1
  7. package/dist/hooks/useMcpOAuthCallback.d.ts.map +1 -1
  8. package/dist/hooks/useMcpOAuthCallback.js +5 -6
  9. package/dist/hooks/useMcpOAuthCallback.js.map +1 -1
  10. package/dist/primitives/server/McpServerIcon.js.map +1 -1
  11. package/dist/primitives/server/McpServerOAuthLink.js.map +1 -1
  12. package/dist/resources/McpManagerResource.d.ts.map +1 -1
  13. package/dist/resources/McpManagerResource.js +4 -2
  14. package/dist/resources/McpManagerResource.js.map +1 -1
  15. package/dist/resources/McpServerResource.d.ts +2 -1
  16. package/dist/resources/McpServerResource.d.ts.map +1 -1
  17. package/dist/resources/McpServerResource.js +107 -21
  18. package/dist/resources/McpServerResource.js.map +1 -1
  19. package/dist/resources/storage/McpLocalStorage.d.ts +7 -0
  20. package/dist/resources/storage/McpLocalStorage.d.ts.map +1 -1
  21. package/dist/resources/storage/McpLocalStorage.js +132 -37
  22. package/dist/resources/storage/McpLocalStorage.js.map +1 -1
  23. package/dist/resources/storage/McpMemoryStorage.d.ts.map +1 -1
  24. package/dist/resources/storage/McpMemoryStorage.js +9 -6
  25. package/dist/resources/storage/McpMemoryStorage.js.map +1 -1
  26. package/dist/resources/storage/types.d.ts +12 -0
  27. package/dist/resources/storage/types.d.ts.map +1 -1
  28. package/dist/utils/createMcpId.d.ts +9 -0
  29. package/dist/utils/createMcpId.d.ts.map +1 -0
  30. package/dist/utils/createMcpId.js +11 -0
  31. package/dist/utils/createMcpId.js.map +1 -0
  32. package/dist/utils/invokeMcpCallback.d.ts.map +1 -1
  33. package/dist/utils/invokeMcpCallback.js +2 -12
  34. package/dist/utils/invokeMcpCallback.js.map +1 -1
  35. package/package.json +8 -8
  36. package/src/auth/createOAuthProvider.test.ts +407 -2
  37. package/src/auth/createOAuthProvider.ts +171 -40
  38. package/src/auth/types.ts +1 -0
  39. package/src/hooks/useMcpOAuthCallback.test.ts +74 -1
  40. package/src/hooks/useMcpOAuthCallback.tsx +11 -8
  41. package/src/resources/McpManagerResource.test.ts +128 -0
  42. package/src/resources/McpManagerResource.ts +4 -5
  43. package/src/resources/McpServerResource.test.ts +420 -18
  44. package/src/resources/McpServerResource.ts +148 -27
  45. package/src/resources/storage/McpLocalStorage.test.ts +71 -1
  46. package/src/resources/storage/McpLocalStorage.ts +69 -47
  47. package/src/resources/storage/McpMemoryStorage.test.ts +99 -0
  48. package/src/resources/storage/McpMemoryStorage.ts +23 -17
  49. package/src/resources/storage/types.ts +12 -0
  50. package/src/utils/createMcpId.test.ts +25 -0
  51. package/src/utils/createMcpId.ts +10 -0
  52. package/src/utils/invokeMcpCallback.ts +3 -21
@@ -3,6 +3,18 @@ import type { MCPCustomServerRecord } from "../../mcp-scope";
3
3
  import type { MCPPersistedAuthState } from "../../auth/types";
4
4
 
5
5
  export type MCPStorage = {
6
+ /**
7
+ * Stable identity of the backing store. Two storages with the same scopeId
8
+ * must read and write the same persisted data. When present, server
9
+ * connections and the OAuth write fence key on it, so swapping to a
10
+ * differently-scoped storage reconnects instead of leaving a live OAuth flow
11
+ * on the replaced store, and clearing through a same-scoped replacement still
12
+ * waits for writes queued against the storage it replaced. When absent, the
13
+ * fence falls back to object identity while connections never re-key at all,
14
+ * so a storage rebuilt on every render has to declare a scopeId; without one
15
+ * a clear runs unfenced against the writes queued by the object it replaced.
16
+ */
17
+ scopeId?: string;
6
18
  loadCustomServers: () => Promise<MCPCustomServerRecord[]>;
7
19
  saveCustomServers: (records: MCPCustomServerRecord[]) => Promise<void>;
8
20
  loadAuthState: (serverId: string) => Promise<MCPPersistedAuthState | null>;
@@ -0,0 +1,25 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+ import { createMcpId } from "./createMcpId";
3
+ import { assertValidServerId } from "./serverId";
4
+
5
+ afterEach(() => {
6
+ vi.unstubAllGlobals();
7
+ });
8
+
9
+ describe("createMcpId", () => {
10
+ it("uses the platform UUID when one is available", () => {
11
+ vi.stubGlobal("crypto", {
12
+ randomUUID: () => "11111111-2222-3333-4444-555555555555",
13
+ });
14
+ expect(createMcpId()).toBe("11111111-2222-3333-4444-555555555555");
15
+ });
16
+
17
+ it("falls back to a prefixed generated id without randomUUID", () => {
18
+ vi.stubGlobal("crypto", {});
19
+ const first = createMcpId();
20
+ const second = createMcpId();
21
+ expect(first).toMatch(/^mcp-[0-9A-Za-z]+$/);
22
+ expect(second).not.toBe(first);
23
+ expect(() => assertValidServerId(first)).not.toThrow();
24
+ });
25
+ });
@@ -0,0 +1,10 @@
1
+ import { generateId } from "@assistant-ui/core";
2
+
3
+ /**
4
+ * Both forms are alphanumeric or hyphenated, so neither can contain the
5
+ * separators `assertValidServerId` reserves.
6
+ */
7
+ export const createMcpId = (): string =>
8
+ typeof crypto !== "undefined" && "randomUUID" in crypto
9
+ ? crypto.randomUUID()
10
+ : `mcp-${generateId()}`;
@@ -1,27 +1,9 @@
1
- const reportCallbackError = (name: string, error: unknown) => {
2
- console.error(`[react-mcp] ${name} callback threw an error`, error);
3
- };
1
+ import { invokeUserCallback } from "@assistant-ui/core/internal";
4
2
 
5
3
  export const invokeMcpCallback = <TArgs extends unknown[]>(
6
4
  name: string,
7
5
  callback: ((...args: TArgs) => void) | undefined,
8
6
  ...args: TArgs
9
- ) => {
10
- if (!callback) return;
11
-
12
- try {
13
- const result = callback(...args) as unknown;
14
- if (
15
- result !== null &&
16
- (typeof result === "object" || typeof result === "function") &&
17
- "then" in result &&
18
- typeof result.then === "function"
19
- ) {
20
- void Promise.resolve(result).catch((error) => {
21
- reportCallbackError(name, error);
22
- });
23
- }
24
- } catch (error) {
25
- reportCallbackError(name, error);
26
- }
7
+ ): void => {
8
+ void invokeUserCallback("react-mcp", name, callback, ...args);
27
9
  };