@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.
- package/dist/auth/createOAuthProvider.d.ts +7 -1
- package/dist/auth/createOAuthProvider.d.ts.map +1 -1
- package/dist/auth/createOAuthProvider.js +115 -31
- package/dist/auth/createOAuthProvider.js.map +1 -1
- package/dist/auth/types.d.ts +1 -0
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/hooks/useMcpOAuthCallback.d.ts.map +1 -1
- package/dist/hooks/useMcpOAuthCallback.js +5 -6
- package/dist/hooks/useMcpOAuthCallback.js.map +1 -1
- package/dist/primitives/server/McpServerIcon.js.map +1 -1
- package/dist/primitives/server/McpServerOAuthLink.js.map +1 -1
- package/dist/resources/McpManagerResource.d.ts.map +1 -1
- package/dist/resources/McpManagerResource.js +4 -2
- package/dist/resources/McpManagerResource.js.map +1 -1
- package/dist/resources/McpServerResource.d.ts +2 -1
- package/dist/resources/McpServerResource.d.ts.map +1 -1
- package/dist/resources/McpServerResource.js +107 -21
- package/dist/resources/McpServerResource.js.map +1 -1
- package/dist/resources/storage/McpLocalStorage.d.ts +7 -0
- package/dist/resources/storage/McpLocalStorage.d.ts.map +1 -1
- package/dist/resources/storage/McpLocalStorage.js +132 -37
- package/dist/resources/storage/McpLocalStorage.js.map +1 -1
- package/dist/resources/storage/McpMemoryStorage.d.ts.map +1 -1
- package/dist/resources/storage/McpMemoryStorage.js +9 -6
- package/dist/resources/storage/McpMemoryStorage.js.map +1 -1
- package/dist/resources/storage/types.d.ts +12 -0
- package/dist/resources/storage/types.d.ts.map +1 -1
- package/dist/utils/createMcpId.d.ts +9 -0
- package/dist/utils/createMcpId.d.ts.map +1 -0
- package/dist/utils/createMcpId.js +11 -0
- package/dist/utils/createMcpId.js.map +1 -0
- package/dist/utils/invokeMcpCallback.d.ts.map +1 -1
- package/dist/utils/invokeMcpCallback.js +2 -12
- package/dist/utils/invokeMcpCallback.js.map +1 -1
- package/package.json +8 -8
- package/src/auth/createOAuthProvider.test.ts +407 -2
- package/src/auth/createOAuthProvider.ts +171 -40
- package/src/auth/types.ts +1 -0
- package/src/hooks/useMcpOAuthCallback.test.ts +74 -1
- package/src/hooks/useMcpOAuthCallback.tsx +11 -8
- package/src/resources/McpManagerResource.test.ts +128 -0
- package/src/resources/McpManagerResource.ts +4 -5
- package/src/resources/McpServerResource.test.ts +420 -18
- package/src/resources/McpServerResource.ts +148 -27
- package/src/resources/storage/McpLocalStorage.test.ts +71 -1
- package/src/resources/storage/McpLocalStorage.ts +69 -47
- package/src/resources/storage/McpMemoryStorage.test.ts +99 -0
- package/src/resources/storage/McpMemoryStorage.ts +23 -17
- package/src/resources/storage/types.ts +12 -0
- package/src/utils/createMcpId.test.ts +25 -0
- package/src/utils/createMcpId.ts +10 -0
- 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
|
-
|
|
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
|
-
|
|
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
|
};
|