@assistant-ui/react-mcp 0.1.21 → 0.1.22
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.map +1 -1
- package/dist/auth/createOAuthProvider.js +7 -1
- package/dist/auth/createOAuthProvider.js.map +1 -1
- package/dist/primitives/addForm/McpAddFormRoot.d.ts.map +1 -1
- package/dist/primitives/addForm/McpAddFormRoot.js +14 -5
- package/dist/primitives/addForm/McpAddFormRoot.js.map +1 -1
- package/dist/resources/McpCustomServerPersistence.d.ts +17 -0
- package/dist/resources/McpCustomServerPersistence.d.ts.map +1 -0
- package/dist/resources/McpCustomServerPersistence.js +192 -0
- package/dist/resources/McpCustomServerPersistence.js.map +1 -0
- package/dist/resources/McpElicitationLifecycle.d.ts +12 -0
- package/dist/resources/McpElicitationLifecycle.d.ts.map +1 -0
- package/dist/resources/McpElicitationLifecycle.js +144 -0
- package/dist/resources/McpElicitationLifecycle.js.map +1 -0
- package/dist/resources/McpManagerResource.d.ts.map +1 -1
- package/dist/resources/McpManagerResource.js +28 -205
- package/dist/resources/McpManagerResource.js.map +1 -1
- package/dist/resources/McpServerResource.d.ts.map +1 -1
- package/dist/resources/McpServerResource.js +24 -101
- package/dist/resources/McpServerResource.js.map +1 -1
- package/dist/resources/storage/McpLocalStorage.d.ts +1 -4
- package/dist/resources/storage/McpLocalStorage.d.ts.map +1 -1
- package/dist/resources/storage/McpLocalStorage.js +1 -100
- package/dist/resources/storage/McpLocalStorage.js.map +1 -1
- package/dist/resources/storage/McpStoredDataNormalization.d.ts +5 -0
- package/dist/resources/storage/McpStoredDataNormalization.d.ts.map +1 -0
- package/dist/resources/storage/McpStoredDataNormalization.js +95 -0
- package/dist/resources/storage/McpStoredDataNormalization.js.map +1 -0
- package/dist/utils/serverUrl.d.ts +1 -0
- package/dist/utils/serverUrl.d.ts.map +1 -1
- package/dist/utils/serverUrl.js +15 -1
- package/dist/utils/serverUrl.js.map +1 -1
- package/package.json +10 -9
- package/src/auth/createOAuthProvider.test.ts +30 -1
- package/src/auth/createOAuthProvider.ts +12 -4
- package/src/primitives/addForm/McpAddFormRoot.test.tsx +66 -0
- package/src/primitives/addForm/McpAddFormRoot.tsx +11 -1
- package/src/resources/McpCustomServerPersistence.test.ts +56 -0
- package/src/resources/McpCustomServerPersistence.ts +233 -0
- package/src/resources/McpElicitationLifecycle.test.ts +83 -0
- package/src/resources/McpElicitationLifecycle.ts +156 -0
- package/src/resources/McpManagerResource.test.ts +36 -0
- package/src/resources/McpManagerResource.ts +25 -248
- package/src/resources/McpServerResource.test.ts +123 -10
- package/src/resources/McpServerResource.ts +29 -149
- package/src/resources/storage/McpLocalStorage.ts +9 -209
- package/src/resources/storage/McpStoredDataNormalization.test.ts +24 -0
- package/src/resources/storage/McpStoredDataNormalization.ts +201 -0
- package/src/utils/serverUrl.test.ts +30 -0
- package/src/utils/serverUrl.ts +26 -0
|
@@ -2,9 +2,39 @@ import { describe, expect, it } from "vitest";
|
|
|
2
2
|
import {
|
|
3
3
|
hasPersistedCredentials,
|
|
4
4
|
isAuthStateForServerUrl,
|
|
5
|
+
isSecureNetworkUrl,
|
|
5
6
|
normalizeMcpServerUrl,
|
|
6
7
|
} from "./serverUrl";
|
|
7
8
|
|
|
9
|
+
describe("isSecureNetworkUrl", () => {
|
|
10
|
+
it.each([
|
|
11
|
+
"https://mcp.example.com/mcp",
|
|
12
|
+
"http://localhost:3000/mcp",
|
|
13
|
+
"http://localhost.:3000/mcp",
|
|
14
|
+
"http://dev.localhost:3000/mcp",
|
|
15
|
+
"http://dev.localhost.:3000/mcp",
|
|
16
|
+
"http://127.0.0.1:3000/mcp",
|
|
17
|
+
"http://127.1.2.3/mcp",
|
|
18
|
+
"http://[::1]:3000/mcp",
|
|
19
|
+
"http://[::ffff:127.0.0.1]:3000/mcp",
|
|
20
|
+
"http://[::ffff:127.1.2.3]/mcp",
|
|
21
|
+
])("accepts %s", (url) => {
|
|
22
|
+
expect(isSecureNetworkUrl(url)).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it.each([
|
|
26
|
+
"http://mcp.example.com/mcp",
|
|
27
|
+
"http://192.168.1.20:3000/mcp",
|
|
28
|
+
"http://localhost.example.com/mcp",
|
|
29
|
+
"http://[::ffff:10.0.0.1]/mcp",
|
|
30
|
+
"http://[::2]/mcp",
|
|
31
|
+
"ws://localhost:3000/mcp",
|
|
32
|
+
"not a url",
|
|
33
|
+
])("rejects %s", (url) => {
|
|
34
|
+
expect(isSecureNetworkUrl(url)).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
8
38
|
describe("normalizeMcpServerUrl", () => {
|
|
9
39
|
it("normalizes host case and the default port", () => {
|
|
10
40
|
expect(normalizeMcpServerUrl("https://MCP.Example.com:443/mcp")).toBe(
|
package/src/utils/serverUrl.ts
CHANGED
|
@@ -3,6 +3,32 @@ import type { MCPPersistedAuthState } from "../auth/types";
|
|
|
3
3
|
export const normalizeMcpServerUrl = (serverUrl: string): string =>
|
|
4
4
|
new URL(serverUrl).toString();
|
|
5
5
|
|
|
6
|
+
const IPV4_LOOPBACK = /^127(?:\.\d{1,3}){3}$/;
|
|
7
|
+
const IPV4_MAPPED_LOOPBACK = /^\[::ffff:7f[0-9a-f]{2}:[0-9a-f]{1,4}\]$/;
|
|
8
|
+
|
|
9
|
+
const isLoopbackHostname = (hostname: string): boolean => {
|
|
10
|
+
const host = hostname.endsWith(".") ? hostname.slice(0, -1) : hostname;
|
|
11
|
+
return (
|
|
12
|
+
host === "localhost" ||
|
|
13
|
+
host.endsWith(".localhost") ||
|
|
14
|
+
IPV4_LOOPBACK.test(host) ||
|
|
15
|
+
host === "[::1]" ||
|
|
16
|
+
IPV4_MAPPED_LOOPBACK.test(host)
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const isSecureNetworkUrl = (serverUrl: string): boolean => {
|
|
21
|
+
try {
|
|
22
|
+
const url = new URL(serverUrl);
|
|
23
|
+
return (
|
|
24
|
+
url.protocol === "https:" ||
|
|
25
|
+
(url.protocol === "http:" && isLoopbackHostname(url.hostname))
|
|
26
|
+
);
|
|
27
|
+
} catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
6
32
|
export const isAuthStateForServerUrl = (
|
|
7
33
|
state: MCPPersistedAuthState | null,
|
|
8
34
|
serverUrl: string,
|