@assistant-ui/react-mcp 0.0.19 → 0.0.21
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/context/McpConnectorByIndexProvider.js +1 -1
- package/dist/context/McpConnectorByIndexProvider.js.map +1 -1
- package/dist/context/McpCustomServerByIndexProvider.js +1 -1
- package/dist/context/McpCustomServerByIndexProvider.js.map +1 -1
- package/dist/context/McpServerByIdProvider.js +1 -1
- package/dist/context/McpServerByIdProvider.js.map +1 -1
- package/dist/hooks/useMcpOAuthCallback.js +1 -1
- package/dist/hooks/useMcpOAuthCallback.js.map +1 -1
- package/dist/primitives/addForm/McpAddFormRoot.js +1 -1
- package/dist/primitives/addForm/McpAddFormRoot.js.map +1 -1
- package/dist/primitives/manager/McpManagerConnectors.js +1 -1
- package/dist/primitives/manager/McpManagerConnectors.js.map +1 -1
- package/dist/primitives/manager/McpManagerCustomServers.js +1 -1
- package/dist/primitives/manager/McpManagerCustomServers.js.map +1 -1
- package/dist/primitives/server/McpServerConnectButton.js +1 -1
- package/dist/primitives/server/McpServerConnectButton.js.map +1 -1
- package/dist/primitives/server/McpServerDisconnectButton.js +1 -1
- package/dist/primitives/server/McpServerDisconnectButton.js.map +1 -1
- package/dist/primitives/server/McpServerRemoveButton.js +1 -1
- package/dist/primitives/server/McpServerRemoveButton.js.map +1 -1
- package/dist/resources/McpManagerResource.js +1 -1
- package/dist/resources/McpManagerResource.js.map +1 -1
- package/dist/resources/storage/types.js +1 -0
- package/package.json +6 -6
- package/src/context/McpConnectorByIndexProvider.tsx +1 -1
- package/src/context/McpCustomServerByIndexProvider.tsx +1 -1
- package/src/context/McpServerByIdProvider.tsx +1 -1
- package/src/hooks/useMcpOAuthCallback.tsx +1 -1
- package/src/primitives/addForm/McpAddFormRoot.tsx +1 -1
- package/src/primitives/manager/McpManagerConnectors.tsx +1 -1
- package/src/primitives/manager/McpManagerCustomServers.tsx +1 -1
- package/src/primitives/server/McpServerConnectButton.tsx +1 -1
- package/src/primitives/server/McpServerDisconnectButton.tsx +1 -1
- package/src/primitives/server/McpServerRemoveButton.tsx +1 -1
- package/src/resources/McpManagerResource.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpConnectorByIndexProvider.js","names":["FC","PropsWithChildren","useAui","AuiProvider","Derived","McpConnectorByIndexProvider","index","t0","$","_c","children","t1","source","query","kind","get","parent","mcp","connector","t2","mcpServer","aui","t3"],"sources":["../../src/context/McpConnectorByIndexProvider.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from \"react\";\nimport { useAui, AuiProvider, Derived } from \"@assistant-ui/store\";\n\nexport const McpConnectorByIndexProvider: FC<\n PropsWithChildren<{ index: number }>\n> = ({ index, children }) => {\n const aui = useAui({\n mcpServer: Derived({\n source: \"mcp\",\n query: { kind: \"connector\", index },\n get: (parent) => parent.mcp
|
|
1
|
+
{"version":3,"file":"McpConnectorByIndexProvider.js","names":["FC","PropsWithChildren","useAui","AuiProvider","Derived","McpConnectorByIndexProvider","index","t0","$","_c","children","t1","source","query","kind","get","parent","mcp","connector","t2","mcpServer","aui","t3"],"sources":["../../src/context/McpConnectorByIndexProvider.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from \"react\";\nimport { useAui, AuiProvider, Derived } from \"@assistant-ui/store\";\n\nexport const McpConnectorByIndexProvider: FC<\n PropsWithChildren<{ index: number }>\n> = ({ index, children }) => {\n const aui = useAui({\n mcpServer: Derived({\n source: \"mcp\",\n query: { kind: \"connector\", index },\n get: (parent) => parent.mcp.connector({ index }),\n }),\n });\n\n return <AuiProvider value={aui}>{children}</AuiProvider>;\n};\n"],"mappings":";;;;AAGA,MAAaK,+BAETE,OAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAC,MAAA,EAAAH,OAAAI,aAAAH;CAAmB,IAAAI;CAAA,IAAAH,EAAA,OAAAF,OAAA;EAETK,KAAAP,QAAQ;GAAAQ,QACT;GAAKC,OACN;IAAAC,MAAQ;IAAWR;GAAQ;GAACS,MAC9BC,WAAYA,OAAMC,IAAIC,UAAW,EAAAZ,MAAQ,CAAC;EACjD,CAAC;EAACE,EAAA,KAAAF;EAAAE,EAAA,KAAAG;CAAA,OAAAA,KAAAH,EAAA;CAAA,IAAAW;CAAA,IAAAX,EAAA,OAAAG,IAAA;EALeQ,KAAA,EAAAC,WACNT,GAKb;EAACH,EAAA,KAAAG;EAAAH,EAAA,KAAAW;CAAA,OAAAA,KAAAX,EAAA;CAND,MAAAa,MAAYnB,OAAOiB,EAMlB;CAAE,IAAAG;CAAA,IAAAd,EAAA,OAAAa,OAAAb,EAAA,OAAAE,UAAA;EAEIY,KAAA,oBAAC,aAAD;GAAoBD,OAAAA;GAAMX;EAAd,CAAA;EAAqCF,EAAA,KAAAa;EAAAb,EAAA,KAAAE;EAAAF,EAAA,KAAAc;CAAA,OAAAA,KAAAd,EAAA;CAAA,OAAjDc;AAAiD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpCustomServerByIndexProvider.js","names":["FC","PropsWithChildren","useAui","AuiProvider","Derived","McpCustomServerByIndexProvider","index","t0","$","_c","children","t1","source","query","kind","get","parent","mcp","customServer","t2","mcpServer","aui","t3"],"sources":["../../src/context/McpCustomServerByIndexProvider.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from \"react\";\nimport { useAui, AuiProvider, Derived } from \"@assistant-ui/store\";\n\nexport const McpCustomServerByIndexProvider: FC<\n PropsWithChildren<{ index: number }>\n> = ({ index, children }) => {\n const aui = useAui({\n mcpServer: Derived({\n source: \"mcp\",\n query: { kind: \"custom\", index },\n get: (parent) => parent.mcp
|
|
1
|
+
{"version":3,"file":"McpCustomServerByIndexProvider.js","names":["FC","PropsWithChildren","useAui","AuiProvider","Derived","McpCustomServerByIndexProvider","index","t0","$","_c","children","t1","source","query","kind","get","parent","mcp","customServer","t2","mcpServer","aui","t3"],"sources":["../../src/context/McpCustomServerByIndexProvider.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from \"react\";\nimport { useAui, AuiProvider, Derived } from \"@assistant-ui/store\";\n\nexport const McpCustomServerByIndexProvider: FC<\n PropsWithChildren<{ index: number }>\n> = ({ index, children }) => {\n const aui = useAui({\n mcpServer: Derived({\n source: \"mcp\",\n query: { kind: \"custom\", index },\n get: (parent) => parent.mcp.customServer({ index }),\n }),\n });\n\n return <AuiProvider value={aui}>{children}</AuiProvider>;\n};\n"],"mappings":";;;;AAGA,MAAaK,kCAETE,OAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAC,MAAA,EAAAH,OAAAI,aAAAH;CAAmB,IAAAI;CAAA,IAAAH,EAAA,OAAAF,OAAA;EAETK,KAAAP,QAAQ;GAAAQ,QACT;GAAKC,OACN;IAAAC,MAAQ;IAAQR;GAAQ;GAACS,MAC3BC,WAAYA,OAAMC,IAAIC,aAAc,EAAAZ,MAAQ,CAAC;EACpD,CAAC;EAACE,EAAA,KAAAF;EAAAE,EAAA,KAAAG;CAAA,OAAAA,KAAAH,EAAA;CAAA,IAAAW;CAAA,IAAAX,EAAA,OAAAG,IAAA;EALeQ,KAAA,EAAAC,WACNT,GAKb;EAACH,EAAA,KAAAG;EAAAH,EAAA,KAAAW;CAAA,OAAAA,KAAAX,EAAA;CAND,MAAAa,MAAYnB,OAAOiB,EAMlB;CAAE,IAAAG;CAAA,IAAAd,EAAA,OAAAa,OAAAb,EAAA,OAAAE,UAAA;EAEIY,KAAA,oBAAC,aAAD;GAAoBD,OAAAA;GAAMX;EAAd,CAAA;EAAqCF,EAAA,KAAAa;EAAAb,EAAA,KAAAE;EAAAF,EAAA,KAAAc;CAAA,OAAAA,KAAAd,EAAA;CAAA,OAAjDc;AAAiD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpServerByIdProvider.js","names":["FC","PropsWithChildren","useAui","AuiProvider","Derived","McpServerByIdProvider","id","t0","$","_c","children","t1","source","query","get","parent","mcp","server","t2","mcpServer","aui","t3"],"sources":["../../src/context/McpServerByIdProvider.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from \"react\";\nimport { useAui, AuiProvider, Derived } from \"@assistant-ui/store\";\n\nexport const McpServerByIdProvider: FC<PropsWithChildren<{ id: string }>> = ({\n id,\n children,\n}) => {\n const aui = useAui({\n mcpServer: Derived({\n source: \"mcp\",\n query: { id },\n get: (parent) => parent.mcp
|
|
1
|
+
{"version":3,"file":"McpServerByIdProvider.js","names":["FC","PropsWithChildren","useAui","AuiProvider","Derived","McpServerByIdProvider","id","t0","$","_c","children","t1","source","query","get","parent","mcp","server","t2","mcpServer","aui","t3"],"sources":["../../src/context/McpServerByIdProvider.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from \"react\";\nimport { useAui, AuiProvider, Derived } from \"@assistant-ui/store\";\n\nexport const McpServerByIdProvider: FC<PropsWithChildren<{ id: string }>> = ({\n id,\n children,\n}) => {\n const aui = useAui({\n mcpServer: Derived({\n source: \"mcp\",\n query: { id },\n get: (parent) => parent.mcp.server({ id }),\n }),\n });\n\n return <AuiProvider value={aui}>{children}</AuiProvider>;\n};\n"],"mappings":";;;;AAGA,MAAaK,yBAA+DE,OAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAC,MAAA,EAAAH,IAAAI,aAAAH;CAG5E,IAAAI;CAAA,IAAAH,EAAA,OAAAF,IAAA;EAEcK,KAAAP,QAAQ;GAAAQ,QACT;GAAKC,OACN,EAAAP,GAAK;GAACQ,MACRC,WAAYA,OAAMC,IAAIC,OAAQ,EAAAX,GAAK,CAAC;EAC3C,CAAC;EAACE,EAAA,KAAAF;EAAAE,EAAA,KAAAG;CAAA,OAAAA,KAAAH,EAAA;CAAA,IAAAU;CAAA,IAAAV,EAAA,OAAAG,IAAA;EALeO,KAAA,EAAAC,WACNR,GAKb;EAACH,EAAA,KAAAG;EAAAH,EAAA,KAAAU;CAAA,OAAAA,KAAAV,EAAA;CAND,MAAAY,MAAYlB,OAAOgB,EAMlB;CAAE,IAAAG;CAAA,IAAAb,EAAA,OAAAY,OAAAZ,EAAA,OAAAE,UAAA;EAEIW,KAAA,oBAAC,aAAD;GAAoBD,OAAAA;GAAMV;EAAd,CAAA;EAAqCF,EAAA,KAAAY;EAAAZ,EAAA,KAAAE;EAAAF,EAAA,KAAAa;CAAA,OAAAA,KAAAb,EAAA;CAAA,OAAjDa;AAAiD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMcpOAuthCallback.js","names":["FC","ReactNode","useEffect","useRef","useState","useAui","decodeServerIdFromState","createMcpOAuthCallbackError","err","serverId","Error","message","String","cause","UseMcpOAuthCallbackOptions","url","onComplete","onError","UseMcpOAuthCallbackResult","status","error","useMcpOAuthCallback","opts","aui","result","setResult","startedRef","optsRef","current","window","location","href","parsed","URL","state","searchParams","get","mcp","server","id","completeAuth","e","McpOAuthCallback","children","t0","$","_c","t1","t2"],"sources":["../../src/hooks/useMcpOAuthCallback.tsx"],"sourcesContent":["import { type FC, type ReactNode, useEffect, useRef, useState } from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { decodeServerIdFromState } from \"../auth/createOAuthProvider\";\n\nexport const createMcpOAuthCallbackError = (\n err: unknown,\n serverId: string | null,\n): Error => {\n const message = err instanceof Error ? err.message : String(err);\n if (serverId) {\n return new Error(\n `MCP OAuth callback for server \"${serverId}\" failed: ${message}`,\n { cause: err },\n );\n }\n return new Error(`MCP OAuth callback failed: ${message}`, { cause: err });\n};\n\nexport type UseMcpOAuthCallbackOptions = {\n /** Defaults to `window.location.href`. */\n url?: string;\n onComplete?: (serverId: string) => void;\n onError?: (err: Error) => void;\n};\n\nexport type UseMcpOAuthCallbackResult = {\n status: \"idle\" | \"running\" | \"done\" | \"error\";\n serverId: string | null;\n error: Error | null;\n};\n\nexport function useMcpOAuthCallback(\n opts: UseMcpOAuthCallbackOptions = {},\n): UseMcpOAuthCallbackResult {\n const aui = useAui();\n const [result, setResult] = useState<UseMcpOAuthCallbackResult>({\n status: \"idle\",\n serverId: null,\n error: null,\n });\n // Guard against React 18 Strict Mode's mount-unmount-remount: the effect\n // body must not run completeAuth twice for the same URL, otherwise the\n // single-use OAuth code is double-redeemed and the second attempt 4xxs.\n const startedRef = useRef<string | null>(null);\n const optsRef = useRef(opts);\n optsRef.current = opts;\n\n useEffect(() => {\n const url =\n opts.url ?? (typeof window !== \"undefined\" ? window.location.href : null);\n if (!url) return;\n if (startedRef.current === url) return;\n startedRef.current = url;\n\n (async () => {\n let serverId: string | null = null;\n try {\n const parsed = new URL(url);\n const state = parsed.searchParams.get(\"state\");\n if (state) serverId = decodeServerIdFromState(state);\n const error = parsed.searchParams.get(\"error\");\n if (error) {\n throw new Error(\n parsed.searchParams.get(\"error_description\") ?? error,\n );\n }\n if (!state) throw new Error('missing \"state\" parameter');\n if (!serverId) {\n throw new Error(\"state was not created by assistant-ui MCP\");\n }\n setResult({ status: \"running\", serverId, error: null });\n await aui.mcp
|
|
1
|
+
{"version":3,"file":"useMcpOAuthCallback.js","names":["FC","ReactNode","useEffect","useRef","useState","useAui","decodeServerIdFromState","createMcpOAuthCallbackError","err","serverId","Error","message","String","cause","UseMcpOAuthCallbackOptions","url","onComplete","onError","UseMcpOAuthCallbackResult","status","error","useMcpOAuthCallback","opts","aui","result","setResult","startedRef","optsRef","current","window","location","href","parsed","URL","state","searchParams","get","mcp","server","id","completeAuth","e","McpOAuthCallback","children","t0","$","_c","t1","t2"],"sources":["../../src/hooks/useMcpOAuthCallback.tsx"],"sourcesContent":["import { type FC, type ReactNode, useEffect, useRef, useState } from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { decodeServerIdFromState } from \"../auth/createOAuthProvider\";\n\nexport const createMcpOAuthCallbackError = (\n err: unknown,\n serverId: string | null,\n): Error => {\n const message = err instanceof Error ? err.message : String(err);\n if (serverId) {\n return new Error(\n `MCP OAuth callback for server \"${serverId}\" failed: ${message}`,\n { cause: err },\n );\n }\n return new Error(`MCP OAuth callback failed: ${message}`, { cause: err });\n};\n\nexport type UseMcpOAuthCallbackOptions = {\n /** Defaults to `window.location.href`. */\n url?: string;\n onComplete?: (serverId: string) => void;\n onError?: (err: Error) => void;\n};\n\nexport type UseMcpOAuthCallbackResult = {\n status: \"idle\" | \"running\" | \"done\" | \"error\";\n serverId: string | null;\n error: Error | null;\n};\n\nexport function useMcpOAuthCallback(\n opts: UseMcpOAuthCallbackOptions = {},\n): UseMcpOAuthCallbackResult {\n const aui = useAui();\n const [result, setResult] = useState<UseMcpOAuthCallbackResult>({\n status: \"idle\",\n serverId: null,\n error: null,\n });\n // Guard against React 18 Strict Mode's mount-unmount-remount: the effect\n // body must not run completeAuth twice for the same URL, otherwise the\n // single-use OAuth code is double-redeemed and the second attempt 4xxs.\n const startedRef = useRef<string | null>(null);\n const optsRef = useRef(opts);\n optsRef.current = opts;\n\n useEffect(() => {\n const url =\n opts.url ?? (typeof window !== \"undefined\" ? window.location.href : null);\n if (!url) return;\n if (startedRef.current === url) return;\n startedRef.current = url;\n\n (async () => {\n let serverId: string | null = null;\n try {\n const parsed = new URL(url);\n const state = parsed.searchParams.get(\"state\");\n if (state) serverId = decodeServerIdFromState(state);\n const error = parsed.searchParams.get(\"error\");\n if (error) {\n throw new Error(\n parsed.searchParams.get(\"error_description\") ?? error,\n );\n }\n if (!state) throw new Error('missing \"state\" parameter');\n if (!serverId) {\n throw new Error(\"state was not created by assistant-ui MCP\");\n }\n setResult({ status: \"running\", serverId, error: null });\n await aui.mcp.server({ id: serverId }).completeAuth(url);\n setResult({ status: \"done\", serverId, error: null });\n optsRef.current.onComplete?.(serverId);\n } catch (err) {\n const e = createMcpOAuthCallbackError(err, serverId);\n setResult({ status: \"error\", serverId, error: e });\n optsRef.current.onError?.(e);\n }\n })();\n }, [aui, opts.url]);\n\n return result;\n}\n\nexport const McpOAuthCallback: FC<\n UseMcpOAuthCallbackOptions & {\n children?: (result: UseMcpOAuthCallbackResult) => ReactNode;\n }\n> = ({ children, ...opts }) => {\n const result = useMcpOAuthC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|
|
|
85
85
|
error: null
|
|
86
86
|
}));
|
|
87
87
|
try {
|
|
88
|
-
const id = await aui.mcp
|
|
88
|
+
const id = await aui.mcp.addCustomServer({
|
|
89
89
|
name: state.name.trim(),
|
|
90
90
|
url: urlResult.url,
|
|
91
91
|
auth: buildAuth()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpAddFormRoot.js","names":["ComponentPropsWithoutRef","ComponentRef","FormEventHandler","forwardRef","useCallback","useMemo","useState","Primitive","useAui","AddFormContext","AddFormState","MCPAuthConfig","INITIAL","name","url","authType","bearerToken","scopes","submitting","error","validateUrl","raw","trimmed","trim","parsed","URL","protocol","McpAddFormPrimitiveRoot","Element","form","Props","Omit","onSubmitted","id","onCancel","props","ref","aui","state","setState","setField","key","K","value","prev","reset","buildAuth","type","token","undefined","scopeList","split","map","s","filter","Boolean","length","submit","p","urlResult","mcp","addCustomServer","auth","err","Error","message","String","cancel","onFormSubmit","HTMLFormElement","e","preventDefault","displayName"],"sources":["../../../src/primitives/addForm/McpAddFormRoot.tsx"],"sourcesContent":["import {\n type ComponentPropsWithoutRef,\n type ComponentRef,\n type FormEventHandler,\n forwardRef,\n useCallback,\n useMemo,\n useState,\n} from \"react\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { AddFormContext, type AddFormState } from \"./context\";\nimport type { MCPAuthConfig } from \"../../mcp-scope\";\n\nconst INITIAL: AddFormState = {\n name: \"\",\n url: \"\",\n authType: \"oauth\",\n bearerToken: \"\",\n scopes: \"\",\n submitting: false,\n error: null,\n};\n\nfunction validateUrl(raw: string): { url: string } | { error: string } {\n const trimmed = raw.trim();\n if (!trimmed) return { error: \"URL is required\" };\n let parsed: URL;\n try {\n parsed = new URL(trimmed);\n } catch {\n return { error: \"Invalid URL\" };\n }\n if (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") {\n return { error: \"URL must be http(s)\" };\n }\n return { url: trimmed };\n}\n\nexport namespace McpAddFormPrimitiveRoot {\n export type Element = ComponentRef<typeof Primitive.form>;\n export type Props = Omit<\n ComponentPropsWithoutRef<typeof Primitive.form>,\n \"onSubmit\"\n > & {\n onSubmitted?: (id: string) => void;\n onCancel?: () => void;\n };\n}\n\nexport const McpAddFormPrimitiveRoot = forwardRef<\n McpAddFormPrimitiveRoot.Element,\n McpAddFormPrimitiveRoot.Props\n>(({ onSubmitted, onCancel, ...props }, ref) => {\n const aui = useAui();\n const [state, setState] = useState<AddFormState>(INITIAL);\n\n const setField = useCallback(\n <K extends keyof AddFormState>(key: K, value: AddFormState[K]) => {\n setState((prev) => ({ ...prev, [key]: value }));\n },\n [],\n );\n\n const reset = useCallback(() => setState(INITIAL), []);\n\n const buildAuth = useCallback((): MCPAuthConfig => {\n switch (state.authType) {\n case \"none\":\n return { type: \"none\" };\n case \"bearer\":\n return { type: \"bearer\", token: state.bearerToken || undefined };\n case \"oauth\": {\n const scopeList = state.scopes\n .split(/[\\s,]+/)\n .map((s) => s.trim())\n .filter(Boolean);\n return {\n type: \"oauth\",\n scopes: scopeList.length > 0 ? scopeList : undefined,\n };\n }\n }\n }, [state.authType, state.bearerToken, state.scopes]);\n\n const submit = useCallback(async () => {\n if (state.submitting) return;\n if (!state.name.trim()) {\n setState((p) => ({ ...p, error: \"Name is required\" }));\n return;\n }\n if (state.authType === \"bearer\" && !state.bearerToken.trim()) {\n setState((p) => ({ ...p, error: \"Bearer token is required\" }));\n return;\n }\n const urlResult = validateUrl(state.url);\n if (\"error\" in urlResult) {\n setState((p) => ({ ...p, error: urlResult.error }));\n return;\n }\n setState((p) => ({ ...p, submitting: true, error: null }));\n try {\n const id = await aui.mcp
|
|
1
|
+
{"version":3,"file":"McpAddFormRoot.js","names":["ComponentPropsWithoutRef","ComponentRef","FormEventHandler","forwardRef","useCallback","useMemo","useState","Primitive","useAui","AddFormContext","AddFormState","MCPAuthConfig","INITIAL","name","url","authType","bearerToken","scopes","submitting","error","validateUrl","raw","trimmed","trim","parsed","URL","protocol","McpAddFormPrimitiveRoot","Element","form","Props","Omit","onSubmitted","id","onCancel","props","ref","aui","state","setState","setField","key","K","value","prev","reset","buildAuth","type","token","undefined","scopeList","split","map","s","filter","Boolean","length","submit","p","urlResult","mcp","addCustomServer","auth","err","Error","message","String","cancel","onFormSubmit","HTMLFormElement","e","preventDefault","displayName"],"sources":["../../../src/primitives/addForm/McpAddFormRoot.tsx"],"sourcesContent":["import {\n type ComponentPropsWithoutRef,\n type ComponentRef,\n type FormEventHandler,\n forwardRef,\n useCallback,\n useMemo,\n useState,\n} from \"react\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { AddFormContext, type AddFormState } from \"./context\";\nimport type { MCPAuthConfig } from \"../../mcp-scope\";\n\nconst INITIAL: AddFormState = {\n name: \"\",\n url: \"\",\n authType: \"oauth\",\n bearerToken: \"\",\n scopes: \"\",\n submitting: false,\n error: null,\n};\n\nfunction validateUrl(raw: string): { url: string } | { error: string } {\n const trimmed = raw.trim();\n if (!trimmed) return { error: \"URL is required\" };\n let parsed: URL;\n try {\n parsed = new URL(trimmed);\n } catch {\n return { error: \"Invalid URL\" };\n }\n if (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") {\n return { error: \"URL must be http(s)\" };\n }\n return { url: trimmed };\n}\n\nexport namespace McpAddFormPrimitiveRoot {\n export type Element = ComponentRef<typeof Primitive.form>;\n export type Props = Omit<\n ComponentPropsWithoutRef<typeof Primitive.form>,\n \"onSubmit\"\n > & {\n onSubmitted?: (id: string) => void;\n onCancel?: () => void;\n };\n}\n\nexport const McpAddFormPrimitiveRoot = forwardRef<\n McpAddFormPrimitiveRoot.Element,\n McpAddFormPrimitiveRoot.Props\n>(({ onSubmitted, onCancel, ...props }, ref) => {\n const aui = useAui();\n const [state, setState] = useState<AddFormState>(INITIAL);\n\n const setField = useCallback(\n <K extends keyof AddFormState>(key: K, value: AddFormState[K]) => {\n setState((prev) => ({ ...prev, [key]: value }));\n },\n [],\n );\n\n const reset = useCallback(() => setState(INITIAL), []);\n\n const buildAuth = useCallback((): MCPAuthConfig => {\n switch (state.authType) {\n case \"none\":\n return { type: \"none\" };\n case \"bearer\":\n return { type: \"bearer\", token: state.bearerToken || undefined };\n case \"oauth\": {\n const scopeList = state.scopes\n .split(/[\\s,]+/)\n .map((s) => s.trim())\n .filter(Boolean);\n return {\n type: \"oauth\",\n scopes: scopeList.length > 0 ? scopeList : undefined,\n };\n }\n }\n }, [state.authType, state.bearerToken, state.scopes]);\n\n const submit = useCallback(async () => {\n if (state.submitting) return;\n if (!state.name.trim()) {\n setState((p) => ({ ...p, error: \"Name is required\" }));\n return;\n }\n if (state.authType === \"bearer\" && !state.bearerToken.trim()) {\n setState((p) => ({ ...p, error: \"Bearer token is required\" }));\n return;\n }\n const urlResult = validateUrl(state.url);\n if (\"error\" in urlResult) {\n setState((p) => ({ ...p, error: urlResult.error }));\n return;\n }\n setState((p) => ({ ...p, submitting: true, error: null }));\n try {\n const id = await aui.mcp.addCustomServer({\n name: state.name.trim(),\n url: urlResult.url,\n auth: buildAuth(),\n });\n setState(INITIAL);\n onSubmitted?.(id);\n } catch (err) {\n setState((p) => ({\n ...p,\n submitting: false,\n error: err instanceof Error ? err.message : String(err),\n }));\n }\n }, [aui, buildAuth, onSubmitted, state]);\n\n const cancel = useCallback(() => {\n setState(INITIAL);\n onCancel?.();\n }, [onCancel]);\n\n const value = useMemo(\n () => ({ state, setField, reset, submit, cancel }),\n [state, setField, reset, submit, cancel],\n );\n\n const onFormSubmit: FormEventHandler<HTMLFormElement> = (e) => {\n e.preventDefault();\n void submit();\n };\n\n return (\n <AddFormContext.Provider value={value}>\n <Primitive.form {...props} ref={ref} onSubmit={onFormSubmit} />\n </AddFormContext.Provider>\n );\n});\n\nMcpAddFormPrimitiveRoot.displayName = \"McpAddFormPrimitive.Root\";\n"],"mappings":";;;;;;AAcA,MAAMY,UAAwB;CAC5BC,MAAM;CACNC,KAAK;CACLC,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ACjB,OAAY;CACd;CAEA,OACE,oBAAC,eAAe,UAAhB;EAAyB,OAAO5B;EAC9B,UAAA,oBAAC,UAAU,MAAX;GAAgB,GAAIR;GAAYC;GAAK,UAAUgC;EAAa,CAAA;CACrC,CAAA;AAE7B,CAAC;AAEDzC,wBAAwB6C,cAAc"}
|
|
@@ -12,7 +12,7 @@ const McpManagerPrimitiveConnectorsInner = ({ children }) => {
|
|
|
12
12
|
return ids.map((id, index) => /* @__PURE__ */ jsx(McpConnectorByIndexProvider, {
|
|
13
13
|
index,
|
|
14
14
|
children: /* @__PURE__ */ jsx(RenderChildrenWithAccessor, {
|
|
15
|
-
getItemState: (aui) => aui.mcp
|
|
15
|
+
getItemState: (aui) => aui.mcp.connector({ index }).getState(),
|
|
16
16
|
children: (getItem) => children({ get server() {
|
|
17
17
|
return getItem();
|
|
18
18
|
} })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpManagerConnectors.js","names":["FC","ReactNode","memo","useMemo","RenderChildrenWithAccessor","useAuiState","McpConnectorByIndexProvider","MCPServerState","SEP","McpManagerPrimitiveConnectors","Props","children","value","server","McpManagerPrimitiveConnectorsInner","idsJoined","s","mcp","connectors","map","c","id","join","ids","split","length","index","aui","connector","getState","getItem","prev","next","displayName"],"sources":["../../../src/primitives/manager/McpManagerConnectors.tsx"],"sourcesContent":["import { type FC, type ReactNode, memo, useMemo } from \"react\";\nimport { RenderChildrenWithAccessor, useAuiState } from \"@assistant-ui/store\";\nimport { McpConnectorByIndexProvider } from \"../../context/McpConnectorByIndexProvider\";\nimport type { MCPServerState } from \"../../mcp-scope\";\n\n// ASCII Unit Separator — never appears in MCP connector ids (uuids, urls,\n// app-provided strings).\nconst SEP = \"\\x1f\";\n\nexport namespace McpManagerPrimitiveConnectors {\n export type Props = {\n /**\n * Render function called once per connector. Receives a lazy `server`\n * accessor — reading it inside the render function subscribes to that\n * connector's state.\n */\n children: (value: { server: MCPServerState }) => ReactNode;\n };\n}\n\nconst McpManagerPrimitiveConnectorsInner: FC<{\n children: (value: { server: MCPServerState }) => ReactNode;\n}> = ({ children }) => {\n // Subscribe to the connector id list, joined to a primitive so identity\n // is stable when the list hasn't changed. Re-renders on add/remove/reorder\n // but not on per-item state changes.\n const idsJoined = useAuiState((s) =>\n s.mcp.connectors.map((c) => c.id).join(SEP),\n );\n const ids = useMemo(\n () => (idsJoined ? idsJoined.split(SEP) : []),\n [idsJoined],\n );\n\n return useMemo(() => {\n if (ids.length === 0) return null;\n return ids.map((id, index) => (\n <McpConnectorByIndexProvider key={id} index={index}>\n <RenderChildrenWithAccessor\n getItemState={(aui) => aui.mcp
|
|
1
|
+
{"version":3,"file":"McpManagerConnectors.js","names":["FC","ReactNode","memo","useMemo","RenderChildrenWithAccessor","useAuiState","McpConnectorByIndexProvider","MCPServerState","SEP","McpManagerPrimitiveConnectors","Props","children","value","server","McpManagerPrimitiveConnectorsInner","idsJoined","s","mcp","connectors","map","c","id","join","ids","split","length","index","aui","connector","getState","getItem","prev","next","displayName"],"sources":["../../../src/primitives/manager/McpManagerConnectors.tsx"],"sourcesContent":["import { type FC, type ReactNode, memo, useMemo } from \"react\";\nimport { RenderChildrenWithAccessor, useAuiState } from \"@assistant-ui/store\";\nimport { McpConnectorByIndexProvider } from \"../../context/McpConnectorByIndexProvider\";\nimport type { MCPServerState } from \"../../mcp-scope\";\n\n// ASCII Unit Separator — never appears in MCP connector ids (uuids, urls,\n// app-provided strings).\nconst SEP = \"\\x1f\";\n\nexport namespace McpManagerPrimitiveConnectors {\n export type Props = {\n /**\n * Render function called once per connector. Receives a lazy `server`\n * accessor — reading it inside the render function subscribes to that\n * connector's state.\n */\n children: (value: { server: MCPServerState }) => ReactNode;\n };\n}\n\nconst McpManagerPrimitiveConnectorsInner: FC<{\n children: (value: { server: MCPServerState }) => ReactNode;\n}> = ({ children }) => {\n // Subscribe to the connector id list, joined to a primitive so identity\n // is stable when the list hasn't changed. Re-renders on add/remove/reorder\n // but not on per-item state changes.\n const idsJoined = useAuiState((s) =>\n s.mcp.connectors.map((c) => c.id).join(SEP),\n );\n const ids = useMemo(\n () => (idsJoined ? idsJoined.split(SEP) : []),\n [idsJoined],\n );\n\n return useMemo(() => {\n if (ids.length === 0) return null;\n return ids.map((id, index) => (\n <McpConnectorByIndexProvider key={id} index={index}>\n <RenderChildrenWithAccessor\n getItemState={(aui) => aui.mcp.connector({ index }).getState()}\n >\n {(getItem) =>\n children({\n get server() {\n return getItem();\n },\n })\n }\n </RenderChildrenWithAccessor>\n </McpConnectorByIndexProvider>\n ));\n }, [ids, children]);\n};\n\n/**\n * Renders all connectors declared on `McpManagerResource`.\n *\n * @example\n * ```tsx\n * <McpManagerPrimitive.Connectors>\n * {({ server }) => (\n * <McpServerPrimitive.Root>\n * <McpServerPrimitive.Name />\n * {server.connectionState === \"error\" && <p>{server.lastError?.message}</p>}\n * </McpServerPrimitive.Root>\n * )}\n * </McpManagerPrimitive.Connectors>\n * ```\n */\nexport const McpManagerPrimitiveConnectors: FC<McpManagerPrimitiveConnectors.Props> =\n memo(\n McpManagerPrimitiveConnectorsInner,\n (prev, next) => prev.children === next.children,\n );\n\nMcpManagerPrimitiveConnectors.displayName = \"McpManagerPrimitive.Connectors\";\n"],"mappings":";;;;;AAOA,MAAMQ,MAAM;AAaZ,MAAMM,sCAEA,EAAEH,eAAe;CAIrB,MAAMI,YAAYV,aAAaW,MAC7BA,EAAEC,IAAIC,WAAWC,KAAKC,MAAMA,EAAEC,EAAE,CAAC,CAACC,KAAKd,GAAG,CAC5C;CACA,MAAMe,MAAMpB,cACHY,YAAYA,UAAUS,MAAMhB,GAAG,IAAI,CAAA,GAC1C,CAACO,SAAS,CACZ;CAEA,OAAOZ,cAAc;EACnB,IAAIoB,IAAIE,WAAW,GAAG,OAAO;EAC7B,OAAOF,IAAIJ,KAAKE,IAAIK,UAClB,oBAAC,6BAAD;GAA6CA;GAC3C,UAAA,oBAAC,4BAAD;IACE,eAAeC,QAAQA,IAAIV,IAAIW,UAAU,EAAEF,MAAM,CAAC,CAAC,CAACG,SAAS;IAE3DC,WAAAA,YACAnB,SAAS,EACP,IAAIE,SAAS;KACX,OAAOiB,QAAQ;IACjB,EACF,CAAC;GAEuB,CAAA;EACD,GAZKT,EAYL,CAC9B;CACH,GAAG,CAACE,KAAKZ,QAAQ,CAAC;AACpB;;;;;;;;;;;;;;;;AAiBA,MAAaF,gCACXP,KACEY,qCACCiB,MAAMC,SAASD,KAAKpB,aAAaqB,KAAKrB,QACzC;AAEFF,8BAA8BwB,cAAc"}
|
|
@@ -12,7 +12,7 @@ const McpManagerPrimitiveCustomServersInner = ({ children }) => {
|
|
|
12
12
|
return ids.map((id, index) => /* @__PURE__ */ jsx(McpCustomServerByIndexProvider, {
|
|
13
13
|
index,
|
|
14
14
|
children: /* @__PURE__ */ jsx(RenderChildrenWithAccessor, {
|
|
15
|
-
getItemState: (aui) => aui.mcp
|
|
15
|
+
getItemState: (aui) => aui.mcp.customServer({ index }).getState(),
|
|
16
16
|
children: (getItem) => children({ get server() {
|
|
17
17
|
return getItem();
|
|
18
18
|
} })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpManagerCustomServers.js","names":["FC","ReactNode","memo","useMemo","RenderChildrenWithAccessor","useAuiState","McpCustomServerByIndexProvider","MCPServerState","SEP","McpManagerPrimitiveCustomServers","Props","children","value","server","McpManagerPrimitiveCustomServersInner","idsJoined","s","mcp","customServers","map","c","id","join","ids","split","length","index","aui","customServer","getState","getItem","prev","next","displayName"],"sources":["../../../src/primitives/manager/McpManagerCustomServers.tsx"],"sourcesContent":["import { type FC, type ReactNode, memo, useMemo } from \"react\";\nimport { RenderChildrenWithAccessor, useAuiState } from \"@assistant-ui/store\";\nimport { McpCustomServerByIndexProvider } from \"../../context/McpCustomServerByIndexProvider\";\nimport type { MCPServerState } from \"../../mcp-scope\";\n\nconst SEP = \"\\x1f\";\n\nexport namespace McpManagerPrimitiveCustomServers {\n export type Props = {\n /**\n * Render function called once per custom server. Receives a lazy\n * `server` accessor — reading it inside the render function subscribes\n * to that server's state.\n */\n children: (value: { server: MCPServerState }) => ReactNode;\n };\n}\n\nconst McpManagerPrimitiveCustomServersInner: FC<{\n children: (value: { server: MCPServerState }) => ReactNode;\n}> = ({ children }) => {\n const idsJoined = useAuiState((s) =>\n s.mcp.customServers.map((c) => c.id).join(SEP),\n );\n const ids = useMemo(\n () => (idsJoined ? idsJoined.split(SEP) : []),\n [idsJoined],\n );\n\n return useMemo(() => {\n if (ids.length === 0) return null;\n return ids.map((id, index) => (\n <McpCustomServerByIndexProvider key={id} index={index}>\n <RenderChildrenWithAccessor\n getItemState={(aui) => aui.mcp
|
|
1
|
+
{"version":3,"file":"McpManagerCustomServers.js","names":["FC","ReactNode","memo","useMemo","RenderChildrenWithAccessor","useAuiState","McpCustomServerByIndexProvider","MCPServerState","SEP","McpManagerPrimitiveCustomServers","Props","children","value","server","McpManagerPrimitiveCustomServersInner","idsJoined","s","mcp","customServers","map","c","id","join","ids","split","length","index","aui","customServer","getState","getItem","prev","next","displayName"],"sources":["../../../src/primitives/manager/McpManagerCustomServers.tsx"],"sourcesContent":["import { type FC, type ReactNode, memo, useMemo } from \"react\";\nimport { RenderChildrenWithAccessor, useAuiState } from \"@assistant-ui/store\";\nimport { McpCustomServerByIndexProvider } from \"../../context/McpCustomServerByIndexProvider\";\nimport type { MCPServerState } from \"../../mcp-scope\";\n\nconst SEP = \"\\x1f\";\n\nexport namespace McpManagerPrimitiveCustomServers {\n export type Props = {\n /**\n * Render function called once per custom server. Receives a lazy\n * `server` accessor — reading it inside the render function subscribes\n * to that server's state.\n */\n children: (value: { server: MCPServerState }) => ReactNode;\n };\n}\n\nconst McpManagerPrimitiveCustomServersInner: FC<{\n children: (value: { server: MCPServerState }) => ReactNode;\n}> = ({ children }) => {\n const idsJoined = useAuiState((s) =>\n s.mcp.customServers.map((c) => c.id).join(SEP),\n );\n const ids = useMemo(\n () => (idsJoined ? idsJoined.split(SEP) : []),\n [idsJoined],\n );\n\n return useMemo(() => {\n if (ids.length === 0) return null;\n return ids.map((id, index) => (\n <McpCustomServerByIndexProvider key={id} index={index}>\n <RenderChildrenWithAccessor\n getItemState={(aui) => aui.mcp.customServer({ index }).getState()}\n >\n {(getItem) =>\n children({\n get server() {\n return getItem();\n },\n })\n }\n </RenderChildrenWithAccessor>\n </McpCustomServerByIndexProvider>\n ));\n }, [ids, children]);\n};\n\n/**\n * Renders all user-added custom servers persisted in storage.\n *\n * @example\n * ```tsx\n * <McpManagerPrimitive.CustomServers>\n * {() => (\n * <McpServerPrimitive.Root>\n * <McpServerPrimitive.Name />\n * <McpServerPrimitive.RemoveButton>Remove</McpServerPrimitive.RemoveButton>\n * </McpServerPrimitive.Root>\n * )}\n * </McpManagerPrimitive.CustomServers>\n * ```\n */\nexport const McpManagerPrimitiveCustomServers: FC<McpManagerPrimitiveCustomServers.Props> =\n memo(\n McpManagerPrimitiveCustomServersInner,\n (prev, next) => prev.children === next.children,\n );\n\nMcpManagerPrimitiveCustomServers.displayName =\n \"McpManagerPrimitive.CustomServers\";\n"],"mappings":";;;;;AAKA,MAAMQ,MAAM;AAaZ,MAAMM,yCAEA,EAAEH,eAAe;CACrB,MAAMI,YAAYV,aAAaW,MAC7BA,EAAEC,IAAIC,cAAcC,KAAKC,MAAMA,EAAEC,EAAE,CAAC,CAACC,KAAKd,GAAG,CAC/C;CACA,MAAMe,MAAMpB,cACHY,YAAYA,UAAUS,MAAMhB,GAAG,IAAI,CAAA,GAC1C,CAACO,SAAS,CACZ;CAEA,OAAOZ,cAAc;EACnB,IAAIoB,IAAIE,WAAW,GAAG,OAAO;EAC7B,OAAOF,IAAIJ,KAAKE,IAAIK,UAClB,oBAAC,gCAAD;GAAgDA;GAC9C,UAAA,oBAAC,4BAAD;IACE,eAAeC,QAAQA,IAAIV,IAAIW,aAAa,EAAEF,MAAM,CAAC,CAAC,CAACG,SAAS;IAE9DC,WAAAA,YACAnB,SAAS,EACP,IAAIE,SAAS;KACX,OAAOiB,QAAQ;IACjB,EACF,CAAC;GAEuB,CAAA;EACE,GAZKT,EAYL,CACjC;CACH,GAAG,CAACE,KAAKZ,QAAQ,CAAC;AACpB;;;;;;;;;;;;;;;;AAiBA,MAAaF,mCACXP,KACEY,wCACCiB,MAAMC,SAASD,KAAKpB,aAAaqB,KAAKrB,QACzC;AAEFF,iCAAiCwB,cAC/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpServerConnectButton.js","names":["ComponentPropsWithoutRef","ComponentRef","forwardRef","Primitive","useAui","useAuiState","McpServerPrimitiveConnectButton","Element","button","Props","CONNECTABLE","Set","props","ref","$","_c","state","_temp","aui","has","t0","undefined","t1","e","onClick","defaultPrevented","mcpServer","connect","t2","displayName","s","connectionState"],"sources":["../../../src/primitives/server/McpServerConnectButton.tsx"],"sourcesContent":["import {\n type ComponentPropsWithoutRef,\n type ComponentRef,\n forwardRef,\n} from \"react\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { useAui, useAuiState } from \"@assistant-ui/store\";\n\nexport namespace McpServerPrimitiveConnectButton {\n export type Element = ComponentRef<typeof Primitive.button>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.button>;\n}\n\nconst CONNECTABLE = new Set([\"disconnected\", \"error\", \"authRequired\"]);\n\nexport const McpServerPrimitiveConnectButton = forwardRef<\n McpServerPrimitiveConnectButton.Element,\n McpServerPrimitiveConnectButton.Props\n>((props, ref) => {\n const state = useAuiState((s) => s.mcpServer.connectionState);\n const aui = useAui();\n if (!CONNECTABLE.has(state)) return null;\n return (\n <Primitive.button\n {...props}\n type=\"button\"\n ref={ref}\n data-state-hint={state === \"authRequired\" ? \"auth-required\" : undefined}\n onClick={(e) => {\n props.onClick?.(e);\n if (e.defaultPrevented) return;\n void aui.mcpServer
|
|
1
|
+
{"version":3,"file":"McpServerConnectButton.js","names":["ComponentPropsWithoutRef","ComponentRef","forwardRef","Primitive","useAui","useAuiState","McpServerPrimitiveConnectButton","Element","button","Props","CONNECTABLE","Set","props","ref","$","_c","state","_temp","aui","has","t0","undefined","t1","e","onClick","defaultPrevented","mcpServer","connect","t2","displayName","s","connectionState"],"sources":["../../../src/primitives/server/McpServerConnectButton.tsx"],"sourcesContent":["import {\n type ComponentPropsWithoutRef,\n type ComponentRef,\n forwardRef,\n} from \"react\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { useAui, useAuiState } from \"@assistant-ui/store\";\n\nexport namespace McpServerPrimitiveConnectButton {\n export type Element = ComponentRef<typeof Primitive.button>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.button>;\n}\n\nconst CONNECTABLE = new Set([\"disconnected\", \"error\", \"authRequired\"]);\n\nexport const McpServerPrimitiveConnectButton = forwardRef<\n McpServerPrimitiveConnectButton.Element,\n McpServerPrimitiveConnectButton.Props\n>((props, ref) => {\n const state = useAuiState((s) => s.mcpServer.connectionState);\n const aui = useAui();\n if (!CONNECTABLE.has(state)) return null;\n return (\n <Primitive.button\n {...props}\n type=\"button\"\n ref={ref}\n data-state-hint={state === \"authRequired\" ? \"auth-required\" : undefined}\n onClick={(e) => {\n props.onClick?.(e);\n if (e.defaultPrevented) return;\n void aui.mcpServer.connect();\n }}\n />\n );\n});\n\nMcpServerPrimitiveConnectButton.displayName =\n \"McpServerPrimitive.ConnectButton\";\n"],"mappings":";;;;;;AAaA,MAAMU,8BAAc,IAAIC,IAAI;CAAC;CAAgB;CAAS;AAAc,CAAC;AAErE,MAAaL,kCAAkCJ,YAG7CU,OAAAC,QAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CACA,MAAAC,QAAcX,YAAYY,KAAkC;CAC5D,MAAAC,MAAYd,OAAO;CACnB,IAAI,CAACM,YAAWS,IAAKH,KAAK,GAAC,OAAS;CAMf,MAAAI,KAAAJ,UAAU,iBAAV,kBAAAK,KAAAA;CAAsD,IAAAC;CAAA,IAAAR,EAAA,OAAAI,OAAAJ,EAAA,OAAAF,OAAA;EAC9DU,MAAAC,MAAA;GACPX,MAAKY,UAAWD,CAAC;GACjB,IAAIA,EAACE,kBAAiB;GACjBP,IAAGQ,UAAUC,QAAS;EAAC;EAC7Bb,EAAA,KAAAI;EAAAJ,EAAA,KAAAF;EAAAE,EAAA,KAAAQ;CAAA,OAAAA,KAAAR,EAAA;CAAA,IAAAc;CAAA,IAAAd,EAAA,OAAAF,SAAAE,EAAA,OAAAD,OAAAC,EAAA,OAAAM,MAAAN,EAAA,OAAAQ,IAAA;EATHM,KAAA,oBAAA,UAAA,QAAA;GAAA,GACMhB;GACC,MAAA;GACAC;GACY,mBAAAO;GACR,SAAAE;EAIR,CAAA;EACDR,EAAA,KAAAF;EAAAE,EAAA,KAAAD;EAAAC,EAAA,KAAAM;EAAAN,EAAA,KAAAQ;EAAAR,EAAA,KAAAc;CAAA,OAAAA,KAAAd,EAAA;CAAA,OAVFc;AAUE,CAEL;AAEDtB,gCAAgCuB,cAC9B;AApBA,SAAAZ,MAAAa,GAAA;CAAA,OACiCA,EAACJ,UAAUK;AAAgB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpServerDisconnectButton.js","names":["ComponentPropsWithoutRef","ComponentRef","forwardRef","Primitive","useAui","useAuiState","McpServerPrimitiveDisconnectButton","Element","button","Props","DISCONNECTABLE","Set","props","ref","$","_c","state","_temp","aui","has","t0","e","onClick","defaultPrevented","mcpServer","disconnect","t1","displayName","s","connectionState"],"sources":["../../../src/primitives/server/McpServerDisconnectButton.tsx"],"sourcesContent":["import {\n type ComponentPropsWithoutRef,\n type ComponentRef,\n forwardRef,\n} from \"react\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { useAui, useAuiState } from \"@assistant-ui/store\";\n\nexport namespace McpServerPrimitiveDisconnectButton {\n export type Element = ComponentRef<typeof Primitive.button>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.button>;\n}\n\nconst DISCONNECTABLE = new Set([\"connected\", \"connecting\", \"authPending\"]);\n\nexport const McpServerPrimitiveDisconnectButton = forwardRef<\n McpServerPrimitiveDisconnectButton.Element,\n McpServerPrimitiveDisconnectButton.Props\n>((props, ref) => {\n const state = useAuiState((s) => s.mcpServer.connectionState);\n const aui = useAui();\n if (!DISCONNECTABLE.has(state)) return null;\n return (\n <Primitive.button\n {...props}\n type=\"button\"\n ref={ref}\n onClick={(e) => {\n props.onClick?.(e);\n if (e.defaultPrevented) return;\n void aui.mcpServer
|
|
1
|
+
{"version":3,"file":"McpServerDisconnectButton.js","names":["ComponentPropsWithoutRef","ComponentRef","forwardRef","Primitive","useAui","useAuiState","McpServerPrimitiveDisconnectButton","Element","button","Props","DISCONNECTABLE","Set","props","ref","$","_c","state","_temp","aui","has","t0","e","onClick","defaultPrevented","mcpServer","disconnect","t1","displayName","s","connectionState"],"sources":["../../../src/primitives/server/McpServerDisconnectButton.tsx"],"sourcesContent":["import {\n type ComponentPropsWithoutRef,\n type ComponentRef,\n forwardRef,\n} from \"react\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { useAui, useAuiState } from \"@assistant-ui/store\";\n\nexport namespace McpServerPrimitiveDisconnectButton {\n export type Element = ComponentRef<typeof Primitive.button>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.button>;\n}\n\nconst DISCONNECTABLE = new Set([\"connected\", \"connecting\", \"authPending\"]);\n\nexport const McpServerPrimitiveDisconnectButton = forwardRef<\n McpServerPrimitiveDisconnectButton.Element,\n McpServerPrimitiveDisconnectButton.Props\n>((props, ref) => {\n const state = useAuiState((s) => s.mcpServer.connectionState);\n const aui = useAui();\n if (!DISCONNECTABLE.has(state)) return null;\n return (\n <Primitive.button\n {...props}\n type=\"button\"\n ref={ref}\n onClick={(e) => {\n props.onClick?.(e);\n if (e.defaultPrevented) return;\n void aui.mcpServer.disconnect();\n }}\n />\n );\n});\n\nMcpServerPrimitiveDisconnectButton.displayName =\n \"McpServerPrimitive.DisconnectButton\";\n"],"mappings":";;;;;;AAaA,MAAMU,iCAAiB,IAAIC,IAAI;CAAC;CAAa;CAAc;AAAa,CAAC;AAEzE,MAAaL,qCAAqCJ,YAGhDU,OAAAC,QAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CACA,MAAAC,QAAcX,YAAYY,KAAkC;CAC5D,MAAAC,MAAYd,OAAO;CACnB,IAAI,CAACM,eAAcS,IAAKH,KAAK,GAAC,OAAS;CAAK,IAAAI;CAAA,IAAAN,EAAA,OAAAI,OAAAJ,EAAA,OAAAF,OAAA;EAM/BQ,MAAAC,MAAA;GACPT,MAAKU,UAAWD,CAAC;GACjB,IAAIA,EAACE,kBAAiB;GACjBL,IAAGM,UAAUC,WAAY;EAAC;EAChCX,EAAA,KAAAI;EAAAJ,EAAA,KAAAF;EAAAE,EAAA,KAAAM;CAAA,OAAAA,KAAAN,EAAA;CAAA,IAAAY;CAAA,IAAAZ,EAAA,OAAAF,SAAAE,EAAA,OAAAD,OAAAC,EAAA,OAAAM,IAAA;EARHM,KAAA,oBAAA,UAAA,QAAA;GAAA,GACMd;GACC,MAAA;GACAC;GACI,SAAAO;EAIR,CAAA;EACDN,EAAA,KAAAF;EAAAE,EAAA,KAAAD;EAAAC,EAAA,KAAAM;EAAAN,EAAA,KAAAY;CAAA,OAAAA,KAAAZ,EAAA;CAAA,OATFY;AASE,CAEL;AAEDpB,mCAAmCqB,cACjC;AAnBA,SAAAV,MAAAW,GAAA;CAAA,OACiCA,EAACJ,UAAUK;AAAgB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpServerRemoveButton.js","names":["ComponentPropsWithoutRef","ComponentRef","forwardRef","Primitive","useAui","useAuiState","McpServerPrimitiveRemoveButton","Element","button","Props","props","ref","$","_c","kind","_temp","aui","t0","e","onClick","defaultPrevented","mcpServer","remove","t1","displayName","s"],"sources":["../../../src/primitives/server/McpServerRemoveButton.tsx"],"sourcesContent":["import {\n type ComponentPropsWithoutRef,\n type ComponentRef,\n forwardRef,\n} from \"react\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { useAui, useAuiState } from \"@assistant-ui/store\";\n\nexport namespace McpServerPrimitiveRemoveButton {\n export type Element = ComponentRef<typeof Primitive.button>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.button>;\n}\n\nexport const McpServerPrimitiveRemoveButton = forwardRef<\n McpServerPrimitiveRemoveButton.Element,\n McpServerPrimitiveRemoveButton.Props\n>((props, ref) => {\n const kind = useAuiState((s) => s.mcpServer.kind);\n const aui = useAui();\n if (kind !== \"custom\") return null;\n return (\n <Primitive.button\n {...props}\n type=\"button\"\n ref={ref}\n onClick={(e) => {\n props.onClick?.(e);\n if (e.defaultPrevented) return;\n void aui.mcpServer
|
|
1
|
+
{"version":3,"file":"McpServerRemoveButton.js","names":["ComponentPropsWithoutRef","ComponentRef","forwardRef","Primitive","useAui","useAuiState","McpServerPrimitiveRemoveButton","Element","button","Props","props","ref","$","_c","kind","_temp","aui","t0","e","onClick","defaultPrevented","mcpServer","remove","t1","displayName","s"],"sources":["../../../src/primitives/server/McpServerRemoveButton.tsx"],"sourcesContent":["import {\n type ComponentPropsWithoutRef,\n type ComponentRef,\n forwardRef,\n} from \"react\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { useAui, useAuiState } from \"@assistant-ui/store\";\n\nexport namespace McpServerPrimitiveRemoveButton {\n export type Element = ComponentRef<typeof Primitive.button>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.button>;\n}\n\nexport const McpServerPrimitiveRemoveButton = forwardRef<\n McpServerPrimitiveRemoveButton.Element,\n McpServerPrimitiveRemoveButton.Props\n>((props, ref) => {\n const kind = useAuiState((s) => s.mcpServer.kind);\n const aui = useAui();\n if (kind !== \"custom\") return null;\n return (\n <Primitive.button\n {...props}\n type=\"button\"\n ref={ref}\n onClick={(e) => {\n props.onClick?.(e);\n if (e.defaultPrevented) return;\n void aui.mcpServer.remove();\n }}\n />\n );\n});\n\nMcpServerPrimitiveRemoveButton.displayName = \"McpServerPrimitive.RemoveButton\";\n"],"mappings":";;;;;;AAaA,MAAaM,iCAAiCJ,YAG5CQ,OAAAC,QAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CACA,MAAAC,OAAaT,YAAYU,KAAuB;CAChD,MAAAC,MAAYZ,OAAO;CACnB,IAAIU,SAAS,UAAQ,OAAS;CAAK,IAAAG;CAAA,IAAAL,EAAA,OAAAI,OAAAJ,EAAA,OAAAF,OAAA;EAMtBO,MAAAC,MAAA;GACPR,MAAKS,UAAWD,CAAC;GACjB,IAAIA,EAACE,kBAAiB;GACjBJ,IAAGK,UAAUC,OAAQ;EAAC;EAC5BV,EAAA,KAAAI;EAAAJ,EAAA,KAAAF;EAAAE,EAAA,KAAAK;CAAA,OAAAA,KAAAL,EAAA;CAAA,IAAAW;CAAA,IAAAX,EAAA,OAAAF,SAAAE,EAAA,OAAAD,OAAAC,EAAA,OAAAK,IAAA;EARHM,KAAA,oBAAA,UAAA,QAAA;GAAA,GACMb;GACC,MAAA;GACAC;GACI,SAAAM;EAIR,CAAA;EACDL,EAAA,KAAAF;EAAAE,EAAA,KAAAD;EAAAC,EAAA,KAAAK;EAAAL,EAAA,KAAAW;CAAA,OAAAA,KAAAX,EAAA;CAAA,OATFW;AASE,CAEL;AAEDjB,+BAA+BkB,cAAc;AAlB3C,SAAAT,MAAAU,GAAA;CAAA,OACgCA,EAACJ,UAAUP;AAAK"}
|
|
@@ -225,7 +225,7 @@ const useMcpManagerResource = (props) => {
|
|
|
225
225
|
t13 = () => {
|
|
226
226
|
const client = clientRef.current;
|
|
227
227
|
if (!client) return;
|
|
228
|
-
return client.modelContext
|
|
228
|
+
return client.modelContext.register({ getModelContext: () => ({ tools: toolkit }) });
|
|
229
229
|
};
|
|
230
230
|
t14 = [toolkit, clientRef];
|
|
231
231
|
$[46] = clientRef;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpManagerResource.js","names":["useState","useEffect","useMemo","useEffectEvent","useRef","useResource","resource","withKey","useClientLookup","useAssistantClientRef","attachTransformScopes","ClientOutput","ModelContext","Tool","McpServerResource","McpLocalStorage","MCPStorageElement","assertUniqueServerIds","MCPAuthConfig","MCPConnector","MCPCustomServerRecord","MCPManagerState","McpManagerResourceProps","connectors","storage","oauthRedirectUri","autoConnect","connectionTimeout","defaultRedirectUri","window","location","origin","NO_CONNECTORS","useMcpManagerResource","props","$","_c","t0","redirectUri","t1","storageElement","t2","Symbol","for","customServers","setCustomServers","isHydrated","setIsHydrated","hydratedRef","t3","signal","markHydrated","cancelled","current","records","loadCustomServers","t4","error","prev","length","persistedIds","Set","map","_temp","filter","r_0","has","r","id","hydrate","signal_0","t5","t6","records_0","saveCustomServers","persistCustomServers","t7","t8","_temp2","_temp3","t9","t10","c_0","c","kind","name","url","icon","auth","onRemove","_temp4","connectorElements","t11","s_0","s","prev_0","x","customElements","serverElements","lookup","all","state","_temp5","_temp6","t12","servers","out","server","connectionState","tool","tools","fullName","type","description","undefined","parameters","inputSchema","execute","args","get","key","callTool","toolkit","clientRef","t13","t14","client","modelContext","register","getModelContext","t15","index","list","entry","Error","serverByKind","t16","t17","query","t18","t19","t20","index_0","t21","index_1","connectionTimeout_0","record","crypto","randomUUID","Date","now","Math","random","toString","slice","createdAt","prev_1","some","c_1","remove","clearAuthState","prev_2","s_3","t22","getState","connector","customServer","addCustomServer","removeServer","McpManagerResource","scopes","parent","source","s_1","s_2"],"sources":["../../src/resources/McpManagerResource.ts"],"sourcesContent":["import { useState, useEffect, useMemo, useEffectEvent, useRef } from \"react\";\nimport { useResource, resource, withKey } from \"@assistant-ui/tap\";\nimport {\n useClientLookup,\n useAssistantClientRef,\n attachTransformScopes,\n type ClientOutput,\n} from \"@assistant-ui/store\";\nimport { ModelContext } from \"@assistant-ui/core/store\";\nimport type { Tool } from \"assistant-stream\";\nimport { McpServerResource } from \"./McpServerResource\";\nimport { McpLocalStorage } from \"./storage/McpLocalStorage\";\nimport type { MCPStorageElement } from \"./storage/types\";\nimport { assertUniqueServerIds } from \"../utils/serverId\";\nimport type {\n MCPAuthConfig,\n MCPConnector,\n MCPCustomServerRecord,\n MCPManagerState,\n} from \"../mcp-scope\";\n\nexport type McpManagerResourceProps = {\n connectors?: MCPConnector[] | undefined;\n storage?: MCPStorageElement | undefined;\n /** OAuth redirect target. Defaults to `${origin}/mcp/callback`. */\n oauthRedirectUri?: string | undefined;\n /** Connect on mount when usable auth exists. Default true. */\n autoConnect?: boolean | undefined;\n /** Optional timeout in milliseconds for connect/listTools calls. Disabled by default. */\n connectionTimeout?: number | undefined;\n};\n\nfunction defaultRedirectUri(): string {\n if (typeof window === \"undefined\") return \"\";\n return `${window.location.origin}/mcp/callback`;\n}\n\n// Stable empty fallback so an absent `connectors` prop doesn't produce a fresh\n// array each render (which would invalidate the serverElements memo below).\nconst NO_CONNECTORS: MCPConnector[] = [];\n\nconst useMcpManagerResource = (\n props: McpManagerResourceProps,\n): ClientOutput<\"mcp\"> => {\n const connectors = props.connectors ?? NO_CONNECTORS;\n const autoConnect = props.autoConnect ?? true;\n const redirectUri = props.oauthRedirectUri ?? defaultRedirectUri();\n const connectionTimeout = props.connectionTimeout;\n\n const storageElement = props.storage ?? McpLocalStorage();\n const storage = useResource(storageElement);\n\n const [customServers, setCustomServers] = useState<MCPCustomServerRecord[]>(\n [],\n );\n const [isHydrated, setIsHydrated] = useState(false);\n\n const hydratedRef = useRef(false);\n\n const hydrate = useEffectEvent(async (signal: { cancelled: boolean }) => {\n const markHydrated = () => {\n if (!signal.cancelled) {\n hydratedRef.current = true;\n setIsHydrated(true);\n }\n };\n\n let records: Awaited<ReturnType<typeof storage.loadCustomServers>>;\n try {\n records = await storage.loadCustomServers();\n } catch (error) {\n markHydrated();\n throw error;\n }\n\n if (signal.cancelled) return;\n // Merge rather than replace so any addCustomServer calls that\n // happened before hydration resolved aren't silently overwritten.\n // Persisted order wins; pre-hydration locals append.\n setCustomServers((prev) => {\n if (prev.length === 0) return records;\n const persistedIds = new Set(records.map((r) => r.id));\n return [...records, ...prev.filter((r) => !persistedIds.has(r.id))];\n });\n markHydrated();\n });\n\n useEffect(() => {\n const signal = { cancelled: false };\n void hydrate(signal);\n return () => {\n signal.cancelled = true;\n };\n }, []);\n\n const persistCustomServers = useEffectEvent(\n async (records: MCPCustomServerRecord[]) => {\n if (!hydratedRef.current) return;\n await storage.saveCustomServers(records);\n },\n );\n\n useEffect(() => {\n void persistCustomServers(customServers);\n }, [customServers]);\n\n const serverElements = useMemo(() => {\n assertUniqueServerIds([\n ...connectors.map((c) => c.id),\n ...customServers.map((s) => s.id),\n ]);\n\n const connectorElements = connectors.map((c) =>\n withKey(\n c.id,\n McpServerResource({\n id: c.id,\n kind: \"connector\",\n name: c.name,\n url: c.url,\n icon: c.icon,\n auth: c.auth,\n storage,\n redirectUri,\n autoConnect,\n connectionTimeout: c.connectionTimeout ?? connectionTimeout,\n onRemove: async () => {\n // connectors cannot be removed\n },\n }),\n ),\n );\n const customElements = customServers.map((s) =>\n withKey(\n s.id,\n McpServerResource({\n id: s.id,\n kind: \"custom\",\n name: s.name,\n url: s.url,\n auth: s.auth,\n storage,\n redirectUri,\n autoConnect,\n connectionTimeout: s.connectionTimeout ?? connectionTimeout,\n onRemove: async () => {\n setCustomServers((prev) => prev.filter((x) => x.id !== s.id));\n },\n }),\n ),\n );\n return [...connectorElements, ...customElements];\n }, [\n connectors,\n customServers,\n storage,\n redirectUri,\n autoConnect,\n connectionTimeout,\n ]);\n\n const lookup = useClientLookup(serverElements);\n\n const state = useMemo<MCPManagerState>(() => {\n const all = lookup.state;\n return {\n servers: all,\n connectors: all.filter((s) => s.kind === \"connector\"),\n customServers: all.filter((s) => s.kind === \"custom\"),\n isHydrated,\n };\n }, [lookup.state, isHydrated]);\n\n // ─── Auto-register MCP tools as frontend tools in modelContext ─────\n // Build the toolkit from connected servers; re-register when the visible\n // tool surface changes. Tool names are prefixed with the server id to\n // avoid collisions across connected servers — connector ids must not\n // contain `__` (enforced by `defineConnector`); `addCustomServer`\n // generates UUIDs that satisfy the constraint by construction.\n const toolkit = useMemo<Record<string, Tool<any, any>>>(() => {\n const out: Record<string, Tool<any, any>> = {};\n for (const server of state.servers) {\n if (server.connectionState !== \"connected\") continue;\n for (const tool of server.tools) {\n const fullName = `${server.id}__${tool.name}`;\n out[fullName] = {\n type: \"frontend\",\n ...(tool.description !== undefined\n ? { description: tool.description }\n : {}),\n parameters: tool.inputSchema as never,\n execute: (args) =>\n lookup.get({ key: server.id }).callTool(tool.name, args as unknown),\n };\n }\n }\n return out;\n }, [state, lookup]);\n\n const clientRef = useAssistantClientRef();\n\n useEffect(() => {\n const client = clientRef.current;\n if (!client) return;\n return client.modelContext().register({\n getModelContext: () => ({ tools: toolkit }),\n });\n }, [toolkit, clientRef]);\n\n const serverByKind = (kind: \"connector\" | \"custom\", index: number) => {\n const list = kind === \"connector\" ? state.connectors : state.customServers;\n const entry = list[index];\n if (!entry) {\n throw new Error(\n `McpManagerResource: no ${kind} at index ${index} (length ${list.length})`,\n );\n }\n return lookup.get({ key: entry.id });\n };\n\n return {\n getState: () => state,\n server: (query) => {\n if (\"id\" in query) return lookup.get({ key: query.id });\n return serverByKind(query.kind, query.index);\n },\n connector: ({ index }) => serverByKind(\"connector\", index),\n customServer: ({ index }) => serverByKind(\"custom\", index),\n addCustomServer: async ({ name, url, auth, connectionTimeout }) => {\n const record: MCPCustomServerRecord = {\n id:\n typeof crypto !== \"undefined\" && \"randomUUID\" in crypto\n ? crypto.randomUUID()\n : `mcp-${Date.now()}-${Math.random().toString(36).slice(2)}`,\n name,\n url,\n auth: auth as MCPAuthConfig,\n connectionTimeout,\n createdAt: Date.now(),\n };\n setCustomServers((prev) => [...prev, record]);\n return record.id;\n },\n removeServer: async (id) => {\n // removeServer is custom-server only — connectors are app-defined\n // and not user-removable. Refuse rather than silently no-op.\n if (state.connectors.some((c) => c.id === id)) {\n throw new Error(\n `Cannot remove connector \"${id}\" — connectors are app-defined and not removable. Use a custom server id instead.`,\n );\n }\n // Delegate to McpServerResource.remove() which disconnects,\n // clears auth state, and unregisters from customServers in one\n // place. Fallback to manual cleanup if the lookup is empty\n // (server already gone).\n try {\n await lookup.get({ key: id }).remove();\n } catch {\n await storage.clearAuthState(id);\n setCustomServers((prev) => prev.filter((s) => s.id !== id));\n }\n },\n };\n};\n\nexport const McpManagerResource = resource(useMcpManagerResource);\n\n// Ensure modelContext exists as a sibling when the manager mounts. If an\n// ancestor (e.g. a chat runtime) already provides modelContext, this is a\n// no-op; otherwise it's auto-mounted alongside `mcp`.\nattachTransformScopes(useMcpManagerResource, (scopes, parent) => {\n if (!scopes.modelContext && parent.modelContext.source === null) {\n scopes.modelContext = ModelContext();\n }\n});\n"],"mappings":";;;;;;;;;AAgCA,SAAS4B,qBAA6B;CACpC,IAAI,OAAOC,WAAW,aAAa,OAAO;CAC1C,OAAO,GAAGA,OAAOC,SAASC,OAAM;AAClC;AAIA,MAAMC,gBAAgC,CAAA;AAEtC,MAAMC,yBAAwBC,UAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAG5B,MAAAb,aAAmBW,MAAKX,cAALS;CACnB,MAAAN,cAAoBQ,MAAKR,eAAL;CAA0B,IAAAW;CAAA,IAAAF,EAAA,OAAAD,MAAAT,kBAAA;EAC1BY,KAAAH,MAAKT,oBAAqBG,mBAAmB;EAACO,EAAA,KAAAD,MAAAT;EAAAU,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAAlE,MAAAG,cAAoBD;CACpB,MAAAV,oBAA0BO,MAAKP;CAAmB,IAAAY;CAAA,IAAAJ,EAAA,OAAAD,MAAAV,SAAA;EAE3Be,KAAAL,MAAKV,WAAYT,gBAAgB;EAACoB,EAAA,KAAAD,MAAAV;EAAAW,EAAA,KAAAI;CAAA,OAAAA,KAAAJ,EAAA;CACzD,MAAAX,UAAgBnB,YAAYmC,EAAc;CAAE,IAAAC;CAAA,IAAAN,EAAA,OAAAO,OAAAC,IAAA,2BAAA,GAAA;EAG1CF,KAAA,CAAA;EAAEN,EAAA,KAAAM;CAAA,OAAAA,KAAAN,EAAA;CADJ,MAAA,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;AAAG;AAxC5B,SAAAU,OAAAK,GAAA;CAAA,OAmECA,EAACf;AAAG;AAnEL,SAAAW,OAAAe,GAAA;CAAA,OAoEIA,EAAC1B;AAAG;AApER,eAAAsB,SAAA,CAAA;AAAA,SAAAY,OAAAuE,KAAA;CAAA,OA8HM/E,IAACV,SAAU;AAAW;AA9H5B,SAAAmB,OAAAuE,KAAA;CAAA,OA+HShF,IAACV,SAAU;AAAQ"}
|
|
1
|
+
{"version":3,"file":"McpManagerResource.js","names":["useState","useEffect","useMemo","useEffectEvent","useRef","useResource","resource","withKey","useClientLookup","useAssistantClientRef","attachTransformScopes","ClientOutput","ModelContext","Tool","McpServerResource","McpLocalStorage","MCPStorageElement","assertUniqueServerIds","MCPAuthConfig","MCPConnector","MCPCustomServerRecord","MCPManagerState","McpManagerResourceProps","connectors","storage","oauthRedirectUri","autoConnect","connectionTimeout","defaultRedirectUri","window","location","origin","NO_CONNECTORS","useMcpManagerResource","props","$","_c","t0","redirectUri","t1","storageElement","t2","Symbol","for","customServers","setCustomServers","isHydrated","setIsHydrated","hydratedRef","t3","signal","markHydrated","cancelled","current","records","loadCustomServers","t4","error","prev","length","persistedIds","Set","map","_temp","filter","r_0","has","r","id","hydrate","signal_0","t5","t6","records_0","saveCustomServers","persistCustomServers","t7","t8","_temp2","_temp3","t9","t10","c_0","c","kind","name","url","icon","auth","onRemove","_temp4","connectorElements","t11","s_0","s","prev_0","x","customElements","serverElements","lookup","all","state","_temp5","_temp6","t12","servers","out","server","connectionState","tool","tools","fullName","type","description","undefined","parameters","inputSchema","execute","args","get","key","callTool","toolkit","clientRef","t13","t14","client","modelContext","register","getModelContext","t15","index","list","entry","Error","serverByKind","t16","t17","query","t18","t19","t20","index_0","t21","index_1","connectionTimeout_0","record","crypto","randomUUID","Date","now","Math","random","toString","slice","createdAt","prev_1","some","c_1","remove","clearAuthState","prev_2","s_3","t22","getState","connector","customServer","addCustomServer","removeServer","McpManagerResource","scopes","parent","source","s_1","s_2"],"sources":["../../src/resources/McpManagerResource.ts"],"sourcesContent":["import { useState, useEffect, useMemo, useEffectEvent, useRef } from \"react\";\nimport { useResource, resource, withKey } from \"@assistant-ui/tap\";\nimport {\n useClientLookup,\n useAssistantClientRef,\n attachTransformScopes,\n type ClientOutput,\n} from \"@assistant-ui/store\";\nimport { ModelContext } from \"@assistant-ui/core/store\";\nimport type { Tool } from \"assistant-stream\";\nimport { McpServerResource } from \"./McpServerResource\";\nimport { McpLocalStorage } from \"./storage/McpLocalStorage\";\nimport type { MCPStorageElement } from \"./storage/types\";\nimport { assertUniqueServerIds } from \"../utils/serverId\";\nimport type {\n MCPAuthConfig,\n MCPConnector,\n MCPCustomServerRecord,\n MCPManagerState,\n} from \"../mcp-scope\";\n\nexport type McpManagerResourceProps = {\n connectors?: MCPConnector[] | undefined;\n storage?: MCPStorageElement | undefined;\n /** OAuth redirect target. Defaults to `${origin}/mcp/callback`. */\n oauthRedirectUri?: string | undefined;\n /** Connect on mount when usable auth exists. Default true. */\n autoConnect?: boolean | undefined;\n /** Optional timeout in milliseconds for connect/listTools calls. Disabled by default. */\n connectionTimeout?: number | undefined;\n};\n\nfunction defaultRedirectUri(): string {\n if (typeof window === \"undefined\") return \"\";\n return `${window.location.origin}/mcp/callback`;\n}\n\n// Stable empty fallback so an absent `connectors` prop doesn't produce a fresh\n// array each render (which would invalidate the serverElements memo below).\nconst NO_CONNECTORS: MCPConnector[] = [];\n\nconst useMcpManagerResource = (\n props: McpManagerResourceProps,\n): ClientOutput<\"mcp\"> => {\n const connectors = props.connectors ?? NO_CONNECTORS;\n const autoConnect = props.autoConnect ?? true;\n const redirectUri = props.oauthRedirectUri ?? defaultRedirectUri();\n const connectionTimeout = props.connectionTimeout;\n\n const storageElement = props.storage ?? McpLocalStorage();\n const storage = useResource(storageElement);\n\n const [customServers, setCustomServers] = useState<MCPCustomServerRecord[]>(\n [],\n );\n const [isHydrated, setIsHydrated] = useState(false);\n\n const hydratedRef = useRef(false);\n\n const hydrate = useEffectEvent(async (signal: { cancelled: boolean }) => {\n const markHydrated = () => {\n if (!signal.cancelled) {\n hydratedRef.current = true;\n setIsHydrated(true);\n }\n };\n\n let records: Awaited<ReturnType<typeof storage.loadCustomServers>>;\n try {\n records = await storage.loadCustomServers();\n } catch (error) {\n markHydrated();\n throw error;\n }\n\n if (signal.cancelled) return;\n // Merge rather than replace so any addCustomServer calls that\n // happened before hydration resolved aren't silently overwritten.\n // Persisted order wins; pre-hydration locals append.\n setCustomServers((prev) => {\n if (prev.length === 0) return records;\n const persistedIds = new Set(records.map((r) => r.id));\n return [...records, ...prev.filter((r) => !persistedIds.has(r.id))];\n });\n markHydrated();\n });\n\n useEffect(() => {\n const signal = { cancelled: false };\n void hydrate(signal);\n return () => {\n signal.cancelled = true;\n };\n }, []);\n\n const persistCustomServers = useEffectEvent(\n async (records: MCPCustomServerRecord[]) => {\n if (!hydratedRef.current) return;\n await storage.saveCustomServers(records);\n },\n );\n\n useEffect(() => {\n void persistCustomServers(customServers);\n }, [customServers]);\n\n const serverElements = useMemo(() => {\n assertUniqueServerIds([\n ...connectors.map((c) => c.id),\n ...customServers.map((s) => s.id),\n ]);\n\n const connectorElements = connectors.map((c) =>\n withKey(\n c.id,\n McpServerResource({\n id: c.id,\n kind: \"connector\",\n name: c.name,\n url: c.url,\n icon: c.icon,\n auth: c.auth,\n storage,\n redirectUri,\n autoConnect,\n connectionTimeout: c.connectionTimeout ?? connectionTimeout,\n onRemove: async () => {\n // connectors cannot be removed\n },\n }),\n ),\n );\n const customElements = customServers.map((s) =>\n withKey(\n s.id,\n McpServerResource({\n id: s.id,\n kind: \"custom\",\n name: s.name,\n url: s.url,\n auth: s.auth,\n storage,\n redirectUri,\n autoConnect,\n connectionTimeout: s.connectionTimeout ?? connectionTimeout,\n onRemove: async () => {\n setCustomServers((prev) => prev.filter((x) => x.id !== s.id));\n },\n }),\n ),\n );\n return [...connectorElements, ...customElements];\n }, [\n connectors,\n customServers,\n storage,\n redirectUri,\n autoConnect,\n connectionTimeout,\n ]);\n\n const lookup = useClientLookup(serverElements);\n\n const state = useMemo<MCPManagerState>(() => {\n const all = lookup.state;\n return {\n servers: all,\n connectors: all.filter((s) => s.kind === \"connector\"),\n customServers: all.filter((s) => s.kind === \"custom\"),\n isHydrated,\n };\n }, [lookup.state, isHydrated]);\n\n // ─── Auto-register MCP tools as frontend tools in modelContext ─────\n // Build the toolkit from connected servers; re-register when the visible\n // tool surface changes. Tool names are prefixed with the server id to\n // avoid collisions across connected servers — connector ids must not\n // contain `__` (enforced by `defineConnector`); `addCustomServer`\n // generates UUIDs that satisfy the constraint by construction.\n const toolkit = useMemo<Record<string, Tool<any, any>>>(() => {\n const out: Record<string, Tool<any, any>> = {};\n for (const server of state.servers) {\n if (server.connectionState !== \"connected\") continue;\n for (const tool of server.tools) {\n const fullName = `${server.id}__${tool.name}`;\n out[fullName] = {\n type: \"frontend\",\n ...(tool.description !== undefined\n ? { description: tool.description }\n : {}),\n parameters: tool.inputSchema as never,\n execute: (args) =>\n lookup.get({ key: server.id }).callTool(tool.name, args as unknown),\n };\n }\n }\n return out;\n }, [state, lookup]);\n\n const clientRef = useAssistantClientRef();\n\n useEffect(() => {\n const client = clientRef.current;\n if (!client) return;\n return client.modelContext.register({\n getModelContext: () => ({ tools: toolkit }),\n });\n }, [toolkit, clientRef]);\n\n const serverByKind = (kind: \"connector\" | \"custom\", index: number) => {\n const list = kind === \"connector\" ? state.connectors : state.customServers;\n const entry = list[index];\n if (!entry) {\n throw new Error(\n `McpManagerResource: no ${kind} at index ${index} (length ${list.length})`,\n );\n }\n return lookup.get({ key: entry.id });\n };\n\n return {\n getState: () => state,\n server: (query) => {\n if (\"id\" in query) return lookup.get({ key: query.id });\n return serverByKind(query.kind, query.index);\n },\n connector: ({ index }) => serverByKind(\"connector\", index),\n customServer: ({ index }) => serverByKind(\"custom\", index),\n addCustomServer: async ({ name, url, auth, connectionTimeout }) => {\n const record: MCPCustomServerRecord = {\n id:\n typeof crypto !== \"undefined\" && \"randomUUID\" in crypto\n ? crypto.randomUUID()\n : `mcp-${Date.now()}-${Math.random().toString(36).slice(2)}`,\n name,\n url,\n auth: auth as MCPAuthConfig,\n connectionTimeout,\n createdAt: Date.now(),\n };\n setCustomServers((prev) => [...prev, record]);\n return record.id;\n },\n removeServer: async (id) => {\n // removeServer is custom-server only — connectors are app-defined\n // and not user-removable. Refuse rather than silently no-op.\n if (state.connectors.some((c) => c.id === id)) {\n throw new Error(\n `Cannot remove connector \"${id}\" — connectors are app-defined and not removable. Use a custom server id instead.`,\n );\n }\n // Delegate to McpServerResource.remove() which disconnects,\n // clears auth state, and unregisters from customServers in one\n // place. Fallback to manual cleanup if the lookup is empty\n // (server already gone).\n try {\n await lookup.get({ key: id }).remove();\n } catch {\n await storage.clearAuthState(id);\n setCustomServers((prev) => prev.filter((s) => s.id !== id));\n }\n },\n };\n};\n\nexport const McpManagerResource = resource(useMcpManagerResource);\n\n// Ensure modelContext exists as a sibling when the manager mounts. If an\n// ancestor (e.g. a chat runtime) already provides modelContext, this is a\n// no-op; otherwise it's auto-mounted alongside `mcp`.\nattachTransformScopes(useMcpManagerResource, (scopes, parent) => {\n if (!scopes.modelContext && parent.modelContext.source === null) {\n scopes.modelContext = ModelContext();\n }\n});\n"],"mappings":";;;;;;;;;AAgCA,SAAS4B,qBAA6B;CACpC,IAAI,OAAOC,WAAW,aAAa,OAAO;CAC1C,OAAO,GAAGA,OAAOC,SAASC,OAAM;AAClC;AAIA,MAAMC,gBAAgC,CAAA;AAEtC,MAAMC,yBAAwBC,UAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAG5B,MAAAb,aAAmBW,MAAKX,cAALS;CACnB,MAAAN,cAAoBQ,MAAKR,eAAL;CAA0B,IAAAW;CAAA,IAAAF,EAAA,OAAAD,MAAAT,kBAAA;EAC1BY,KAAAH,MAAKT,oBAAqBG,mBAAmB;EAACO,EAAA,KAAAD,MAAAT;EAAAU,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAAl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AAAsG;EAAAtG,EAAA,MAAAwG;EAAAxG,EAAA,MAAAyG;EAAAzG,EAAA,MAAA4G;EAAA5G,EAAA,MAAAgI;CAAA,OAAAA,MAAAhI,EAAA;CAAA,OA1CMgI;AA0CN;AAGH,MAAaM,qBAAqBnK,SAAS2B,qBAAqB;AAKhEvB,sBAAsBuB,wBAAwByI,QAAQC,WAAW;CAC/D,IAAI,CAACD,OAAO3C,gBAAgB4C,OAAO5C,aAAa6C,WAAW,MACzDF,OAAO3C,eAAenH,aAAa;AAEvC,CAAC;AAzO6B,SAAAmD,MAAAI,GAAA;CAAA,OAwCwBA,EAACC;AAAG;AAxC5B,SAAAU,OAAAK,GAAA;CAAA,OAmECA,EAACf;AAAG;AAnEL,SAAAW,OAAAe,GAAA;CAAA,OAoEIA,EAAC1B;AAAG;AApER,eAAAsB,SAAA,CAAA;AAAA,SAAAY,OAAAuE,KAAA;CAAA,OA8HM/E,IAACV,SAAU;AAAW;AA9H5B,SAAAmB,OAAAuE,KAAA;CAAA,OA+HShF,IAACV,SAAU;AAAQ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@assistant-ui/tap";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@assistant-ui/react-mcp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"description": "MCP server configuration and connection primitives for @assistant-ui",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
31
31
|
"@radix-ui/react-primitive": "^2.1.10",
|
|
32
|
-
"@assistant-ui/core": "0.
|
|
33
|
-
"@assistant-ui/store": "0.
|
|
34
|
-
"@assistant-ui/tap": "0.9.
|
|
35
|
-
"assistant-stream": "0.3.
|
|
32
|
+
"@assistant-ui/core": "0.3.0",
|
|
33
|
+
"@assistant-ui/store": "0.3.0",
|
|
34
|
+
"@assistant-ui/tap": "0.9.7",
|
|
35
|
+
"assistant-stream": "0.3.29"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@types/react": "*",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@types/react": "^19.2.17",
|
|
48
48
|
"react": "^19.2.8",
|
|
49
49
|
"vitest": "^4.1.10",
|
|
50
|
-
"@assistant-ui/x-buildutils": "0.0.
|
|
50
|
+
"@assistant-ui/x-buildutils": "0.0.20"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public",
|
|
@@ -69,7 +69,7 @@ export function useMcpOAuthCallback(
|
|
|
69
69
|
throw new Error("state was not created by assistant-ui MCP");
|
|
70
70
|
}
|
|
71
71
|
setResult({ status: "running", serverId, error: null });
|
|
72
|
-
await aui.mcp
|
|
72
|
+
await aui.mcp.server({ id: serverId }).completeAuth(url);
|
|
73
73
|
setResult({ status: "done", serverId, error: null });
|
|
74
74
|
optsRef.current.onComplete?.(serverId);
|
|
75
75
|
} catch (err) {
|
|
@@ -100,7 +100,7 @@ export const McpAddFormPrimitiveRoot = forwardRef<
|
|
|
100
100
|
}
|
|
101
101
|
setState((p) => ({ ...p, submitting: true, error: null }));
|
|
102
102
|
try {
|
|
103
|
-
const id = await aui.mcp
|
|
103
|
+
const id = await aui.mcp.addCustomServer({
|
|
104
104
|
name: state.name.trim(),
|
|
105
105
|
url: urlResult.url,
|
|
106
106
|
auth: buildAuth(),
|
|
@@ -37,7 +37,7 @@ const McpManagerPrimitiveConnectorsInner: FC<{
|
|
|
37
37
|
return ids.map((id, index) => (
|
|
38
38
|
<McpConnectorByIndexProvider key={id} index={index}>
|
|
39
39
|
<RenderChildrenWithAccessor
|
|
40
|
-
getItemState={(aui) => aui.mcp
|
|
40
|
+
getItemState={(aui) => aui.mcp.connector({ index }).getState()}
|
|
41
41
|
>
|
|
42
42
|
{(getItem) =>
|
|
43
43
|
children({
|
|
@@ -32,7 +32,7 @@ const McpManagerPrimitiveCustomServersInner: FC<{
|
|
|
32
32
|
return ids.map((id, index) => (
|
|
33
33
|
<McpCustomServerByIndexProvider key={id} index={index}>
|
|
34
34
|
<RenderChildrenWithAccessor
|
|
35
|
-
getItemState={(aui) => aui.mcp
|
|
35
|
+
getItemState={(aui) => aui.mcp.customServer({ index }).getState()}
|
|
36
36
|
>
|
|
37
37
|
{(getItem) =>
|
|
38
38
|
children({
|
|
@@ -202,7 +202,7 @@ const useMcpManagerResource = (
|
|
|
202
202
|
useEffect(() => {
|
|
203
203
|
const client = clientRef.current;
|
|
204
204
|
if (!client) return;
|
|
205
|
-
return client.modelContext
|
|
205
|
+
return client.modelContext.register({
|
|
206
206
|
getModelContext: () => ({ tools: toolkit }),
|
|
207
207
|
});
|
|
208
208
|
}, [toolkit, clientRef]);
|