@assistant-ui/react-mcp 0.1.19 → 0.1.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.
Files changed (207) hide show
  1. package/LICENSE +1 -1
  2. package/dist/auth/buildHeaders.d.ts +2 -4
  3. package/dist/auth/buildHeaders.d.ts.map +1 -1
  4. package/dist/auth/createOAuthProvider.d.ts +19 -20
  5. package/dist/auth/createOAuthProvider.d.ts.map +1 -1
  6. package/dist/auth/types.d.ts +12 -14
  7. package/dist/auth/types.d.ts.map +1 -1
  8. package/dist/connector.d.ts +1 -3
  9. package/dist/connector.d.ts.map +1 -1
  10. package/dist/context/McpConnectorByIndexProvider.d.ts +2 -4
  11. package/dist/context/McpConnectorByIndexProvider.d.ts.map +1 -1
  12. package/dist/context/McpConnectorByIndexProvider.js +1 -1
  13. package/dist/context/McpConnectorByIndexProvider.js.map +1 -1
  14. package/dist/context/McpCustomServerByIndexProvider.d.ts +2 -4
  15. package/dist/context/McpCustomServerByIndexProvider.d.ts.map +1 -1
  16. package/dist/context/McpCustomServerByIndexProvider.js +1 -1
  17. package/dist/context/McpCustomServerByIndexProvider.js.map +1 -1
  18. package/dist/context/McpServerByIdProvider.d.ts +2 -4
  19. package/dist/context/McpServerByIdProvider.d.ts.map +1 -1
  20. package/dist/context/McpServerByIdProvider.js +1 -1
  21. package/dist/context/McpServerByIdProvider.js.map +1 -1
  22. package/dist/hooks/useMcpOAuthCallback.d.ts +9 -11
  23. package/dist/hooks/useMcpOAuthCallback.d.ts.map +1 -1
  24. package/dist/hooks/useMcpOAuthCallback.js +2 -2
  25. package/dist/hooks/useMcpOAuthCallback.js.map +1 -1
  26. package/dist/index.d.ts +19 -18
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +4 -4
  29. package/dist/mcp-scope.d.ts +110 -112
  30. package/dist/mcp-scope.d.ts.map +1 -1
  31. package/dist/primitives/addForm/McpAddFormAuthFields.d.ts +12 -14
  32. package/dist/primitives/addForm/McpAddFormAuthFields.d.ts.map +1 -1
  33. package/dist/primitives/addForm/McpAddFormAuthFields.js.map +1 -1
  34. package/dist/primitives/addForm/McpAddFormAuthSelect.d.ts +3 -5
  35. package/dist/primitives/addForm/McpAddFormAuthSelect.d.ts.map +1 -1
  36. package/dist/primitives/addForm/McpAddFormAuthSelect.js +1 -1
  37. package/dist/primitives/addForm/McpAddFormAuthSelect.js.map +1 -1
  38. package/dist/primitives/addForm/McpAddFormBearerTokenField.d.ts +3 -5
  39. package/dist/primitives/addForm/McpAddFormBearerTokenField.d.ts.map +1 -1
  40. package/dist/primitives/addForm/McpAddFormBearerTokenField.js +1 -1
  41. package/dist/primitives/addForm/McpAddFormBearerTokenField.js.map +1 -1
  42. package/dist/primitives/addForm/McpAddFormCancel.d.ts +4 -6
  43. package/dist/primitives/addForm/McpAddFormCancel.d.ts.map +1 -1
  44. package/dist/primitives/addForm/McpAddFormCancel.js +1 -1
  45. package/dist/primitives/addForm/McpAddFormCancel.js.map +1 -1
  46. package/dist/primitives/addForm/McpAddFormError.d.ts +4 -6
  47. package/dist/primitives/addForm/McpAddFormError.d.ts.map +1 -1
  48. package/dist/primitives/addForm/McpAddFormError.js +1 -1
  49. package/dist/primitives/addForm/McpAddFormError.js.map +1 -1
  50. package/dist/primitives/addForm/McpAddFormNameField.d.ts +3 -5
  51. package/dist/primitives/addForm/McpAddFormNameField.d.ts.map +1 -1
  52. package/dist/primitives/addForm/McpAddFormNameField.js +1 -1
  53. package/dist/primitives/addForm/McpAddFormNameField.js.map +1 -1
  54. package/dist/primitives/addForm/McpAddFormRoot.d.ts +9 -11
  55. package/dist/primitives/addForm/McpAddFormRoot.d.ts.map +1 -1
  56. package/dist/primitives/addForm/McpAddFormRoot.js +2 -2
  57. package/dist/primitives/addForm/McpAddFormScopesField.d.ts +3 -5
  58. package/dist/primitives/addForm/McpAddFormScopesField.d.ts.map +1 -1
  59. package/dist/primitives/addForm/McpAddFormScopesField.js +1 -1
  60. package/dist/primitives/addForm/McpAddFormScopesField.js.map +1 -1
  61. package/dist/primitives/addForm/McpAddFormSubmit.d.ts +4 -6
  62. package/dist/primitives/addForm/McpAddFormSubmit.d.ts.map +1 -1
  63. package/dist/primitives/addForm/McpAddFormSubmit.js +1 -1
  64. package/dist/primitives/addForm/McpAddFormSubmit.js.map +1 -1
  65. package/dist/primitives/addForm/McpAddFormUrlField.d.ts +3 -5
  66. package/dist/primitives/addForm/McpAddFormUrlField.d.ts.map +1 -1
  67. package/dist/primitives/addForm/McpAddFormUrlField.js +1 -1
  68. package/dist/primitives/addForm/McpAddFormUrlField.js.map +1 -1
  69. package/dist/primitives/addForm/context.d.ts +18 -20
  70. package/dist/primitives/addForm/context.d.ts.map +1 -1
  71. package/dist/primitives/addForm.d.ts +10 -15
  72. package/dist/primitives/addForm.d.ts.map +1 -1
  73. package/dist/primitives/elicitation/McpElicitationPrimitiveAccept.d.ts +4 -6
  74. package/dist/primitives/elicitation/McpElicitationPrimitiveAccept.d.ts.map +1 -1
  75. package/dist/primitives/elicitation/McpElicitationPrimitiveAccept.js +2 -2
  76. package/dist/primitives/elicitation/McpElicitationPrimitiveAccept.js.map +1 -1
  77. package/dist/primitives/elicitation/McpElicitationPrimitiveCancel.d.ts +4 -6
  78. package/dist/primitives/elicitation/McpElicitationPrimitiveCancel.d.ts.map +1 -1
  79. package/dist/primitives/elicitation/McpElicitationPrimitiveCancel.js +2 -2
  80. package/dist/primitives/elicitation/McpElicitationPrimitiveCancel.js.map +1 -1
  81. package/dist/primitives/elicitation/McpElicitationPrimitiveDecline.d.ts +4 -6
  82. package/dist/primitives/elicitation/McpElicitationPrimitiveDecline.d.ts.map +1 -1
  83. package/dist/primitives/elicitation/McpElicitationPrimitiveDecline.js +2 -2
  84. package/dist/primitives/elicitation/McpElicitationPrimitiveDecline.js.map +1 -1
  85. package/dist/primitives/elicitation/McpElicitationPrimitiveError.d.ts +4 -6
  86. package/dist/primitives/elicitation/McpElicitationPrimitiveError.d.ts.map +1 -1
  87. package/dist/primitives/elicitation/McpElicitationPrimitiveError.js +1 -1
  88. package/dist/primitives/elicitation/McpElicitationPrimitiveError.js.map +1 -1
  89. package/dist/primitives/elicitation/McpElicitationPrimitiveFields.d.ts +6 -8
  90. package/dist/primitives/elicitation/McpElicitationPrimitiveFields.d.ts.map +1 -1
  91. package/dist/primitives/elicitation/McpElicitationPrimitiveFields.js +1 -1
  92. package/dist/primitives/elicitation/McpElicitationPrimitiveFields.js.map +1 -1
  93. package/dist/primitives/elicitation/McpElicitationPrimitiveItems.d.ts +6 -9
  94. package/dist/primitives/elicitation/McpElicitationPrimitiveItems.d.ts.map +1 -1
  95. package/dist/primitives/elicitation/McpElicitationPrimitiveItems.js +2 -2
  96. package/dist/primitives/elicitation/McpElicitationPrimitiveItems.js.map +1 -1
  97. package/dist/primitives/elicitation/McpElicitationPrimitiveMessage.d.ts +4 -6
  98. package/dist/primitives/elicitation/McpElicitationPrimitiveMessage.d.ts.map +1 -1
  99. package/dist/primitives/elicitation/McpElicitationPrimitiveMessage.js +1 -1
  100. package/dist/primitives/elicitation/McpElicitationPrimitiveMessage.js.map +1 -1
  101. package/dist/primitives/elicitation/McpElicitationPrimitiveRoot.d.ts +4 -6
  102. package/dist/primitives/elicitation/McpElicitationPrimitiveRoot.d.ts.map +1 -1
  103. package/dist/primitives/elicitation/McpElicitationPrimitiveRoot.js +1 -1
  104. package/dist/primitives/elicitation/McpElicitationPrimitiveRoot.js.map +1 -1
  105. package/dist/primitives/elicitation/context.d.ts +8 -10
  106. package/dist/primitives/elicitation/context.d.ts.map +1 -1
  107. package/dist/primitives/elicitation/initialElicitationDraft.d.ts +0 -2
  108. package/dist/primitives/elicitation/initialElicitationDraft.d.ts.map +1 -1
  109. package/dist/primitives/elicitation/prepareElicitationContent.d.ts +3 -5
  110. package/dist/primitives/elicitation/prepareElicitationContent.d.ts.map +1 -1
  111. package/dist/primitives/elicitation.d.ts +8 -14
  112. package/dist/primitives/elicitation.d.ts.map +1 -1
  113. package/dist/primitives/manager/McpManagerAddCustomTrigger.d.ts +4 -6
  114. package/dist/primitives/manager/McpManagerAddCustomTrigger.d.ts.map +1 -1
  115. package/dist/primitives/manager/McpManagerAddCustomTrigger.js +1 -1
  116. package/dist/primitives/manager/McpManagerAddCustomTrigger.js.map +1 -1
  117. package/dist/primitives/manager/McpManagerConnectors.d.ts +12 -14
  118. package/dist/primitives/manager/McpManagerConnectors.d.ts.map +1 -1
  119. package/dist/primitives/manager/McpManagerConnectors.js +1 -1
  120. package/dist/primitives/manager/McpManagerCustomServers.d.ts +12 -14
  121. package/dist/primitives/manager/McpManagerCustomServers.d.ts.map +1 -1
  122. package/dist/primitives/manager/McpManagerCustomServers.js +1 -1
  123. package/dist/primitives/manager/McpManagerRoot.d.ts +4 -6
  124. package/dist/primitives/manager/McpManagerRoot.d.ts.map +1 -1
  125. package/dist/primitives/manager/McpManagerRoot.js +2 -2
  126. package/dist/primitives/manager/McpManagerRoot.js.map +1 -1
  127. package/dist/primitives/manager.d.ts +4 -9
  128. package/dist/primitives/manager.d.ts.map +1 -1
  129. package/dist/primitives/server/McpServerConnectButton.d.ts +4 -6
  130. package/dist/primitives/server/McpServerConnectButton.d.ts.map +1 -1
  131. package/dist/primitives/server/McpServerConnectButton.js +2 -2
  132. package/dist/primitives/server/McpServerConnectButton.js.map +1 -1
  133. package/dist/primitives/server/McpServerDisconnectButton.d.ts +4 -6
  134. package/dist/primitives/server/McpServerDisconnectButton.d.ts.map +1 -1
  135. package/dist/primitives/server/McpServerDisconnectButton.js +2 -2
  136. package/dist/primitives/server/McpServerDisconnectButton.js.map +1 -1
  137. package/dist/primitives/server/McpServerError.d.ts +4 -6
  138. package/dist/primitives/server/McpServerError.d.ts.map +1 -1
  139. package/dist/primitives/server/McpServerError.js +2 -2
  140. package/dist/primitives/server/McpServerError.js.map +1 -1
  141. package/dist/primitives/server/McpServerIcon.d.ts +11 -13
  142. package/dist/primitives/server/McpServerIcon.d.ts.map +1 -1
  143. package/dist/primitives/server/McpServerIcon.js +2 -2
  144. package/dist/primitives/server/McpServerIcon.js.map +1 -1
  145. package/dist/primitives/server/McpServerName.d.ts +4 -6
  146. package/dist/primitives/server/McpServerName.d.ts.map +1 -1
  147. package/dist/primitives/server/McpServerName.js +2 -2
  148. package/dist/primitives/server/McpServerName.js.map +1 -1
  149. package/dist/primitives/server/McpServerOAuthLink.d.ts +9 -11
  150. package/dist/primitives/server/McpServerOAuthLink.d.ts.map +1 -1
  151. package/dist/primitives/server/McpServerOAuthLink.js +2 -2
  152. package/dist/primitives/server/McpServerOAuthLink.js.map +1 -1
  153. package/dist/primitives/server/McpServerRemoveButton.d.ts +4 -6
  154. package/dist/primitives/server/McpServerRemoveButton.d.ts.map +1 -1
  155. package/dist/primitives/server/McpServerRemoveButton.js +2 -2
  156. package/dist/primitives/server/McpServerRemoveButton.js.map +1 -1
  157. package/dist/primitives/server/McpServerRoot.d.ts +4 -6
  158. package/dist/primitives/server/McpServerRoot.d.ts.map +1 -1
  159. package/dist/primitives/server/McpServerRoot.js +2 -2
  160. package/dist/primitives/server/McpServerRoot.js.map +1 -1
  161. package/dist/primitives/server/McpServerStatus.d.ts +4 -6
  162. package/dist/primitives/server/McpServerStatus.d.ts.map +1 -1
  163. package/dist/primitives/server/McpServerStatus.js +2 -2
  164. package/dist/primitives/server/McpServerStatus.js.map +1 -1
  165. package/dist/primitives/server/McpServerToolName.d.ts +4 -6
  166. package/dist/primitives/server/McpServerToolName.d.ts.map +1 -1
  167. package/dist/primitives/server/McpServerToolName.js +1 -1
  168. package/dist/primitives/server/McpServerToolName.js.map +1 -1
  169. package/dist/primitives/server/McpServerTools.d.ts +5 -7
  170. package/dist/primitives/server/McpServerTools.d.ts.map +1 -1
  171. package/dist/primitives/server/McpServerTools.js +2 -2
  172. package/dist/primitives/server/McpServerTools.js.map +1 -1
  173. package/dist/primitives/server.d.ts +11 -16
  174. package/dist/primitives/server.d.ts.map +1 -1
  175. package/dist/resources/McpManagerResource.d.ts +11 -13
  176. package/dist/resources/McpManagerResource.d.ts.map +1 -1
  177. package/dist/resources/McpManagerResource.js +2 -2
  178. package/dist/resources/McpManagerResource.js.map +1 -1
  179. package/dist/resources/McpServerRemovalFence.d.ts +1 -3
  180. package/dist/resources/McpServerRemovalFence.d.ts.map +1 -1
  181. package/dist/resources/McpServerResource.d.ts +18 -20
  182. package/dist/resources/McpServerResource.d.ts.map +1 -1
  183. package/dist/resources/McpServerResource.js +51 -43
  184. package/dist/resources/McpServerResource.js.map +1 -1
  185. package/dist/resources/storage/McpCustomStorage.d.ts +1 -3
  186. package/dist/resources/storage/McpCustomStorage.d.ts.map +1 -1
  187. package/dist/resources/storage/McpLocalStorage.d.ts +14 -16
  188. package/dist/resources/storage/McpLocalStorage.d.ts.map +1 -1
  189. package/dist/resources/storage/McpLocalStorage.js +1 -1
  190. package/dist/resources/storage/McpLocalStorage.js.map +1 -1
  191. package/dist/resources/storage/McpMemoryStorage.d.ts +1 -3
  192. package/dist/resources/storage/McpMemoryStorage.d.ts.map +1 -1
  193. package/dist/resources/storage/types.d.ts +22 -24
  194. package/dist/resources/storage/types.d.ts.map +1 -1
  195. package/dist/resources/validateElicitationContent.d.ts +3 -4
  196. package/dist/resources/validateElicitationContent.d.ts.map +1 -1
  197. package/dist/utils/createMcpId.d.ts +0 -2
  198. package/dist/utils/createMcpId.d.ts.map +1 -1
  199. package/dist/utils/invokeMcpCallback.d.ts +0 -2
  200. package/dist/utils/invokeMcpCallback.d.ts.map +1 -1
  201. package/dist/utils/serverId.d.ts +0 -2
  202. package/dist/utils/serverId.d.ts.map +1 -1
  203. package/dist/utils/serverUrl.d.ts +1 -3
  204. package/dist/utils/serverUrl.d.ts.map +1 -1
  205. package/package.json +12 -9
  206. package/src/resources/McpServerResource.test.ts +112 -0
  207. package/src/resources/McpServerResource.ts +22 -7
@@ -1 +1 @@
1
- {"version":3,"file":"McpServerResource.js","names":["useState","useRef","useEffect","useMemo","useEffectEvent","resource","useResource","withKey","ClientOutput","shallowEqual","Client","StreamableHTTPClientTransport","UnauthorizedError","ClientOptions","ElicitRequest","ElicitResult","StreamableHTTPClientTransportOptions","clearOAuthProviderAuthState","createOAuthProvider","hasUsableOAuthTokens","buildHeaders","assertValidServerId","hasPersistedCredentials","isAuthStateForServerUrl","validateElicitationContent","MCPStorage","MCPAuthConfig","MCPConnectionState","MCPElicitation","MCPElicitationResponse","MCPServerKind","MCPServerState","MCPToolInfo","createMcpId","beginMcpServerRemovalFence","McpServerResourceProps","id","kind","name","url","icon","auth","storage","redirectUri","autoConnect","connectionTimeout","cache","defaultTtlMs","elicitation","onRemove","Promise","McpServerResourceInstanceProps","transportCloseQueueRef","current","getConnectionDependencies","props","authDependencies","type","token","scopeId","scopes","length","authorizationEndpoint","tokenEndpoint","registrationEndpoint","clientId","clientSecret","useMcpServerResourceInstance","connectionState","setConnectionState","tools","setTools","lastError","setLastError","message","authorizationUrl","setAuthorizationUrl","pendingElicitations","setPendingElicitations","clientRef","transportRef","pendingTransportRef","connectionGenerationRef","pendingAuthValidationRef","count","promise","resolve","elicitationResolversRef","Map","result","signal","AbortSignal","onAbort","requestedSchema","pendingDisposalRef","cancelled","mountedRef","closeTransportSafely","transport","close","closeQueuedTransports","transports","task","then","all","map","closePendingTransport","resolvePendingElicitation","entry","get","delete","removeEventListener","filter","setPendingElicitationError","error","NonNullable","has","cancelPendingElicitations","action","detachTransports","pendingTransport","activeTransport","Set","closeTransports","isCurrentConnection","generation","createInterruptedAuthError","cause","Error","undefined","withConnectionTimeout","T","phase","startedAt","timeoutMs","remainingMs","Date","now","timeoutError","timeout","ReturnType","setTimeout","race","_","reject","clearTimeout","unboundAuthMessage","loadAuthState","state","unbound","buildTransport","authProvider","serverId","serverUrl","config","onAuthorizationUrl","toString","URL","headers","transportOpts","requestInit","applyToolsList","list","Array","description","inputSchema","t","info","syncTools","client","options","listPromise","listTools","finalizeConnect","clientOptions","capabilities","listChanged","autoRefresh","debounceMs","onChanged","items","defaultCacheTtlMs","version","setRequestHandler","request","context","params","set","mcpReq","aborted","addEventListener","once","connect","synced","doConnect","err","String","doDisconnect","doCompleteAuth","callbackUrl","validationGeneration","searchParams","pendingAuthValidation","resolvePromise","persisted","finishAuth","connected","tryAutoConnect","loaded","Awaited","previousDisposal","pendingDisposal","queueMicrotask","getState","disconnect","remove","releaseRemovalFence","callTool","args","arguments","Record","listResources","readResource","uri","completeAuth","answerElicitation","response","property","content","isArray","errors","properties","join","McpServerResourceInstance","McpServerResource","useMcpServerResource","dependencies","connection","setConnection","currentConnection"],"sources":["../../src/resources/McpServerResource.ts"],"sourcesContent":["import { useState, useRef, useEffect, useMemo, useEffectEvent } from \"react\";\nimport { resource, useResource, withKey } from \"@assistant-ui/tap\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport { shallowEqual } from \"@assistant-ui/store/internal\";\nimport {\n Client,\n StreamableHTTPClientTransport,\n UnauthorizedError,\n type ClientOptions,\n type ElicitRequest,\n type ElicitResult,\n type StreamableHTTPClientTransportOptions,\n} from \"@modelcontextprotocol/client\";\nimport {\n clearOAuthProviderAuthState,\n createOAuthProvider,\n hasUsableOAuthTokens,\n} from \"../auth/createOAuthProvider\";\nimport { buildHeaders } from \"../auth/buildHeaders\";\nimport { assertValidServerId } from \"../utils/serverId\";\nimport {\n hasPersistedCredentials,\n isAuthStateForServerUrl,\n} from \"../utils/serverUrl\";\nimport { validateElicitationContent } from \"./validateElicitationContent\";\nimport type { MCPStorage } from \"./storage/types\";\nimport type {\n MCPAuthConfig,\n MCPConnectionState,\n MCPElicitation,\n MCPElicitationResponse,\n MCPServerKind,\n MCPServerState,\n MCPToolInfo,\n} from \"../mcp-scope\";\nimport { createMcpId } from \"../utils/createMcpId\";\nimport { beginMcpServerRemovalFence } from \"./McpServerRemovalFence\";\n\nexport type McpServerResourceProps = {\n id: string;\n kind: MCPServerKind;\n name: string;\n url: string;\n icon?: string | undefined;\n auth: MCPAuthConfig;\n storage: MCPStorage;\n redirectUri: string;\n autoConnect: boolean;\n connectionTimeout?: number | undefined;\n cache?: { readonly defaultTtlMs?: number } | undefined;\n readonly elicitation?: boolean;\n onRemove: () => Promise<void>;\n};\n\ntype McpServerResourceInstanceProps = McpServerResourceProps & {\n transportCloseQueueRef: { current: Promise<void> };\n};\n\nexport const getConnectionDependencies = (\n props: McpServerResourceProps,\n): readonly unknown[] => {\n const auth = props.auth;\n const authDependencies =\n auth.type === \"bearer\"\n ? [auth.type, auth.token, props.storage.scopeId]\n : auth.type === \"oauth\"\n ? [\n auth.type,\n auth.scopes?.length,\n ...(auth.scopes ?? []),\n auth.authorizationEndpoint,\n auth.tokenEndpoint,\n auth.registrationEndpoint,\n auth.clientId,\n auth.clientSecret,\n props.storage.scopeId,\n ]\n : [auth.type];\n\n return [\n props.id,\n props.url,\n ...authDependencies,\n props.redirectUri,\n props.cache?.defaultTtlMs,\n props.elicitation !== false,\n ];\n};\n\nconst useMcpServerResourceInstance = (\n props: McpServerResourceInstanceProps,\n): ClientOutput<\"mcpServer\"> => {\n assertValidServerId(props.id);\n const [connectionState, setConnectionState] =\n useState<MCPConnectionState>(\"disconnected\");\n const [tools, setTools] = useState<MCPToolInfo[]>([]);\n const [lastError, setLastError] = useState<{ message: string } | null>(null);\n const [authorizationUrl, setAuthorizationUrl] = useState<string | null>(null);\n const [pendingElicitations, setPendingElicitations] = useState<\n MCPElicitation[]\n >([]);\n\n const clientRef = useRef<Client | null>(null);\n const transportRef = useRef<StreamableHTTPClientTransport | null>(null);\n const pendingTransportRef = useRef<StreamableHTTPClientTransport | null>(\n null,\n );\n const connectionGenerationRef = useRef(0);\n const pendingAuthValidationRef = useRef<{\n count: number;\n promise: Promise<void>;\n resolve: () => void;\n } | null>(null);\n const elicitationResolversRef = useRef(\n new Map<\n string,\n {\n resolve: (result: ElicitResult) => void;\n signal: AbortSignal;\n onAbort: () => void;\n requestedSchema: unknown;\n }\n >(),\n );\n const pendingDisposalRef = useRef<{ cancelled: boolean } | null>(null);\n const mountedRef = useRef(true);\n\n const closeTransportSafely = async (\n transport: StreamableHTTPClientTransport,\n ): Promise<void> => {\n try {\n await transport.close();\n } catch {\n // ignore close errors\n }\n };\n\n const closeQueuedTransports = (\n transports: StreamableHTTPClientTransport[],\n ): Promise<void> => {\n const task = props.transportCloseQueueRef.current.then(async () => {\n await Promise.all(transports.map(closeTransportSafely));\n });\n props.transportCloseQueueRef.current = task;\n return task;\n };\n\n const closePendingTransport = async () => {\n const transport = pendingTransportRef.current;\n pendingTransportRef.current = null;\n await closeQueuedTransports(transport ? [transport] : []);\n };\n\n const resolvePendingElicitation = (id: string, result: ElicitResult) => {\n const entry = elicitationResolversRef.current.get(id);\n if (!entry) return false;\n elicitationResolversRef.current.delete(id);\n entry.signal.removeEventListener(\"abort\", entry.onAbort);\n setPendingElicitations((current) =>\n current.filter((elicitation) => elicitation.id !== id),\n );\n entry.resolve(result);\n return true;\n };\n\n const setPendingElicitationError = (\n id: string,\n error: NonNullable<MCPElicitation[\"error\"]>,\n ) => {\n if (!elicitationResolversRef.current.has(id)) return false;\n setPendingElicitations((current) =>\n current.map((elicitation) =>\n elicitation.id === id ? { ...elicitation, error } : elicitation,\n ),\n );\n return true;\n };\n\n const cancelPendingElicitations = () => {\n for (const [id] of elicitationResolversRef.current) {\n resolvePendingElicitation(id, { action: \"cancel\" });\n }\n };\n\n const detachTransports = () => {\n cancelPendingElicitations();\n const pendingTransport = pendingTransportRef.current;\n const activeTransport = transportRef.current;\n pendingTransportRef.current = null;\n transportRef.current = null;\n clientRef.current = null;\n\n return [\n ...new Set(\n [pendingTransport, activeTransport].filter(\n (transport): transport is StreamableHTTPClientTransport =>\n transport !== null,\n ),\n ),\n ];\n };\n\n const closeTransports = async () => {\n await closeQueuedTransports(detachTransports());\n };\n\n const isCurrentConnection = (generation: number) =>\n mountedRef.current && generation === connectionGenerationRef.current;\n\n const createInterruptedAuthError = (cause?: unknown) =>\n new Error(\n `MCP server \"${props.id}\" authorization was interrupted before completion.`,\n cause === undefined ? undefined : { cause },\n );\n\n const withConnectionTimeout = useEffectEvent(\n async <T>(\n promise: Promise<T>,\n phase: \"connecting\" | \"listing tools\",\n startedAt: number,\n ): Promise<T> => {\n const timeoutMs = props.connectionTimeout;\n if (timeoutMs === undefined) return await promise;\n const remainingMs = timeoutMs - (Date.now() - startedAt);\n const timeoutError = () =>\n new Error(\n `MCP server \"${props.id}\" timed out while ${phase} after ${timeoutMs}ms.`,\n );\n if (remainingMs <= 0) throw timeoutError();\n\n let timeout: ReturnType<typeof setTimeout> | undefined;\n try {\n return await Promise.race([\n promise,\n new Promise<never>((_, reject) => {\n timeout = setTimeout(() => reject(timeoutError()), remainingMs);\n }),\n ]);\n } finally {\n if (timeout !== undefined) clearTimeout(timeout);\n }\n },\n );\n\n const unboundAuthMessage = () =>\n `MCP server \"${props.id}\" has saved authentication for a different URL. Authenticate again to connect to ${props.url}.`;\n\n const loadAuthState = useEffectEvent(async () => {\n const state = await props.storage.loadAuthState(props.id);\n if (isAuthStateForServerUrl(state, props.url)) {\n return { state, unbound: false };\n }\n return { state: null, unbound: hasPersistedCredentials(state) };\n });\n\n const buildTransport = useEffectEvent(\n async (): Promise<StreamableHTTPClientTransport> => {\n if (props.auth.type === \"oauth\") {\n const authProvider = createOAuthProvider({\n serverId: props.id,\n serverUrl: props.url,\n config: props.auth,\n storage: props.storage,\n redirectUri: props.redirectUri,\n onAuthorizationUrl: (url) => setAuthorizationUrl(url.toString()),\n });\n return new StreamableHTTPClientTransport(new URL(props.url), {\n authProvider,\n });\n }\n if (props.auth.type === \"bearer\") {\n const { state, unbound } = await loadAuthState();\n const headers = buildHeaders(props.auth, state);\n if (!headers && unbound) throw new Error(unboundAuthMessage());\n const transportOpts: StreamableHTTPClientTransportOptions = {};\n if (headers) transportOpts.requestInit = { headers };\n return new StreamableHTTPClientTransport(\n new URL(props.url),\n transportOpts,\n );\n }\n return new StreamableHTTPClientTransport(new URL(props.url));\n },\n );\n\n const applyToolsList = useEffectEvent(\n (list: {\n tools: Array<{\n name: string;\n description?: string | undefined;\n inputSchema: unknown;\n }>;\n }) => {\n setTools(\n list.tools.map((t) => {\n const info: MCPToolInfo = {\n name: t.name,\n inputSchema: t.inputSchema,\n };\n if (t.description !== undefined) info.description = t.description;\n return info;\n }),\n );\n },\n );\n\n const syncTools = useEffectEvent(\n async (\n client: Client,\n generation: number,\n options?: { startedAt?: number | undefined },\n ): Promise<boolean> => {\n const listPromise = client.listTools();\n const list =\n options?.startedAt === undefined\n ? await listPromise\n : await withConnectionTimeout(\n listPromise,\n \"listing tools\",\n options.startedAt,\n );\n if (!isCurrentConnection(generation)) return false;\n applyToolsList(list);\n return true;\n },\n );\n\n const finalizeConnect = useEffectEvent(\n async (\n transport: StreamableHTTPClientTransport,\n generation: number,\n ): Promise<boolean> => {\n const clientOptions: ClientOptions = {\n ...(props.elicitation === false\n ? {}\n : { capabilities: { elicitation: {} } }),\n listChanged: {\n tools: {\n autoRefresh: true,\n debounceMs: 300,\n onChanged: (error, items) => {\n if (!isCurrentConnection(generation)) return;\n if (error !== null) {\n setLastError({ message: error.message });\n return;\n }\n if (items === null) return;\n setLastError(null);\n applyToolsList({ tools: items });\n },\n },\n },\n };\n if (props.cache?.defaultTtlMs !== undefined) {\n clientOptions.defaultCacheTtlMs = props.cache.defaultTtlMs;\n }\n const client = new Client(\n {\n name: \"assistant-ui-mcp\",\n version: \"0.0.0\",\n },\n clientOptions,\n );\n if (props.elicitation !== false) {\n client.setRequestHandler(\n \"elicitation/create\",\n (request: ElicitRequest, context): Promise<ElicitResult> => {\n if (!isCurrentConnection(generation)) {\n return Promise.resolve({ action: \"cancel\" });\n }\n if (!(\"requestedSchema\" in request.params)) {\n return Promise.resolve({ action: \"cancel\" });\n }\n const { message, requestedSchema } = request.params;\n\n const id = createMcpId();\n const promise = new Promise<ElicitResult>((resolve) => {\n const onAbort = () => {\n resolvePendingElicitation(id, { action: \"cancel\" });\n };\n elicitationResolversRef.current.set(id, {\n resolve,\n signal: context.mcpReq.signal,\n onAbort,\n requestedSchema,\n });\n });\n setPendingElicitations((current) => [\n ...current,\n {\n id,\n message,\n requestedSchema,\n },\n ]);\n const entry = elicitationResolversRef.current.get(id);\n if (entry) {\n if (context.mcpReq.signal.aborted) {\n entry.onAbort();\n } else {\n context.mcpReq.signal.addEventListener(\"abort\", entry.onAbort, {\n once: true,\n });\n }\n }\n return promise;\n },\n );\n }\n const startedAt = Date.now();\n await withConnectionTimeout(\n client.connect(transport),\n \"connecting\",\n startedAt,\n );\n if (!isCurrentConnection(generation)) return false;\n // Defer ref assignment until listTools() also succeeds — otherwise a\n // post-connect failure leaves stale refs that `callTool()` would\n // happily walk into, producing confusing SDK errors instead of\n // \"not connected\".\n const synced = await syncTools(client, generation, { startedAt });\n if (!synced) return false;\n\n pendingTransportRef.current = null;\n clientRef.current = client;\n transportRef.current = transport;\n setConnectionState(\"connected\");\n return true;\n },\n );\n\n const doConnect = useEffectEvent(async () => {\n const generation = ++connectionGenerationRef.current;\n // Close any prior transport/client so a re-connect doesn't leak.\n await closeTransports();\n if (!isCurrentConnection(generation)) return;\n\n setConnectionState(\"connecting\");\n setLastError(null);\n setAuthorizationUrl(null);\n // Clear tools so a reconnect (error → connect, or authRequired\n // → connect) doesn't expose the previous attempt's tool list.\n setTools([]);\n let transport: StreamableHTTPClientTransport | null = null;\n try {\n transport = await buildTransport();\n if (!isCurrentConnection(generation)) {\n await closeQueuedTransports([transport]);\n return;\n }\n pendingTransportRef.current = transport;\n // Don't assign to transportRef until connect succeeds — otherwise a\n // failed `listTools()` leaves an orphaned transport that future\n // doConnect / doDisconnect calls treat as live.\n await finalizeConnect(transport, generation);\n } catch (err) {\n if (!isCurrentConnection(generation)) return;\n\n if (err instanceof UnauthorizedError) {\n // OAuth: keep the transport alive so completeAuth can call\n // finishAuth on it. Closing it before storing would leave a\n // closed transport on transportRef.\n pendingTransportRef.current = null;\n transportRef.current = transport;\n setConnectionState(\"authRequired\");\n } else {\n cancelPendingElicitations();\n if (transport) {\n pendingTransportRef.current = null;\n await closeQueuedTransports([transport]);\n }\n setLastError({\n message: err instanceof Error ? err.message : String(err),\n });\n setConnectionState(\"error\");\n }\n }\n });\n\n const doDisconnect = useEffectEvent(async () => {\n connectionGenerationRef.current += 1;\n setTools([]);\n setAuthorizationUrl(null);\n setConnectionState(\"disconnected\");\n await closeTransports();\n });\n\n const doCompleteAuth = useEffectEvent(async (callbackUrl: string) => {\n const validationGeneration = connectionGenerationRef.current;\n const url = new URL(callbackUrl);\n const state = url.searchParams.get(\"state\");\n if (!state) throw new Error('missing \"state\" parameter');\n let pendingAuthValidation = pendingAuthValidationRef.current;\n if (!pendingAuthValidation) {\n let resolve!: () => void;\n const promise = new Promise<void>((resolvePromise) => {\n resolve = resolvePromise;\n });\n pendingAuthValidation = { count: 0, promise, resolve };\n pendingAuthValidationRef.current = pendingAuthValidation;\n }\n pendingAuthValidation.count += 1;\n try {\n const { state: persisted, unbound } = await loadAuthState();\n if (!isCurrentConnection(validationGeneration)) {\n throw createInterruptedAuthError();\n }\n if (unbound) throw new Error(unboundAuthMessage());\n if (!persisted?.state) {\n throw new Error(\n \"no pending OAuth authorization request for this server\",\n );\n }\n if (persisted.state !== state) {\n throw new Error(\"OAuth state does not match the authorization request\");\n }\n if (!url.searchParams.get(\"code\") && !url.searchParams.get(\"error\")) {\n throw new Error(\"missing authorization code in callback URL\");\n }\n } finally {\n pendingAuthValidation.count -= 1;\n if (pendingAuthValidation.count === 0) {\n pendingAuthValidationRef.current = null;\n pendingAuthValidation.resolve();\n }\n }\n\n // Claim the generation before a waiting auto-connect can resume.\n const generation = ++connectionGenerationRef.current;\n cancelPendingElicitations();\n await closePendingTransport();\n if (!isCurrentConnection(generation)) throw createInterruptedAuthError();\n\n setConnectionState(\"authPending\");\n setLastError(null);\n try {\n let transport = transportRef.current;\n if (!transport) {\n transport = await buildTransport();\n if (!isCurrentConnection(generation)) {\n await closeQueuedTransports([transport]);\n throw createInterruptedAuthError();\n }\n }\n transportRef.current = null;\n clientRef.current = null;\n pendingTransportRef.current = transport;\n await transport.finishAuth(url.searchParams);\n if (!isCurrentConnection(generation)) throw createInterruptedAuthError();\n setAuthorizationUrl(null);\n const connected = await finalizeConnect(transport, generation);\n if (!connected) throw createInterruptedAuthError();\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n if (!isCurrentConnection(generation))\n throw createInterruptedAuthError(error);\n\n await closeTransports();\n setLastError({\n message: error.message,\n });\n setConnectionState(\"error\");\n throw error;\n }\n });\n\n const tryAutoConnect = useEffectEvent(\n async (signal: { cancelled: boolean }) => {\n if (!props.autoConnect) return;\n if (props.auth.type === \"none\") {\n void doConnect();\n return;\n }\n // Static connector token short-circuits the storage read.\n if (props.auth.type === \"bearer\" && props.auth.token) {\n void doConnect();\n return;\n }\n const generation = connectionGenerationRef.current;\n let loaded: Awaited<ReturnType<typeof loadAuthState>>;\n try {\n loaded = await loadAuthState();\n } catch (error) {\n if (signal.cancelled || !isCurrentConnection(generation)) return;\n const message = error instanceof Error ? error.message : String(error);\n setLastError({\n message: `MCP server \"${props.id}\" failed to load saved authentication: ${message}`,\n });\n setConnectionState(\"error\");\n return;\n }\n if (signal.cancelled || !isCurrentConnection(generation)) return;\n if (loaded.unbound) {\n setLastError({ message: unboundAuthMessage() });\n return;\n }\n const persisted = loaded.state;\n if (props.auth.type === \"oauth\") {\n if (!hasUsableOAuthTokens(persisted, props.auth)) return;\n } else if (!persisted?.token) {\n return;\n }\n const pendingAuthValidation = pendingAuthValidationRef.current;\n if (pendingAuthValidation) {\n await pendingAuthValidation.promise;\n if (signal.cancelled || !isCurrentConnection(generation)) return;\n }\n void doConnect();\n },\n );\n\n // Auto-connect on mount when usable auth exists.\n useEffect(() => {\n const transportCloseQueueRef = props.transportCloseQueueRef;\n const previousDisposal = pendingDisposalRef.current;\n if (previousDisposal) previousDisposal.cancelled = true;\n const pendingDisposal = { cancelled: false };\n pendingDisposalRef.current = pendingDisposal;\n mountedRef.current = true;\n const signal = { cancelled: false };\n // Auto-connect opens a transport, so it belongs to the same effect as the\n // disposal that closes it.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n void tryAutoConnect(signal);\n return () => {\n mountedRef.current = false;\n signal.cancelled = true;\n const task = transportCloseQueueRef.current.then(async () => {\n await new Promise<void>((resolve) => queueMicrotask(resolve));\n if (pendingDisposal.cancelled) return;\n connectionGenerationRef.current += 1;\n await Promise.all(detachTransports().map(closeTransportSafely));\n });\n transportCloseQueueRef.current = task;\n };\n }, [props.transportCloseQueueRef]);\n\n const state = useMemo<MCPServerState>(\n () => ({\n id: props.id,\n kind: props.kind,\n name: props.name,\n url: props.url,\n icon: props.icon,\n connectionState,\n lastError,\n tools,\n authorizationUrl,\n pendingElicitations,\n }),\n [\n props.id,\n props.kind,\n props.name,\n props.url,\n props.icon,\n connectionState,\n lastError,\n tools,\n authorizationUrl,\n pendingElicitations,\n ],\n );\n\n return {\n getState: () => state,\n connect: doConnect,\n disconnect: doDisconnect,\n remove: async () => {\n const releaseRemovalFence = beginMcpServerRemovalFence(props);\n try {\n await doDisconnect();\n await clearOAuthProviderAuthState(props.storage, props.id);\n await props.onRemove();\n } catch (err) {\n releaseRemovalFence?.();\n setLastError({\n message: err instanceof Error ? err.message : String(err),\n });\n throw err;\n }\n releaseRemovalFence?.();\n },\n callTool: async (name, args) => {\n const client = clientRef.current;\n if (!client) {\n throw new Error(`MCP server \"${props.id}\" is not connected`);\n }\n return await client.callTool({\n name,\n arguments: args as Record<string, unknown> | undefined,\n });\n },\n listResources: async (params) => {\n const client = clientRef.current;\n if (!client) {\n throw new Error(`MCP server \"${props.id}\" is not connected`);\n }\n return await client.listResources(params);\n },\n readResource: async (uri) => {\n const client = clientRef.current;\n if (!client) {\n throw new Error(`MCP server \"${props.id}\" is not connected`);\n }\n return await client.readResource({ uri });\n },\n completeAuth: doCompleteAuth,\n answerElicitation: (\n id: string,\n response: MCPElicitationResponse,\n ): readonly { property: string; message: string }[] | undefined => {\n if (response.action === \"accept\") {\n const entry = elicitationResolversRef.current.get(id);\n if (!entry) return undefined;\n\n if (\n typeof response.content !== \"object\" ||\n response.content === null ||\n Array.isArray(response.content)\n ) {\n const errors = [\n {\n property: \"content\",\n message: \"Response content must be an object.\",\n },\n ];\n setPendingElicitationError(id, {\n message: \"Invalid elicitation content: content.\",\n properties: [\"content\"],\n });\n return errors;\n }\n\n const errors = validateElicitationContent(\n entry.requestedSchema,\n response.content,\n );\n if (errors.length > 0) {\n const properties = [\n ...new Set(errors.map((error) => error.property)),\n ];\n setPendingElicitationError(id, {\n message: `Invalid elicitation content: ${properties.join(\", \")}.`,\n properties,\n });\n return errors;\n }\n\n const result: ElicitResult = {\n action: \"accept\",\n content: response.content as ElicitResult[\"content\"],\n };\n resolvePendingElicitation(id, result);\n return undefined;\n }\n\n resolvePendingElicitation(id, { action: response.action });\n return undefined;\n },\n };\n};\n\nconst McpServerResourceInstance = resource(useMcpServerResourceInstance);\n\nexport const McpServerResource = resource(function useMcpServerResource(\n props: McpServerResourceProps,\n): ClientOutput<\"mcpServer\"> {\n const transportCloseQueueRef = useRef(Promise.resolve());\n const dependencies = getConnectionDependencies(props);\n const [connection, setConnection] = useState({ dependencies, generation: 0 });\n let currentConnection = connection;\n if (!shallowEqual(connection.dependencies, dependencies)) {\n currentConnection = {\n dependencies,\n generation: connection.generation + 1,\n };\n setConnection(currentConnection);\n }\n\n // Storage keys remounts through its optional scopeId rather than object\n // identity, because a defaulted storage element is rebuilt on ordinary\n // renders.\n return useResource(\n withKey(\n currentConnection.generation,\n McpServerResourceInstance({ ...props, transportCloseQueueRef }),\n ),\n );\n});\n"],"mappings":";;;;;;;;;;;;AA0DA,MAAasD,6BACXC,UACuB;CACvB,MAAMd,OAAOc,MAAMd;CACnB,MAAMe,mBACJf,KAAKgB,SAAS,WACV;EAAChB,KAAKgB;EAAMhB,KAAKiB;EAAOH,MAAMb,QAAQiB;CAAO,IAC7ClB,KAAKgB,SAAS,UACZ;EACEhB,KAAKgB;EACLhB,KAAKmB,QAAQC;EACb,GAAIpB,KAAKmB,UAAU,CAAA;EACn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QAAQ,CAAC,CAAC;KAEnDlH,2BAA2B7E,MAAI;MAC7BsC,SAAS,gCAAgC6J,WAAWC,KAAK,IAAI,EAAC;MAC9DD;KACF,CAAC;KACD,OAAOD;IACT;IAEA,MAAM7I,WAAuB;KAC3B6B,QAAQ;KACR8G,SAASF,SAASE;IACpB;IACAzH,0BAA0BvE,MAAIqD,QAAM;IACpC;GACF;GAEAkB,0BAA0BvE,MAAI,EAAEkF,QAAQ4G,SAAS5G,OAAO,CAAC;EAE3D;CACF;AACF;AAEA,MAAMmH,4BAA4BpO,SAAS8D,4BAA4B;AAEvE,MAAauK,oBAAoBrO,SAAS,SAASsO,qBACjDpL,OAC2B;CAC3B,MAAMH,yBAAyBnD,OAAOiD,QAAQoC,QAAQ,CAAC;CACvD,MAAMsJ,eAAetL,0BAA0BC,KAAK;CACpD,MAAM,CAACsL,YAAYC,iBAAiB9O,SAAS;EAAE4O;EAAc/G,YAAY;CAAE,CAAC;CAC5E,IAAIkH,oBAAoBF;CACxB,IAAI,CAACpO,aAAaoO,WAAWD,cAAcA,YAAY,GAAG;EACxDG,oBAAoB;GAClBH;GACA/G,YAAYgH,WAAWhH,aAAa;EACtC;EACAiH,cAAcC,iBAAiB;CACjC;CAKA,OAAOzO,YACLC,QACEwO,kBAAkBlH,YAClB4G,0BAA0B;EAAE,GAAGlL;EAAOH;CAAuB,CAAC,CAChE,CACF;AACF,CAAC"}
1
+ {"version":3,"file":"McpServerResource.js","names":["useState","useRef","useEffect","useMemo","useEffectEvent","resource","useResource","withKey","ClientOutput","shallowEqual","Client","StreamableHTTPClientTransport","UnauthorizedError","ClientOptions","ElicitRequest","ElicitResult","StreamableHTTPClientTransportOptions","clearOAuthProviderAuthState","createOAuthProvider","hasUsableOAuthTokens","buildHeaders","assertValidServerId","hasPersistedCredentials","isAuthStateForServerUrl","validateElicitationContent","MCPStorage","MCPAuthConfig","MCPConnectionState","MCPElicitation","MCPElicitationResponse","MCPServerKind","MCPServerState","MCPToolInfo","createMcpId","beginMcpServerRemovalFence","McpServerResourceProps","id","kind","name","url","icon","auth","storage","redirectUri","autoConnect","connectionTimeout","cache","defaultTtlMs","elicitation","onRemove","Promise","McpServerResourceInstanceProps","transportCloseQueueRef","current","getConnectionDependencies","props","authDependencies","type","token","scopeId","scopes","length","authorizationEndpoint","tokenEndpoint","registrationEndpoint","clientId","clientSecret","useMcpServerResourceInstance","connectionState","setConnectionState","tools","setTools","lastError","setLastError","message","authorizationUrl","setAuthorizationUrl","pendingElicitations","setPendingElicitations","clientRef","transportRef","pendingTransportRef","transportGenerationRef","WeakMap","connectionGenerationRef","pendingAuthValidationRef","count","promise","resolve","elicitationResolversRef","Map","result","signal","AbortSignal","onAbort","requestedSchema","pendingDisposalRef","cancelled","mountedRef","closeTransportSafely","transport","close","closeQueuedTransports","transports","task","then","all","map","closePendingTransport","resolvePendingElicitation","entry","get","delete","removeEventListener","filter","setPendingElicitationError","error","NonNullable","has","cancelPendingElicitations","action","detachTransports","pendingTransport","activeTransport","Set","closeTransports","isCurrentConnection","generation","createInterruptedAuthError","cause","Error","undefined","withConnectionTimeout","T","phase","startedAt","timeoutMs","remainingMs","Date","now","timeoutError","timeout","ReturnType","setTimeout","race","_","reject","clearTimeout","unboundAuthMessage","loadAuthState","state","unbound","buildTransport","generationOwner","authProvider","serverId","serverUrl","config","onAuthorizationUrl","toString","URL","set","headers","transportOpts","requestInit","applyToolsList","list","Array","description","inputSchema","t","info","syncTools","client","options","listPromise","listTools","finalizeConnect","clientOptions","capabilities","listChanged","autoRefresh","debounceMs","onChanged","items","defaultCacheTtlMs","version","setRequestHandler","request","context","params","mcpReq","aborted","addEventListener","once","connect","synced","doConnect","err","String","doDisconnect","doCompleteAuth","callbackUrl","validationGeneration","searchParams","pendingAuthValidation","resolvePromise","persisted","finishAuth","connected","tryAutoConnect","loaded","Awaited","previousDisposal","pendingDisposal","queueMicrotask","getState","disconnect","remove","releaseRemovalFence","callTool","args","arguments","Record","listResources","readResource","uri","completeAuth","answerElicitation","response","property","content","isArray","errors","properties","join","McpServerResourceInstance","McpServerResource","useMcpServerResource","dependencies","connection","setConnection","currentConnection"],"sources":["../../src/resources/McpServerResource.ts"],"sourcesContent":["import { useState, useRef, useEffect, useMemo, useEffectEvent } from \"react\";\nimport { resource, useResource, withKey } from \"@assistant-ui/tap\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport { shallowEqual } from \"@assistant-ui/store/internal\";\nimport {\n Client,\n StreamableHTTPClientTransport,\n UnauthorizedError,\n type ClientOptions,\n type ElicitRequest,\n type ElicitResult,\n type StreamableHTTPClientTransportOptions,\n} from \"@modelcontextprotocol/client\";\nimport {\n clearOAuthProviderAuthState,\n createOAuthProvider,\n hasUsableOAuthTokens,\n} from \"../auth/createOAuthProvider\";\nimport { buildHeaders } from \"../auth/buildHeaders\";\nimport { assertValidServerId } from \"../utils/serverId\";\nimport {\n hasPersistedCredentials,\n isAuthStateForServerUrl,\n} from \"../utils/serverUrl\";\nimport { validateElicitationContent } from \"./validateElicitationContent\";\nimport type { MCPStorage } from \"./storage/types\";\nimport type {\n MCPAuthConfig,\n MCPConnectionState,\n MCPElicitation,\n MCPElicitationResponse,\n MCPServerKind,\n MCPServerState,\n MCPToolInfo,\n} from \"../mcp-scope\";\nimport { createMcpId } from \"../utils/createMcpId\";\nimport { beginMcpServerRemovalFence } from \"./McpServerRemovalFence\";\n\nexport type McpServerResourceProps = {\n id: string;\n kind: MCPServerKind;\n name: string;\n url: string;\n icon?: string | undefined;\n auth: MCPAuthConfig;\n storage: MCPStorage;\n redirectUri: string;\n autoConnect: boolean;\n connectionTimeout?: number | undefined;\n cache?: { readonly defaultTtlMs?: number } | undefined;\n readonly elicitation?: boolean;\n onRemove: () => Promise<void>;\n};\n\ntype McpServerResourceInstanceProps = McpServerResourceProps & {\n transportCloseQueueRef: { current: Promise<void> };\n};\n\nexport const getConnectionDependencies = (\n props: McpServerResourceProps,\n): readonly unknown[] => {\n const auth = props.auth;\n const authDependencies =\n auth.type === \"bearer\"\n ? [auth.type, auth.token, props.storage.scopeId]\n : auth.type === \"oauth\"\n ? [\n auth.type,\n auth.scopes?.length,\n ...(auth.scopes ?? []),\n auth.authorizationEndpoint,\n auth.tokenEndpoint,\n auth.registrationEndpoint,\n auth.clientId,\n auth.clientSecret,\n props.storage.scopeId,\n ]\n : [auth.type];\n\n return [\n props.id,\n props.url,\n ...authDependencies,\n props.redirectUri,\n props.cache?.defaultTtlMs,\n props.elicitation !== false,\n ];\n};\n\nconst useMcpServerResourceInstance = (\n props: McpServerResourceInstanceProps,\n): ClientOutput<\"mcpServer\"> => {\n assertValidServerId(props.id);\n const [connectionState, setConnectionState] =\n useState<MCPConnectionState>(\"disconnected\");\n const [tools, setTools] = useState<MCPToolInfo[]>([]);\n const [lastError, setLastError] = useState<{ message: string } | null>(null);\n const [authorizationUrl, setAuthorizationUrl] = useState<string | null>(null);\n const [pendingElicitations, setPendingElicitations] = useState<\n MCPElicitation[]\n >([]);\n\n const clientRef = useRef<Client | null>(null);\n const transportRef = useRef<StreamableHTTPClientTransport | null>(null);\n const pendingTransportRef = useRef<StreamableHTTPClientTransport | null>(\n null,\n );\n const transportGenerationRef = useRef(\n new WeakMap<StreamableHTTPClientTransport, { current: number }>(),\n );\n const connectionGenerationRef = useRef(0);\n const pendingAuthValidationRef = useRef<{\n count: number;\n promise: Promise<void>;\n resolve: () => void;\n } | null>(null);\n const elicitationResolversRef = useRef(\n new Map<\n string,\n {\n resolve: (result: ElicitResult) => void;\n signal: AbortSignal;\n onAbort: () => void;\n requestedSchema: unknown;\n }\n >(),\n );\n const pendingDisposalRef = useRef<{ cancelled: boolean } | null>(null);\n const mountedRef = useRef(true);\n\n const closeTransportSafely = async (\n transport: StreamableHTTPClientTransport,\n ): Promise<void> => {\n try {\n await transport.close();\n } catch {\n // ignore close errors\n }\n };\n\n const closeQueuedTransports = (\n transports: StreamableHTTPClientTransport[],\n ): Promise<void> => {\n const task = props.transportCloseQueueRef.current.then(async () => {\n await Promise.all(transports.map(closeTransportSafely));\n });\n props.transportCloseQueueRef.current = task;\n return task;\n };\n\n const closePendingTransport = async () => {\n const transport = pendingTransportRef.current;\n pendingTransportRef.current = null;\n await closeQueuedTransports(transport ? [transport] : []);\n };\n\n const resolvePendingElicitation = (id: string, result: ElicitResult) => {\n const entry = elicitationResolversRef.current.get(id);\n if (!entry) return false;\n elicitationResolversRef.current.delete(id);\n entry.signal.removeEventListener(\"abort\", entry.onAbort);\n setPendingElicitations((current) =>\n current.filter((elicitation) => elicitation.id !== id),\n );\n entry.resolve(result);\n return true;\n };\n\n const setPendingElicitationError = (\n id: string,\n error: NonNullable<MCPElicitation[\"error\"]>,\n ) => {\n if (!elicitationResolversRef.current.has(id)) return false;\n setPendingElicitations((current) =>\n current.map((elicitation) =>\n elicitation.id === id ? { ...elicitation, error } : elicitation,\n ),\n );\n return true;\n };\n\n const cancelPendingElicitations = () => {\n for (const [id] of elicitationResolversRef.current) {\n resolvePendingElicitation(id, { action: \"cancel\" });\n }\n };\n\n const detachTransports = () => {\n cancelPendingElicitations();\n const pendingTransport = pendingTransportRef.current;\n const activeTransport = transportRef.current;\n pendingTransportRef.current = null;\n transportRef.current = null;\n clientRef.current = null;\n\n return [\n ...new Set(\n [pendingTransport, activeTransport].filter(\n (transport): transport is StreamableHTTPClientTransport =>\n transport !== null,\n ),\n ),\n ];\n };\n\n const closeTransports = async () => {\n await closeQueuedTransports(detachTransports());\n };\n\n const isCurrentConnection = (generation: number) =>\n mountedRef.current && generation === connectionGenerationRef.current;\n\n const createInterruptedAuthError = (cause?: unknown) =>\n new Error(\n `MCP server \"${props.id}\" authorization was interrupted before completion.`,\n cause === undefined ? undefined : { cause },\n );\n\n const withConnectionTimeout = useEffectEvent(\n async <T>(\n promise: Promise<T>,\n phase: \"connecting\" | \"listing tools\",\n startedAt: number,\n ): Promise<T> => {\n const timeoutMs = props.connectionTimeout;\n if (timeoutMs === undefined) return await promise;\n const remainingMs = timeoutMs - (Date.now() - startedAt);\n const timeoutError = () =>\n new Error(\n `MCP server \"${props.id}\" timed out while ${phase} after ${timeoutMs}ms.`,\n );\n if (remainingMs <= 0) throw timeoutError();\n\n let timeout: ReturnType<typeof setTimeout> | undefined;\n try {\n return await Promise.race([\n promise,\n new Promise<never>((_, reject) => {\n timeout = setTimeout(() => reject(timeoutError()), remainingMs);\n }),\n ]);\n } finally {\n if (timeout !== undefined) clearTimeout(timeout);\n }\n },\n );\n\n const unboundAuthMessage = () =>\n `MCP server \"${props.id}\" has saved authentication for a different URL. Authenticate again to connect to ${props.url}.`;\n\n const loadAuthState = useEffectEvent(async () => {\n const state = await props.storage.loadAuthState(props.id);\n if (isAuthStateForServerUrl(state, props.url)) {\n return { state, unbound: false };\n }\n return { state: null, unbound: hasPersistedCredentials(state) };\n });\n\n const buildTransport = useEffectEvent(\n async (generation: number): Promise<StreamableHTTPClientTransport> => {\n if (props.auth.type === \"oauth\") {\n const generationOwner = { current: generation };\n const authProvider = createOAuthProvider({\n serverId: props.id,\n serverUrl: props.url,\n config: props.auth,\n storage: props.storage,\n redirectUri: props.redirectUri,\n onAuthorizationUrl: (url) => {\n if (isCurrentConnection(generationOwner.current)) {\n setAuthorizationUrl(url.toString());\n }\n },\n });\n const transport = new StreamableHTTPClientTransport(\n new URL(props.url),\n {\n authProvider,\n },\n );\n transportGenerationRef.current.set(transport, generationOwner);\n return transport;\n }\n if (props.auth.type === \"bearer\") {\n const { state, unbound } = await loadAuthState();\n const headers = buildHeaders(props.auth, state);\n if (!headers && unbound) throw new Error(unboundAuthMessage());\n const transportOpts: StreamableHTTPClientTransportOptions = {};\n if (headers) transportOpts.requestInit = { headers };\n return new StreamableHTTPClientTransport(\n new URL(props.url),\n transportOpts,\n );\n }\n return new StreamableHTTPClientTransport(new URL(props.url));\n },\n );\n\n const applyToolsList = useEffectEvent(\n (list: {\n tools: Array<{\n name: string;\n description?: string | undefined;\n inputSchema: unknown;\n }>;\n }) => {\n setTools(\n list.tools.map((t) => {\n const info: MCPToolInfo = {\n name: t.name,\n inputSchema: t.inputSchema,\n };\n if (t.description !== undefined) info.description = t.description;\n return info;\n }),\n );\n },\n );\n\n const syncTools = useEffectEvent(\n async (\n client: Client,\n generation: number,\n options?: { startedAt?: number | undefined },\n ): Promise<boolean> => {\n const listPromise = client.listTools();\n const list =\n options?.startedAt === undefined\n ? await listPromise\n : await withConnectionTimeout(\n listPromise,\n \"listing tools\",\n options.startedAt,\n );\n if (!isCurrentConnection(generation)) return false;\n applyToolsList(list);\n return true;\n },\n );\n\n const finalizeConnect = useEffectEvent(\n async (\n transport: StreamableHTTPClientTransport,\n generation: number,\n ): Promise<boolean> => {\n const clientOptions: ClientOptions = {\n ...(props.elicitation === false\n ? {}\n : { capabilities: { elicitation: {} } }),\n listChanged: {\n tools: {\n autoRefresh: true,\n debounceMs: 300,\n onChanged: (error, items) => {\n if (!isCurrentConnection(generation)) return;\n if (error !== null) {\n setLastError({ message: error.message });\n return;\n }\n if (items === null) return;\n setLastError(null);\n applyToolsList({ tools: items });\n },\n },\n },\n };\n if (props.cache?.defaultTtlMs !== undefined) {\n clientOptions.defaultCacheTtlMs = props.cache.defaultTtlMs;\n }\n const client = new Client(\n {\n name: \"assistant-ui-mcp\",\n version: \"0.0.0\",\n },\n clientOptions,\n );\n if (props.elicitation !== false) {\n client.setRequestHandler(\n \"elicitation/create\",\n (request: ElicitRequest, context): Promise<ElicitResult> => {\n if (!isCurrentConnection(generation)) {\n return Promise.resolve({ action: \"cancel\" });\n }\n if (!(\"requestedSchema\" in request.params)) {\n return Promise.resolve({ action: \"cancel\" });\n }\n const { message, requestedSchema } = request.params;\n\n const id = createMcpId();\n const promise = new Promise<ElicitResult>((resolve) => {\n const onAbort = () => {\n resolvePendingElicitation(id, { action: \"cancel\" });\n };\n elicitationResolversRef.current.set(id, {\n resolve,\n signal: context.mcpReq.signal,\n onAbort,\n requestedSchema,\n });\n });\n setPendingElicitations((current) => [\n ...current,\n {\n id,\n message,\n requestedSchema,\n },\n ]);\n const entry = elicitationResolversRef.current.get(id);\n if (entry) {\n if (context.mcpReq.signal.aborted) {\n entry.onAbort();\n } else {\n context.mcpReq.signal.addEventListener(\"abort\", entry.onAbort, {\n once: true,\n });\n }\n }\n return promise;\n },\n );\n }\n const startedAt = Date.now();\n await withConnectionTimeout(\n client.connect(transport),\n \"connecting\",\n startedAt,\n );\n if (!isCurrentConnection(generation)) return false;\n // Defer ref assignment until listTools() also succeeds — otherwise a\n // post-connect failure leaves stale refs that `callTool()` would\n // happily walk into, producing confusing SDK errors instead of\n // \"not connected\".\n const synced = await syncTools(client, generation, { startedAt });\n if (!synced) return false;\n\n pendingTransportRef.current = null;\n clientRef.current = client;\n transportRef.current = transport;\n setConnectionState(\"connected\");\n return true;\n },\n );\n\n const doConnect = useEffectEvent(async () => {\n const generation = ++connectionGenerationRef.current;\n // Close any prior transport/client so a re-connect doesn't leak.\n await closeTransports();\n if (!isCurrentConnection(generation)) return;\n\n setConnectionState(\"connecting\");\n setLastError(null);\n setAuthorizationUrl(null);\n // Clear tools so a reconnect (error → connect, or authRequired\n // → connect) doesn't expose the previous attempt's tool list.\n setTools([]);\n let transport: StreamableHTTPClientTransport | null = null;\n try {\n transport = await buildTransport(generation);\n if (!isCurrentConnection(generation)) {\n await closeQueuedTransports([transport]);\n return;\n }\n pendingTransportRef.current = transport;\n // Don't assign to transportRef until connect succeeds — otherwise a\n // failed `listTools()` leaves an orphaned transport that future\n // doConnect / doDisconnect calls treat as live.\n await finalizeConnect(transport, generation);\n } catch (err) {\n if (!isCurrentConnection(generation)) return;\n\n if (err instanceof UnauthorizedError) {\n // OAuth: keep the transport alive so completeAuth can call\n // finishAuth on it. Closing it before storing would leave a\n // closed transport on transportRef.\n pendingTransportRef.current = null;\n transportRef.current = transport;\n setConnectionState(\"authRequired\");\n } else {\n cancelPendingElicitations();\n if (transport) {\n pendingTransportRef.current = null;\n await closeQueuedTransports([transport]);\n }\n setLastError({\n message: err instanceof Error ? err.message : String(err),\n });\n setConnectionState(\"error\");\n }\n }\n });\n\n const doDisconnect = useEffectEvent(async () => {\n connectionGenerationRef.current += 1;\n setTools([]);\n setAuthorizationUrl(null);\n setConnectionState(\"disconnected\");\n await closeTransports();\n });\n\n const doCompleteAuth = useEffectEvent(async (callbackUrl: string) => {\n const validationGeneration = connectionGenerationRef.current;\n const url = new URL(callbackUrl);\n const state = url.searchParams.get(\"state\");\n if (!state) throw new Error('missing \"state\" parameter');\n let pendingAuthValidation = pendingAuthValidationRef.current;\n if (!pendingAuthValidation) {\n let resolve!: () => void;\n const promise = new Promise<void>((resolvePromise) => {\n resolve = resolvePromise;\n });\n pendingAuthValidation = { count: 0, promise, resolve };\n pendingAuthValidationRef.current = pendingAuthValidation;\n }\n pendingAuthValidation.count += 1;\n try {\n const { state: persisted, unbound } = await loadAuthState();\n if (!isCurrentConnection(validationGeneration)) {\n throw createInterruptedAuthError();\n }\n if (unbound) throw new Error(unboundAuthMessage());\n if (!persisted?.state) {\n throw new Error(\n \"no pending OAuth authorization request for this server\",\n );\n }\n if (persisted.state !== state) {\n throw new Error(\"OAuth state does not match the authorization request\");\n }\n if (!url.searchParams.get(\"code\") && !url.searchParams.get(\"error\")) {\n throw new Error(\"missing authorization code in callback URL\");\n }\n } finally {\n pendingAuthValidation.count -= 1;\n if (pendingAuthValidation.count === 0) {\n pendingAuthValidationRef.current = null;\n pendingAuthValidation.resolve();\n }\n }\n\n // Claim the generation before a waiting auto-connect can resume.\n const generation = ++connectionGenerationRef.current;\n cancelPendingElicitations();\n await closePendingTransport();\n if (!isCurrentConnection(generation)) throw createInterruptedAuthError();\n\n setConnectionState(\"authPending\");\n setLastError(null);\n try {\n let transport = transportRef.current;\n if (!transport) {\n transport = await buildTransport(generation);\n if (!isCurrentConnection(generation)) {\n await closeQueuedTransports([transport]);\n throw createInterruptedAuthError();\n }\n }\n const generationOwner = transportGenerationRef.current.get(transport);\n if (generationOwner) generationOwner.current = generation;\n transportRef.current = null;\n clientRef.current = null;\n pendingTransportRef.current = transport;\n await transport.finishAuth(url.searchParams);\n if (!isCurrentConnection(generation)) throw createInterruptedAuthError();\n setAuthorizationUrl(null);\n const connected = await finalizeConnect(transport, generation);\n if (!connected) throw createInterruptedAuthError();\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n if (!isCurrentConnection(generation))\n throw createInterruptedAuthError(error);\n\n await closeTransports();\n setLastError({\n message: error.message,\n });\n setConnectionState(\"error\");\n throw error;\n }\n });\n\n const tryAutoConnect = useEffectEvent(\n async (signal: { cancelled: boolean }) => {\n if (!props.autoConnect) return;\n if (props.auth.type === \"none\") {\n void doConnect();\n return;\n }\n // Static connector token short-circuits the storage read.\n if (props.auth.type === \"bearer\" && props.auth.token) {\n void doConnect();\n return;\n }\n const generation = connectionGenerationRef.current;\n let loaded: Awaited<ReturnType<typeof loadAuthState>>;\n try {\n loaded = await loadAuthState();\n } catch (error) {\n if (signal.cancelled || !isCurrentConnection(generation)) return;\n const message = error instanceof Error ? error.message : String(error);\n setLastError({\n message: `MCP server \"${props.id}\" failed to load saved authentication: ${message}`,\n });\n setConnectionState(\"error\");\n return;\n }\n if (signal.cancelled || !isCurrentConnection(generation)) return;\n if (loaded.unbound) {\n setLastError({ message: unboundAuthMessage() });\n return;\n }\n const persisted = loaded.state;\n if (props.auth.type === \"oauth\") {\n if (!hasUsableOAuthTokens(persisted, props.auth)) return;\n } else if (!persisted?.token) {\n return;\n }\n const pendingAuthValidation = pendingAuthValidationRef.current;\n if (pendingAuthValidation) {\n await pendingAuthValidation.promise;\n if (signal.cancelled || !isCurrentConnection(generation)) return;\n }\n void doConnect();\n },\n );\n\n // Auto-connect on mount when usable auth exists.\n useEffect(() => {\n const transportCloseQueueRef = props.transportCloseQueueRef;\n const previousDisposal = pendingDisposalRef.current;\n if (previousDisposal) previousDisposal.cancelled = true;\n const pendingDisposal = { cancelled: false };\n pendingDisposalRef.current = pendingDisposal;\n mountedRef.current = true;\n const signal = { cancelled: false };\n // Auto-connect opens a transport, so it belongs to the same effect as the\n // disposal that closes it.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n void tryAutoConnect(signal);\n return () => {\n mountedRef.current = false;\n signal.cancelled = true;\n const task = transportCloseQueueRef.current.then(async () => {\n await new Promise<void>((resolve) => queueMicrotask(resolve));\n if (pendingDisposal.cancelled) return;\n connectionGenerationRef.current += 1;\n await Promise.all(detachTransports().map(closeTransportSafely));\n });\n transportCloseQueueRef.current = task;\n };\n }, [props.transportCloseQueueRef]);\n\n const state = useMemo<MCPServerState>(\n () => ({\n id: props.id,\n kind: props.kind,\n name: props.name,\n url: props.url,\n icon: props.icon,\n connectionState,\n lastError,\n tools,\n authorizationUrl,\n pendingElicitations,\n }),\n [\n props.id,\n props.kind,\n props.name,\n props.url,\n props.icon,\n connectionState,\n lastError,\n tools,\n authorizationUrl,\n pendingElicitations,\n ],\n );\n\n return {\n getState: () => state,\n connect: doConnect,\n disconnect: doDisconnect,\n remove: async () => {\n const releaseRemovalFence = beginMcpServerRemovalFence(props);\n try {\n await doDisconnect();\n await clearOAuthProviderAuthState(props.storage, props.id);\n await props.onRemove();\n } catch (err) {\n releaseRemovalFence?.();\n setLastError({\n message: err instanceof Error ? err.message : String(err),\n });\n throw err;\n }\n releaseRemovalFence?.();\n },\n callTool: async (name, args) => {\n const client = clientRef.current;\n if (!client) {\n throw new Error(`MCP server \"${props.id}\" is not connected`);\n }\n return await client.callTool({\n name,\n arguments: args as Record<string, unknown> | undefined,\n });\n },\n listResources: async (params) => {\n const client = clientRef.current;\n if (!client) {\n throw new Error(`MCP server \"${props.id}\" is not connected`);\n }\n return await client.listResources(params);\n },\n readResource: async (uri) => {\n const client = clientRef.current;\n if (!client) {\n throw new Error(`MCP server \"${props.id}\" is not connected`);\n }\n return await client.readResource({ uri });\n },\n completeAuth: doCompleteAuth,\n answerElicitation: (\n id: string,\n response: MCPElicitationResponse,\n ): readonly { property: string; message: string }[] | undefined => {\n if (response.action === \"accept\") {\n const entry = elicitationResolversRef.current.get(id);\n if (!entry) return undefined;\n\n if (\n typeof response.content !== \"object\" ||\n response.content === null ||\n Array.isArray(response.content)\n ) {\n const errors = [\n {\n property: \"content\",\n message: \"Response content must be an object.\",\n },\n ];\n setPendingElicitationError(id, {\n message: \"Invalid elicitation content: content.\",\n properties: [\"content\"],\n });\n return errors;\n }\n\n const errors = validateElicitationContent(\n entry.requestedSchema,\n response.content,\n );\n if (errors.length > 0) {\n const properties = [\n ...new Set(errors.map((error) => error.property)),\n ];\n setPendingElicitationError(id, {\n message: `Invalid elicitation content: ${properties.join(\", \")}.`,\n properties,\n });\n return errors;\n }\n\n const result: ElicitResult = {\n action: \"accept\",\n content: response.content as ElicitResult[\"content\"],\n };\n resolvePendingElicitation(id, result);\n return undefined;\n }\n\n resolvePendingElicitation(id, { action: response.action });\n return undefined;\n },\n };\n};\n\nconst McpServerResourceInstance = resource(useMcpServerResourceInstance);\n\nexport const McpServerResource = resource(function useMcpServerResource(\n props: McpServerResourceProps,\n): ClientOutput<\"mcpServer\"> {\n const transportCloseQueueRef = useRef(Promise.resolve());\n const dependencies = getConnectionDependencies(props);\n const [connection, setConnection] = useState({ dependencies, generation: 0 });\n let currentConnection = connection;\n if (!shallowEqual(connection.dependencies, dependencies)) {\n currentConnection = {\n dependencies,\n generation: connection.generation + 1,\n };\n setConnection(currentConnection);\n }\n\n // Storage keys remounts through its optional scopeId rather than object\n // identity, because a defaulted storage element is rebuilt on ordinary\n // renders.\n return useResource(\n withKey(\n currentConnection.generation,\n McpServerResourceInstance({ ...props, transportCloseQueueRef }),\n ),\n );\n});\n"],"mappings":";;;;;;;;;;;;AA0DA,MAAasD,6BACXC,UACuB;CACvB,MAAMd,OAAOc,MAAMd;CACnB,MAAMe,mBACJf,KAAKgB,SAAS,WACV;EAAChB,KAAKgB;EAAMhB,KAAKiB;EAAOH,MAAMb,QAAQiB;CAAO,IAC7ClB,KAAKgB,SAAS,UACZ;EACEhB,KAAKgB;EACLhB,KAAKmB,QAAQC;EACb,GAAIpB,KAAKmB,UAAU,CAAA;EACnBnB,K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F;AACF,CAAC"}
@@ -1,5 +1,3 @@
1
- import { MCPStorage } from "./types.js";
2
- //#region src/resources/storage/McpCustomStorage.d.ts
1
+ import type { MCPStorage } from "./types.js";
3
2
  export declare const McpCustomStorage: import("@assistant-ui/tap").Resource<MCPStorage, [impl: MCPStorage]>;
4
- //#endregion
5
3
  //# sourceMappingURL=McpCustomStorage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"McpCustomStorage.d.ts","names":[],"sources":["../../../src/resources/storage/McpCustomStorage.ts"],"mappings":";;qBAOa,8CAAgB,SAAA,aAAA,MAAA"}
1
+ {"version":3,"file":"McpCustomStorage.d.ts","sourceRoot":"","sources":["../../../src/resources/storage/McpCustomStorage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAgB;AAM1C,eAAO,MAAM,gBAAgB,sEAAgC,CAAC"}
@@ -1,22 +1,20 @@
1
- import { MCPCustomServerRecord } from "../../mcp-scope.js";
2
- import { MCPPersistedAuthState } from "../../auth/types.js";
3
- import { MCPStorage } from "./types.js";
4
- //#region src/resources/storage/McpLocalStorage.d.ts
1
+ import type { MCPCustomServerRecord } from "../../mcp-scope.js";
2
+ import type { MCPPersistedAuthState } from "../../auth/types.js";
3
+ import type { MCPStorage } from "./types.js";
5
4
  export type McpLocalStorageOptions = {
6
- /** Namespace prefix for keys. Default "aui-mcp". */
7
- keyPrefix?: string;
8
- /** Override the underlying Storage. Defaults to globalThis.localStorage. */
9
- storage?: Storage;
10
- /**
11
- * Stable identity for the backing data, used to key server reconnects.
12
- * Required to get reconnect-on-swap behavior when `storage` is overridden;
13
- * without it a custom backing store declares no scope, since a prefix
14
- * alone cannot distinguish two different stores.
15
- */
16
- scopeId?: string;
5
+ /** Namespace prefix for keys. Default "aui-mcp". */
6
+ keyPrefix?: string;
7
+ /** Override the underlying Storage. Defaults to globalThis.localStorage. */
8
+ storage?: Storage;
9
+ /**
10
+ * Stable identity for the backing data, used to key server reconnects.
11
+ * Required to get reconnect-on-swap behavior when `storage` is overridden;
12
+ * without it a custom backing store declares no scope, since a prefix
13
+ * alone cannot distinguish two different stores.
14
+ */
15
+ scopeId?: string;
17
16
  };
18
17
  export declare const normalizeCustomServerRecords: (value: unknown) => MCPCustomServerRecord[];
19
18
  export declare const normalizePersistedAuthState: (value: unknown) => MCPPersistedAuthState | null;
20
19
  export declare const McpLocalStorage: import("@assistant-ui/tap").Resource<MCPStorage, [opts?: McpLocalStorageOptions | undefined]>;
21
- //#endregion
22
20
  //# sourceMappingURL=McpLocalStorage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"McpLocalStorage.d.ts","names":[],"sources":["../../../src/resources/storage/McpLocalStorage.ts"],"mappings":";;;;YAcY;;EAEV;;EAEA,UAAU;;;;;;;EAOV;;qBAiGW,+BACX,mBACC;qBAiFU,8BACX,mBACC;qBAiGU,6CAAe,SAAA,aAAA,OAAA"}
1
+ {"version":3,"file":"McpLocalStorage.d.ts","sourceRoot":"","sources":["../../../src/resources/storage/McpLocalStorage.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAiB,qBAAqB,EAAE,2BAAwB;AAC5E,OAAO,KAAK,EAAE,qBAAqB,EAAE,4BAAyB;AAE9D,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAgB;AAE1C,MAAM,MAAM,sBAAsB,GAAG;IACnC,oDAAoD;IACpD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAgGF,eAAO,MAAM,4BAA4B,GACvC,OAAO,OAAO,KACb,qBAAqB,EAMvB,CAAC;AA2EF,eAAO,MAAM,2BAA2B,GACtC,OAAO,OAAO,KACb,qBAAqB,GAAG,IA8B1B,CAAC;AAmEF,eAAO,MAAM,eAAe,+FAA+B,CAAC"}
@@ -1,5 +1,5 @@
1
- import { assertValidServerId } from "../../utils/serverId.js";
2
1
  import { normalizeMcpServerUrl } from "../../utils/serverUrl.js";
2
+ import { assertValidServerId } from "../../utils/serverId.js";
3
3
  import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
4
4
  import "@assistant-ui/tap/react-shim";
5
5
  import { resource } from "@assistant-ui/tap";
@@ -1 +1 @@
1
- {"version":3,"file":"McpLocalStorage.js","names":["resource","useMemo","OAuthMetadataSchema","OAuthClientInformationFullSchema","OAuthProtectedResourceMetadataSchema","OAuthTokensSchema","normalizeMcpServerUrl","MCPAuthConfig","MCPCustomServerRecord","MCPPersistedAuthState","assertValidServerId","MCPStorage","McpLocalStorageOptions","keyPrefix","storage","Storage","scopeId","resolveStorage","opts","globalThis","localStorage","isRecord","value","Record","Array","isArray","isOptionalString","undefined","isNonEmptyString","trim","length","isOptionalNonEmptyString","isOptionalStringArray","every","item","isOptionalConnectionTimeout","Number","isFinite","isValidServerId","id","isMCPAuthConfig","auth","type","token","scopes","authorizationEndpoint","tokenEndpoint","registrationEndpoint","clientId","clientSecret","isCustomServerRecord","name","url","createdAt","connectionTimeout","normalizeCustomServerRecord","record","normalizeCustomServerRecords","flatMap","normalizeOAuthTokens","result","safeParse","success","data","normalizeClientInformation","isSecureNetworkUrl","URL","isIpv4Loopback","test","hostname","protocol","endsWith","isMcpServerUrl","normalizeDiscoveryState","authorizationServerUrl","state","NonNullable","resourceMetadataUrl","metadata","authorizationServerMetadata","resourceMetadata","normalizePersistedAuthState","serverUrl","tokensClientId","codeVerifier","tokens","clientInformation","clientInformationSource","discoveryState","Object","keys","useMcpLocalStorage","t0","$","_c","t1","prefix","t2","customServersKey","t3","authKey","t4","key","fallback","raw","getItem","JSON","parse","T","read","t5","key_0","setItem","stringify","write","t6","key_1","removeItem","remove","t7","t8","t9","records","t10","id_0","t11","id_1","t12","id_2","t13","loadCustomServers","saveCustomServers","loadAuthState","saveAuthState","clearAuthState","McpLocalStorage"],"sources":["../../../src/resources/storage/McpLocalStorage.ts"],"sourcesContent":["import { resource } from \"@assistant-ui/tap\";\nimport { useMemo } from \"react\";\nimport {\n OAuthMetadataSchema,\n OAuthClientInformationFullSchema,\n OAuthProtectedResourceMetadataSchema,\n OAuthTokensSchema,\n} from \"@modelcontextprotocol/core\";\nimport { normalizeMcpServerUrl } from \"../../utils/serverUrl\";\nimport type { MCPAuthConfig, MCPCustomServerRecord } from \"../../mcp-scope\";\nimport type { MCPPersistedAuthState } from \"../../auth/types\";\nimport { assertValidServerId } from \"../../utils/serverId\";\nimport type { MCPStorage } from \"./types\";\n\nexport type McpLocalStorageOptions = {\n /** Namespace prefix for keys. Default \"aui-mcp\". */\n keyPrefix?: string;\n /** Override the underlying Storage. Defaults to globalThis.localStorage. */\n storage?: Storage;\n /**\n * Stable identity for the backing data, used to key server reconnects.\n * Required to get reconnect-on-swap behavior when `storage` is overridden;\n * without it a custom backing store declares no scope, since a prefix\n * alone cannot distinguish two different stores.\n */\n scopeId?: string;\n};\n\nfunction resolveStorage(opts: McpLocalStorageOptions): Storage | null {\n if (opts.storage) return opts.storage;\n if (typeof globalThis !== \"undefined\" && \"localStorage\" in globalThis) {\n try {\n return (globalThis as { localStorage: Storage }).localStorage;\n } catch {\n return null;\n }\n }\n return null;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst isOptionalString = (value: unknown): value is string | undefined =>\n value === undefined || typeof value === \"string\";\n\nconst isNonEmptyString = (value: unknown): value is string =>\n typeof value === \"string\" && value.trim().length > 0;\n\nconst isOptionalNonEmptyString = (\n value: unknown,\n): value is string | undefined =>\n value === undefined || isNonEmptyString(value);\n\nconst isOptionalStringArray = (value: unknown): value is string[] | undefined =>\n value === undefined ||\n (Array.isArray(value) && value.every((item) => typeof item === \"string\"));\n\nconst isOptionalConnectionTimeout = (\n value: unknown,\n): value is number | undefined =>\n value === undefined ||\n (typeof value === \"number\" && Number.isFinite(value) && value >= 0);\n\nconst isValidServerId = (id: string): boolean => {\n try {\n assertValidServerId(id);\n return true;\n } catch {\n return false;\n }\n};\n\nconst isMCPAuthConfig = (auth: unknown): auth is MCPAuthConfig => {\n if (!isRecord(auth)) return false;\n\n switch (auth.type) {\n case \"none\":\n return true;\n case \"bearer\":\n return isOptionalNonEmptyString(auth.token);\n case \"oauth\":\n return (\n isOptionalStringArray(auth.scopes) &&\n isOptionalString(auth.authorizationEndpoint) &&\n isOptionalString(auth.tokenEndpoint) &&\n isOptionalString(auth.registrationEndpoint) &&\n isOptionalString(auth.clientId) &&\n isOptionalString(auth.clientSecret)\n );\n default:\n return false;\n }\n};\n\nconst isCustomServerRecord = (\n value: unknown,\n): value is MCPCustomServerRecord => {\n if (!isRecord(value)) return false;\n if (typeof value.id !== \"string\" || !isValidServerId(value.id)) {\n return false;\n }\n return (\n isNonEmptyString(value.name) &&\n isNonEmptyString(value.url) &&\n Number.isFinite(value.createdAt) &&\n isMCPAuthConfig(value.auth) &&\n isOptionalConnectionTimeout(value.connectionTimeout)\n );\n};\n\nconst normalizeCustomServerRecord = (\n value: unknown,\n): MCPCustomServerRecord | null => {\n if (isCustomServerRecord(value)) return value;\n if (!isRecord(value)) return null;\n\n const record = { ...value };\n delete record.connectionTimeout;\n return isCustomServerRecord(record) ? record : null;\n};\n\nexport const normalizeCustomServerRecords = (\n value: unknown,\n): MCPCustomServerRecord[] => {\n if (!Array.isArray(value)) return [];\n return value.flatMap((item) => {\n const record = normalizeCustomServerRecord(item);\n return record === null ? [] : [record];\n });\n};\n\nconst normalizeOAuthTokens = (\n value: unknown,\n): MCPPersistedAuthState[\"tokens\"] | undefined => {\n const result = OAuthTokensSchema.safeParse(value);\n return result.success ? result.data : undefined;\n};\n\nconst normalizeClientInformation = (\n value: unknown,\n): MCPPersistedAuthState[\"clientInformation\"] | undefined => {\n const result = OAuthClientInformationFullSchema.safeParse(value);\n return result.success ? result.data : undefined;\n};\n\nconst isSecureNetworkUrl = (value: unknown): value is string => {\n if (!isNonEmptyString(value)) return false;\n try {\n const url = new URL(value);\n const isIpv4Loopback = /^127(?:\\.\\d{1,3}){3}$/.test(url.hostname);\n return (\n url.protocol === \"https:\" ||\n (url.protocol === \"http:\" &&\n (url.hostname === \"localhost\" ||\n url.hostname.endsWith(\".localhost\") ||\n isIpv4Loopback ||\n url.hostname === \"[::1]\"))\n );\n } catch {\n return false;\n }\n};\n\nconst isMcpServerUrl = (value: unknown): value is string => {\n if (typeof value !== \"string\") return false;\n try {\n const url = new URL(value);\n return url.protocol === \"https:\" || url.protocol === \"http:\";\n } catch {\n return false;\n }\n};\n\nconst normalizeDiscoveryState = (\n value: unknown,\n): MCPPersistedAuthState[\"discoveryState\"] | undefined => {\n if (!isRecord(value) || !isSecureNetworkUrl(value.authorizationServerUrl)) {\n return undefined;\n }\n\n // A malformed optional field is dropped alone: keeping the validated\n // authorization server URL preserves the redirect-time binding, and the SDK\n // re-discovers whatever metadata is missing.\n const state: NonNullable<MCPPersistedAuthState[\"discoveryState\"]> = {\n authorizationServerUrl: value.authorizationServerUrl,\n };\n\n if (isSecureNetworkUrl(value.resourceMetadataUrl)) {\n state.resourceMetadataUrl = value.resourceMetadataUrl;\n }\n\n const metadata = OAuthMetadataSchema.safeParse(\n value.authorizationServerMetadata,\n );\n if (metadata.success) state.authorizationServerMetadata = metadata.data;\n\n const resourceMetadata = OAuthProtectedResourceMetadataSchema.safeParse(\n value.resourceMetadata,\n );\n if (resourceMetadata.success) state.resourceMetadata = resourceMetadata.data;\n\n return state;\n};\n\nexport const normalizePersistedAuthState = (\n value: unknown,\n): MCPPersistedAuthState | null => {\n if (!isRecord(value)) return null;\n if (\"serverUrl\" in value && !isMcpServerUrl(value.serverUrl)) return null;\n\n const state: MCPPersistedAuthState = {};\n if (isMcpServerUrl(value.serverUrl)) {\n state.serverUrl = normalizeMcpServerUrl(value.serverUrl);\n }\n if (isNonEmptyString(value.token)) state.token = value.token;\n if (isNonEmptyString(value.tokensClientId)) {\n state.tokensClientId = value.tokensClientId;\n }\n if (isNonEmptyString(value.codeVerifier)) {\n state.codeVerifier = value.codeVerifier;\n }\n if (isNonEmptyString(value.state)) state.state = value.state;\n\n const tokens = normalizeOAuthTokens(value.tokens);\n if (tokens) state.tokens = tokens;\n\n const clientInformation = normalizeClientInformation(value.clientInformation);\n if (clientInformation) state.clientInformation = clientInformation;\n if (value.clientInformationSource === \"registered\") {\n state.clientInformationSource = value.clientInformationSource;\n }\n\n const discoveryState = normalizeDiscoveryState(value.discoveryState);\n if (discoveryState) state.discoveryState = discoveryState;\n\n return Object.keys(state).length > 0 ? state : null;\n};\n\nconst useMcpLocalStorage = (opts: McpLocalStorageOptions = {}): MCPStorage => {\n const prefix = opts.keyPrefix ?? \"aui-mcp\";\n const storage = resolveStorage(opts);\n // Deriving a scope from the prefix is only honest for the shared\n // globalThis.localStorage; two custom backing stores under one prefix hold\n // different data, so an overridden backing declares no scope unless the\n // caller names one.\n const scopeId =\n opts.scopeId ??\n (opts.storage === undefined ? `local-storage:${prefix}` : undefined);\n\n // Callers key per-server coordination state on this instance, so it has to\n // stay referentially stable for as long as the underlying store does.\n return useMemo(() => {\n const customServersKey = `${prefix}:custom-servers`;\n const authKey = (id: string) => `${prefix}:auth:${id}`;\n\n const read = <T>(key: string, fallback: T): T => {\n if (!storage) return fallback;\n try {\n const raw = storage.getItem(key);\n if (raw == null) return fallback;\n return JSON.parse(raw) as T;\n } catch {\n return fallback;\n }\n };\n\n const write = (key: string, value: unknown): void => {\n if (!storage) return;\n try {\n storage.setItem(key, JSON.stringify(value));\n } catch {\n // quota or serialization failure — silently drop\n }\n };\n\n const remove = (key: string): void => {\n if (!storage) return;\n try {\n storage.removeItem(key);\n } catch {\n // ignore\n }\n };\n\n return {\n ...(scopeId !== undefined ? { scopeId } : {}),\n loadCustomServers: async () =>\n normalizeCustomServerRecords(read<unknown>(customServersKey, [])),\n saveCustomServers: async (records) => {\n write(customServersKey, records);\n },\n loadAuthState: async (id) =>\n normalizePersistedAuthState(read<unknown>(authKey(id), null)),\n saveAuthState: async (id, state) => {\n write(authKey(id), state);\n },\n clearAuthState: async (id) => {\n remove(authKey(id));\n },\n };\n }, [prefix, storage, scopeId]);\n};\n\nexport const McpLocalStorage = resource(useMcpLocalStorage);\n"],"mappings":";;;;;;;AA4BA,SAASiB,eAAeC,MAA8C;CACpE,IAAIA,KAAKJ,SAAS,OAAOI,KAAKJ;CAC9B,IAAI,OAAOK,eAAe,eAAe,kBAAkBA,YACzD,IAAI;EACF,OAAQA,WAAyCC;CACnD,QAAQ;EACN,OAAO;CACT;CAEF,OAAO;AACT;AAEA,MAAMC,YAAYC,UAChB,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACE,MAAMC,QAAQH,KAAK;AAErE,MAAMI,oBAAoBJ,UACxBA,UAAUK,KAAAA,KAAa,OAAOL,UAAU;AAE1C,MAAMM,oBAAoBN,UACxB,OAAOA,UAAU,YAAYA,MAAMO,KAAK,CAAC,CAACC,SAAS;AAErD,MAAMC,4BACJT,UAEAA,UAAUK,KAAAA,KAAaC,iBAAiBN,KAAK;AAE/C,MAAMU,yBAAyBV,UAC7BA,UAAUK,KAAAA,KACTH,MAAMC,QAAQH,KAAK,KAAKA,MAAMW,OAAOC,SAAS,OAAOA,SAAS,QAAQ;AAEzE,MAAMC,+BACJb,UAEAA,UAAUK,KAAAA,KACT,OAAOL,UAAU,YAAYc,OAAOC,SAASf,KAAK,KAAKA,SAAS;AAEnE,MAAMgB,mBAAmBC,OAAwB;CAC/C,IAAI;EACF7B,oBAAoB6B,EAAE;EACtB,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;AAEA,MAAMC,mBAAmBC,SAAyC;CAChE,IAAI,CAACpB,SAASoB,IAAI,GAAG,OAAO;CAE5B,QAAQA,KAAKC,MAAb;EACE,KAAK,QACH,OAAO;EACT,KAAK,UACH,OAAOX,yBAAyBU,KAAKE,KAAK;EAC5C,KAAK,SACH,OACEX,sBAAsBS,KAAKG,MAAM,KACjClB,iBAAiBe,KAAKI,qBAAqB,KAC3CnB,iB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EAAA,MAAAO;EAAAP,EAAA,MAAAyB;EAAAzB,EAAA,MAAAkC;CAAA,OAAAA,MAAAlC,EAAA;CAAA,IAAAoC;CAAA,IAAApC,EAAA,QAAA8B,OAAA9B,EAAA,QAAAgC,OAAAhC,EAAA,QAAAkC,OAAAlC,EAAA,QAAA0B,MAAA1B,EAAA,QAAA2B,MAAA3B,EAAA,QAAA4B,IAAA;EAdIQ,MAAA;GAAA,GACDV;GAAwCW,mBACzBV;GACgDW,mBAChDV;GAElBW,eACcT;GACgDU,eAChDR;GAEdS,gBACeP;EAGlB;EAAClC,EAAA,MAAA8B;EAAA9B,EAAA,MAAAgC;EAAAhC,EAAA,MAAAkC;EAAAlC,EAAA,MAAA0B;EAAA1B,EAAA,MAAA2B;EAAA3B,EAAA,MAAA4B;EAAA5B,EAAA,MAAAoC;CAAA,OAAAA,MAAApC,EAAA;CAAA,OAfDoC;AAeE;AAIN,MAAaM,kBAAkBvI,SAAS2F,kBAAkB"}
1
+ {"version":3,"file":"McpLocalStorage.js","names":["resource","useMemo","OAuthMetadataSchema","OAuthClientInformationFullSchema","OAuthProtectedResourceMetadataSchema","OAuthTokensSchema","normalizeMcpServerUrl","MCPAuthConfig","MCPCustomServerRecord","MCPPersistedAuthState","assertValidServerId","MCPStorage","McpLocalStorageOptions","keyPrefix","storage","Storage","scopeId","resolveStorage","opts","globalThis","localStorage","isRecord","value","Record","Array","isArray","isOptionalString","undefined","isNonEmptyString","trim","length","isOptionalNonEmptyString","isOptionalStringArray","every","item","isOptionalConnectionTimeout","Number","isFinite","isValidServerId","id","isMCPAuthConfig","auth","type","token","scopes","authorizationEndpoint","tokenEndpoint","registrationEndpoint","clientId","clientSecret","isCustomServerRecord","name","url","createdAt","connectionTimeout","normalizeCustomServerRecord","record","normalizeCustomServerRecords","flatMap","normalizeOAuthTokens","result","safeParse","success","data","normalizeClientInformation","isSecureNetworkUrl","URL","isIpv4Loopback","test","hostname","protocol","endsWith","isMcpServerUrl","normalizeDiscoveryState","authorizationServerUrl","state","NonNullable","resourceMetadataUrl","metadata","authorizationServerMetadata","resourceMetadata","normalizePersistedAuthState","serverUrl","tokensClientId","codeVerifier","tokens","clientInformation","clientInformationSource","discoveryState","Object","keys","useMcpLocalStorage","t0","$","_c","t1","prefix","t2","customServersKey","t3","authKey","t4","key","fallback","raw","getItem","JSON","parse","T","read","t5","key_0","setItem","stringify","write","t6","key_1","removeItem","remove","t7","t8","t9","records","t10","id_0","t11","id_1","t12","id_2","t13","loadCustomServers","saveCustomServers","loadAuthState","saveAuthState","clearAuthState","McpLocalStorage","_c"],"sources":["../../../src/resources/storage/McpLocalStorage.ts"],"sourcesContent":["import { resource } from \"@assistant-ui/tap\";\nimport { useMemo } from \"react\";\nimport {\n OAuthMetadataSchema,\n OAuthClientInformationFullSchema,\n OAuthProtectedResourceMetadataSchema,\n OAuthTokensSchema,\n} from \"@modelcontextprotocol/core\";\nimport { normalizeMcpServerUrl } from \"../../utils/serverUrl\";\nimport type { MCPAuthConfig, MCPCustomServerRecord } from \"../../mcp-scope\";\nimport type { MCPPersistedAuthState } from \"../../auth/types\";\nimport { assertValidServerId } from \"../../utils/serverId\";\nimport type { MCPStorage } from \"./types\";\n\nexport type McpLocalStorageOptions = {\n /** Namespace prefix for keys. Default \"aui-mcp\". */\n keyPrefix?: string;\n /** Override the underlying Storage. Defaults to globalThis.localStorage. */\n storage?: Storage;\n /**\n * Stable identity for the backing data, used to key server reconnects.\n * Required to get reconnect-on-swap behavior when `storage` is overridden;\n * without it a custom backing store declares no scope, since a prefix\n * alone cannot distinguish two different stores.\n */\n scopeId?: string;\n};\n\nfunction resolveStorage(opts: McpLocalStorageOptions): Storage | null {\n if (opts.storage) return opts.storage;\n if (typeof globalThis !== \"undefined\" && \"localStorage\" in globalThis) {\n try {\n return (globalThis as { localStorage: Storage }).localStorage;\n } catch {\n return null;\n }\n }\n return null;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst isOptionalString = (value: unknown): value is string | undefined =>\n value === undefined || typeof value === \"string\";\n\nconst isNonEmptyString = (value: unknown): value is string =>\n typeof value === \"string\" && value.trim().length > 0;\n\nconst isOptionalNonEmptyString = (\n value: unknown,\n): value is string | undefined =>\n value === undefined || isNonEmptyString(value);\n\nconst isOptionalStringArray = (value: unknown): value is string[] | undefined =>\n value === undefined ||\n (Array.isArray(value) && value.every((item) => typeof item === \"string\"));\n\nconst isOptionalConnectionTimeout = (\n value: unknown,\n): value is number | undefined =>\n value === undefined ||\n (typeof value === \"number\" && Number.isFinite(value) && value >= 0);\n\nconst isValidServerId = (id: string): boolean => {\n try {\n assertValidServerId(id);\n return true;\n } catch {\n return false;\n }\n};\n\nconst isMCPAuthConfig = (auth: unknown): auth is MCPAuthConfig => {\n if (!isRecord(auth)) return false;\n\n switch (auth.type) {\n case \"none\":\n return true;\n case \"bearer\":\n return isOptionalNonEmptyString(auth.token);\n case \"oauth\":\n return (\n isOptionalStringArray(auth.scopes) &&\n isOptionalString(auth.authorizationEndpoint) &&\n isOptionalString(auth.tokenEndpoint) &&\n isOptionalString(auth.registrationEndpoint) &&\n isOptionalString(auth.clientId) &&\n isOptionalString(auth.clientSecret)\n );\n default:\n return false;\n }\n};\n\nconst isCustomServerRecord = (\n value: unknown,\n): value is MCPCustomServerRecord => {\n if (!isRecord(value)) return false;\n if (typeof value.id !== \"string\" || !isValidServerId(value.id)) {\n return false;\n }\n return (\n isNonEmptyString(value.name) &&\n isNonEmptyString(value.url) &&\n Number.isFinite(value.createdAt) &&\n isMCPAuthConfig(value.auth) &&\n isOptionalConnectionTimeout(value.connectionTimeout)\n );\n};\n\nconst normalizeCustomServerRecord = (\n value: unknown,\n): MCPCustomServerRecord | null => {\n if (isCustomServerRecord(value)) return value;\n if (!isRecord(value)) return null;\n\n const record = { ...value };\n delete record.connectionTimeout;\n return isCustomServerRecord(record) ? record : null;\n};\n\nexport const normalizeCustomServerRecords = (\n value: unknown,\n): MCPCustomServerRecord[] => {\n if (!Array.isArray(value)) return [];\n return value.flatMap((item) => {\n const record = normalizeCustomServerRecord(item);\n return record === null ? [] : [record];\n });\n};\n\nconst normalizeOAuthTokens = (\n value: unknown,\n): MCPPersistedAuthState[\"tokens\"] | undefined => {\n const result = OAuthTokensSchema.safeParse(value);\n return result.success ? result.data : undefined;\n};\n\nconst normalizeClientInformation = (\n value: unknown,\n): MCPPersistedAuthState[\"clientInformation\"] | undefined => {\n const result = OAuthClientInformationFullSchema.safeParse(value);\n return result.success ? result.data : undefined;\n};\n\nconst isSecureNetworkUrl = (value: unknown): value is string => {\n if (!isNonEmptyString(value)) return false;\n try {\n const url = new URL(value);\n const isIpv4Loopback = /^127(?:\\.\\d{1,3}){3}$/.test(url.hostname);\n return (\n url.protocol === \"https:\" ||\n (url.protocol === \"http:\" &&\n (url.hostname === \"localhost\" ||\n url.hostname.endsWith(\".localhost\") ||\n isIpv4Loopback ||\n url.hostname === \"[::1]\"))\n );\n } catch {\n return false;\n }\n};\n\nconst isMcpServerUrl = (value: unknown): value is string => {\n if (typeof value !== \"string\") return false;\n try {\n const url = new URL(value);\n return url.protocol === \"https:\" || url.protocol === \"http:\";\n } catch {\n return false;\n }\n};\n\nconst normalizeDiscoveryState = (\n value: unknown,\n): MCPPersistedAuthState[\"discoveryState\"] | undefined => {\n if (!isRecord(value) || !isSecureNetworkUrl(value.authorizationServerUrl)) {\n return undefined;\n }\n\n // A malformed optional field is dropped alone: keeping the validated\n // authorization server URL preserves the redirect-time binding, and the SDK\n // re-discovers whatever metadata is missing.\n const state: NonNullable<MCPPersistedAuthState[\"discoveryState\"]> = {\n authorizationServerUrl: value.authorizationServerUrl,\n };\n\n if (isSecureNetworkUrl(value.resourceMetadataUrl)) {\n state.resourceMetadataUrl = value.resourceMetadataUrl;\n }\n\n const metadata = OAuthMetadataSchema.safeParse(\n value.authorizationServerMetadata,\n );\n if (metadata.success) state.authorizationServerMetadata = metadata.data;\n\n const resourceMetadata = OAuthProtectedResourceMetadataSchema.safeParse(\n value.resourceMetadata,\n );\n if (resourceMetadata.success) state.resourceMetadata = resourceMetadata.data;\n\n return state;\n};\n\nexport const normalizePersistedAuthState = (\n value: unknown,\n): MCPPersistedAuthState | null => {\n if (!isRecord(value)) return null;\n if (\"serverUrl\" in value && !isMcpServerUrl(value.serverUrl)) return null;\n\n const state: MCPPersistedAuthState = {};\n if (isMcpServerUrl(value.serverUrl)) {\n state.serverUrl = normalizeMcpServerUrl(value.serverUrl);\n }\n if (isNonEmptyString(value.token)) state.token = value.token;\n if (isNonEmptyString(value.tokensClientId)) {\n state.tokensClientId = value.tokensClientId;\n }\n if (isNonEmptyString(value.codeVerifier)) {\n state.codeVerifier = value.codeVerifier;\n }\n if (isNonEmptyString(value.state)) state.state = value.state;\n\n const tokens = normalizeOAuthTokens(value.tokens);\n if (tokens) state.tokens = tokens;\n\n const clientInformation = normalizeClientInformation(value.clientInformation);\n if (clientInformation) state.clientInformation = clientInformation;\n if (value.clientInformationSource === \"registered\") {\n state.clientInformationSource = value.clientInformationSource;\n }\n\n const discoveryState = normalizeDiscoveryState(value.discoveryState);\n if (discoveryState) state.discoveryState = discoveryState;\n\n return Object.keys(state).length > 0 ? state : null;\n};\n\nconst useMcpLocalStorage = (opts: McpLocalStorageOptions = {}): MCPStorage => {\n const prefix = opts.keyPrefix ?? \"aui-mcp\";\n const storage = resolveStorage(opts);\n // Deriving a scope from the prefix is only honest for the shared\n // globalThis.localStorage; two custom backing stores under one prefix hold\n // different data, so an overridden backing declares no scope unless the\n // caller names one.\n const scopeId =\n opts.scopeId ??\n (opts.storage === undefined ? `local-storage:${prefix}` : undefined);\n\n // Callers key per-server coordination state on this instance, so it has to\n // stay referentially stable for as long as the underlying store does.\n return useMemo(() => {\n const customServersKey = `${prefix}:custom-servers`;\n const authKey = (id: string) => `${prefix}:auth:${id}`;\n\n const read = <T>(key: string, fallback: T): T => {\n if (!storage) return fallback;\n try {\n const raw = storage.getItem(key);\n if (raw == null) return fallback;\n return JSON.parse(raw) as T;\n } catch {\n return fallback;\n }\n };\n\n const write = (key: string, value: unknown): void => {\n if (!storage) return;\n try {\n storage.setItem(key, JSON.stringify(value));\n } catch {\n // quota or serialization failure — silently drop\n }\n };\n\n const remove = (key: string): void => {\n if (!storage) return;\n try {\n storage.removeItem(key);\n } catch {\n // ignore\n }\n };\n\n return {\n ...(scopeId !== undefined ? { scopeId } : {}),\n loadCustomServers: async () =>\n normalizeCustomServerRecords(read<unknown>(customServersKey, [])),\n saveCustomServers: async (records) => {\n write(customServersKey, records);\n },\n loadAuthState: async (id) =>\n normalizePersistedAuthState(read<unknown>(authKey(id), null)),\n saveAuthState: async (id, state) => {\n write(authKey(id), state);\n },\n clearAuthState: async (id) => {\n remove(authKey(id));\n },\n };\n }, [prefix, storage, scopeId]);\n};\n\nexport const McpLocalStorage = resource(useMcpLocalStorage);\n"],"mappings":";;;;;;;AA4BA,SAASiB,eAAeC,MAA8C;CACpE,IAAIA,KAAKJ,SAAS,OAAOI,KAAKJ;CAC9B,IAAI,OAAOK,eAAe,eAAe,kBAAkBA,YACzD,IAAI;EACF,OAAQA,WAAyCC;CACnD,QAAQ;EACN,OAAO;CACT;CAEF,OAAO;AACT;AAEA,MAAMC,YAAYC,UAChB,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACE,MAAMC,QAAQH,KAAK;AAErE,MAAMI,oBAAoBJ,UACxBA,UAAUK,KAAAA,KAAa,OAAOL,UAAU;AAE1C,MAAMM,oBAAoBN,UACxB,OAAOA,UAAU,YAAYA,MAAMO,KAAK,CAAC,CAACC,SAAS;AAErD,MAAMC,4BACJT,UAEAA,UAAUK,KAAAA,KAAaC,iBAAiBN,KAAK;AAE/C,MAAMU,yBAAyBV,UAC7BA,UAAUK,KAAAA,KACTH,MAAMC,QAAQH,KAAK,KAAKA,MAAMW,OAAOC,SAAS,OAAOA,SAAS,QAAQ;AAEzE,MAAMC,+BACJb,UAEAA,UAAUK,KAAAA,KACT,OAAOL,UAAU,YAAYc,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AAA9B,EAAA;CAAA,IAAAgC;CAAA,IAAAhC,EAAA,QAAAO,WAAAP,EAAA,QAAAqB,OAAA;EAChDW,MAAA,OAAAC,MAAAnD,UAAA;GACbuC,MAAMd,QAAQ7D,IAAE,GAAGoC,KAAK;EAAC;EAC1BkB,EAAA,MAAAO;EAAAP,EAAA,MAAAqB;EAAArB,EAAA,MAAAgC;CAAA,OAAAA,MAAAhC,EAAA;CAAA,IAAAkC;CAAA,IAAAlC,EAAA,QAAAO,WAAAP,EAAA,QAAAyB,QAAA;EACeS,MAAA,OAAAC,SAAA;GACdV,OAAOlB,QAAQ7D,IAAE,CAAC;EAAC;EACpBsD,EAAA,MAAAO;EAAAP,EAAA,MAAAyB;EAAAzB,EAAA,MAAAkC;CAAA,OAAAA,MAAAlC,EAAA;CAAA,IAAAoC;CAAA,IAAApC,EAAA,QAAA8B,OAAA9B,EAAA,QAAAgC,OAAAhC,EAAA,QAAAkC,OAAAlC,EAAA,QAAA0B,MAAA1B,EAAA,QAAA2B,MAAA3B,EAAA,QAAA4B,IAAA;EAdIQ,MAAA;GAAA,GACDV;GAAwCW,mBACzBV;GACgDW,mBAChDV;GAElBW,eACcT;GACgDU,eAChDR;GAEdS,gBACeP;EAGlB;EAAClC,EAAA,MAAA8B;EAAA9B,EAAA,MAAAgC;EAAAhC,EAAA,MAAAkC;EAAAlC,EAAA,MAAA0B;EAAA1B,EAAA,MAAA2B;EAAA3B,EAAA,MAAA4B;EAAA5B,EAAA,MAAAoC;CAAA,OAAAA,MAAApC,EAAA;CAAA,OAfDoC;AAeE;AAIN,MAAaM,kBAAkBvI,SAAS2F,kBAAkB"}
@@ -1,5 +1,3 @@
1
- import { MCPStorage } from "./types.js";
2
- //#region src/resources/storage/McpMemoryStorage.d.ts
1
+ import type { MCPStorage } from "./types.js";
3
2
  export declare const McpMemoryStorage: import("@assistant-ui/tap").Resource<MCPStorage, []>;
4
- //#endregion
5
3
  //# sourceMappingURL=McpMemoryStorage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"McpMemoryStorage.d.ts","names":[],"sources":["../../../src/resources/storage/McpMemoryStorage.ts"],"mappings":";;qBA6Ba,8CAAgB,SAAA"}
1
+ {"version":3,"file":"McpMemoryStorage.d.ts","sourceRoot":"","sources":["../../../src/resources/storage/McpMemoryStorage.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAgB;AAwB1C,eAAO,MAAM,gBAAgB,sDAAgC,CAAC"}
@@ -1,28 +1,26 @@
1
- import { MCPCustomServerRecord } from "../../mcp-scope.js";
2
- import { MCPPersistedAuthState } from "../../auth/types.js";
3
- import { ResourceElement } from "@assistant-ui/tap";
4
- //#region src/resources/storage/types.d.ts
1
+ import { type ResourceElement } from "@assistant-ui/tap";
2
+ import type { MCPCustomServerRecord } from "../../mcp-scope.js";
3
+ import type { MCPPersistedAuthState } from "../../auth/types.js";
5
4
  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, custom servers,
9
- * server connections, and the OAuth write fence key on it. Swapping to a
10
- * differently-scoped storage rehydrates its custom servers and reconnects
11
- * authenticated servers instead of retaining data or a live OAuth flow from
12
- * the replaced store. Clearing through a same-scoped replacement still waits
13
- * for writes queued against the storage it replaced. When absent, the fence
14
- * falls back to object identity while custom servers and connections never
15
- * re-key. Replacing an unscoped storage can therefore persist the previous
16
- * store's custom servers into the replacement, and a clear runs unfenced
17
- * against writes queued by the object it replaced.
18
- */
19
- scopeId?: string;
20
- loadCustomServers: () => Promise<MCPCustomServerRecord[]>;
21
- saveCustomServers: (records: MCPCustomServerRecord[]) => Promise<void>;
22
- loadAuthState: (serverId: string) => Promise<MCPPersistedAuthState | null>;
23
- saveAuthState: (serverId: string, state: MCPPersistedAuthState) => Promise<void>;
24
- clearAuthState: (serverId: string) => Promise<void>;
5
+ /**
6
+ * Stable identity of the backing store. Two storages with the same scopeId
7
+ * must read and write the same persisted data. When present, custom servers,
8
+ * server connections, and the OAuth write fence key on it. Swapping to a
9
+ * differently-scoped storage rehydrates its custom servers and reconnects
10
+ * authenticated servers instead of retaining data or a live OAuth flow from
11
+ * the replaced store. Clearing through a same-scoped replacement still waits
12
+ * for writes queued against the storage it replaced. When absent, the fence
13
+ * falls back to object identity while custom servers and connections never
14
+ * re-key. Replacing an unscoped storage can therefore persist the previous
15
+ * store's custom servers into the replacement, and a clear runs unfenced
16
+ * against writes queued by the object it replaced.
17
+ */
18
+ scopeId?: string;
19
+ loadCustomServers: () => Promise<MCPCustomServerRecord[]>;
20
+ saveCustomServers: (records: MCPCustomServerRecord[]) => Promise<void>;
21
+ loadAuthState: (serverId: string) => Promise<MCPPersistedAuthState | null>;
22
+ saveAuthState: (serverId: string, state: MCPPersistedAuthState) => Promise<void>;
23
+ clearAuthState: (serverId: string) => Promise<void>;
25
24
  };
26
25
  export type MCPStorageElement = ResourceElement<MCPStorage>;
27
- //#endregion
28
26
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/resources/storage/types.ts"],"mappings":";;;;YAIY;;;;;;;;;;;;;;EAcV;EACA,yBAAyB,QAAQ;EACjC,oBAAoB,SAAS,4BAA4B;EACzD,gBAAgB,qBAAqB,QAAQ;EAC7C,gBACE,kBACA,OAAO,0BACJ;EACL,iBAAiB,qBAAqB;;YAG5B,oBAAoB,gBAAgB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/resources/storage/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,qBAAqB,EAAE,2BAAwB;AAC7D,OAAO,KAAK,EAAE,qBAAqB,EAAE,4BAAyB;AAE9D,MAAM,MAAM,UAAU,GAAG;IACvB;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAAC;IAC1D,iBAAiB,EAAE,CAAC,OAAO,EAAE,qBAAqB,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvE,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAAC;IAC3E,aAAa,EAAE,CACb,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,qBAAqB,KACzB,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACrD,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC"}
@@ -1,8 +1,7 @@
1
- //#region src/resources/validateElicitationContent.d.ts
2
1
  type ValidationError = {
3
- property: string;
4
- message: string;
2
+ property: string;
3
+ message: string;
5
4
  };
6
5
  export declare const validateElicitationContent: (requestedSchema: unknown, content: Record<string, unknown>) => readonly ValidationError[];
7
- //#endregion
6
+ export {};
8
7
  //# sourceMappingURL=validateElicitationContent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validateElicitationContent.d.ts","names":[],"sources":["../../src/resources/validateElicitationContent.ts"],"mappings":";KAAK;EACH;EACA;;qBA+BW,6BACX,0BACA,SAAS,qCACC"}
1
+ {"version":3,"file":"validateElicitationContent.d.ts","sourceRoot":"","sources":["../../src/resources/validateElicitationContent.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,GAAG;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AA8BF,eAAO,MAAM,0BAA0B,GACrC,iBAAiB,OAAO,EACxB,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC/B,SAAS,eAAe,EA0C1B,CAAC"}
@@ -1,8 +1,6 @@
1
- //#region src/utils/createMcpId.d.ts
2
1
  /**
3
2
  * Both forms are alphanumeric or hyphenated, so neither can contain the
4
3
  * separators `assertValidServerId` reserves.
5
4
  */
6
5
  export declare const createMcpId: () => string;
7
- //#endregion
8
6
  //# sourceMappingURL=createMcpId.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createMcpId.d.ts","names":[],"sources":["../../src/utils/createMcpId.ts"],"mappings":";;;;;qBAMa"}
1
+ {"version":3,"file":"createMcpId.d.ts","sourceRoot":"","sources":["../../src/utils/createMcpId.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,WAAW,QAAO,MAGJ,CAAC"}
@@ -1,4 +1,2 @@
1
- //#region src/utils/invokeMcpCallback.d.ts
2
1
  export declare const invokeMcpCallback: <TArgs extends unknown[]>(name: string, callback: ((...args: TArgs) => void) | undefined, ...args: TArgs) => void;
3
- //#endregion
4
2
  //# sourceMappingURL=invokeMcpCallback.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"invokeMcpCallback.d.ts","names":[],"sources":["../../src/utils/invokeMcpCallback.ts"],"mappings":";qBAEa,oBAAqB,yBAChC,cACA,eAAe,MAAM,gCAClB,MAAM"}
1
+ {"version":3,"file":"invokeMcpCallback.d.ts","sourceRoot":"","sources":["../../src/utils/invokeMcpCallback.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,GAAI,KAAK,SAAS,OAAO,EAAE,EACvD,MAAM,MAAM,EACZ,UAAU,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,SAAS,EAChD,GAAG,MAAM,KAAK,KACb,IAEF,CAAC"}
@@ -1,5 +1,3 @@
1
- //#region src/utils/serverId.d.ts
2
1
  export declare function assertValidServerId(id: string): void;
3
2
  export declare function assertUniqueServerIds(ids: Iterable<string>): void;
4
- //#endregion
5
3
  //# sourceMappingURL=serverId.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"serverId.d.ts","names":[],"sources":["../../src/utils/serverId.ts"],"mappings":";wBAIgB,oBAAoB;wBAgBpB,sBAAsB,KAAK"}
1
+ {"version":3,"file":"serverId.d.ts","sourceRoot":"","sources":["../../src/utils/serverId.ts"],"names":[],"mappings":"AAIA,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAcpD;AAED,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,CAUjE"}
@@ -1,7 +1,5 @@
1
- import { MCPPersistedAuthState } from "../auth/types.js";
2
- //#region src/utils/serverUrl.d.ts
1
+ import type { MCPPersistedAuthState } from "../auth/types.js";
3
2
  export declare const normalizeMcpServerUrl: (serverUrl: string) => string;
4
3
  export declare const isAuthStateForServerUrl: (state: MCPPersistedAuthState | null, serverUrl: string) => boolean;
5
4
  export declare const hasPersistedCredentials: (state: MCPPersistedAuthState | null) => boolean;
6
- //#endregion
7
5
  //# sourceMappingURL=serverUrl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"serverUrl.d.ts","names":[],"sources":["../../src/utils/serverUrl.ts"],"mappings":";;qBAEa,wBAAyB;qBAGzB,0BACX,OAAO,8BACP;qBAaW,0BACX,OAAO"}
1
+ {"version":3,"file":"serverUrl.d.ts","sourceRoot":"","sources":["../../src/utils/serverUrl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,yBAAsB;AAE3D,eAAO,MAAM,qBAAqB,GAAI,WAAW,MAAM,KAAG,MAC3B,CAAC;AAEhC,eAAO,MAAM,uBAAuB,GAClC,OAAO,qBAAqB,GAAG,IAAI,EACnC,WAAW,MAAM,KAChB,OAUF,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,OAAO,qBAAqB,GAAG,IAAI,KAClC,OAA0D,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assistant-ui/react-mcp",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
4
4
  "description": "MCP server configuration and connection primitives for @assistant-ui",
5
5
  "keywords": [
6
6
  "mcp",
@@ -27,13 +27,13 @@
27
27
  ],
28
28
  "sideEffects": false,
29
29
  "dependencies": {
30
- "@assistant-ui/core": "^0.3.20",
31
- "@assistant-ui/store": "^0.3.14",
32
- "@assistant-ui/tap": "^0.9.18",
33
- "@modelcontextprotocol/client": "^2.0.0",
34
- "@modelcontextprotocol/core": "^2.0.0",
30
+ "@assistant-ui/core": "^0.3.23",
31
+ "@assistant-ui/store": "^0.3.17",
32
+ "@assistant-ui/tap": "^0.9.21",
33
+ "@modelcontextprotocol/client": "^2.2.0",
34
+ "@modelcontextprotocol/core": "^2.2.0",
35
35
  "@radix-ui/react-primitive": "^2.1.10",
36
- "assistant-stream": "^0.3.44"
36
+ "assistant-stream": "^0.3.47"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@types/react": "*",
@@ -45,13 +45,14 @@
45
45
  }
46
46
  },
47
47
  "devDependencies": {
48
- "@assistant-ui/x-buildutils": "0.0.28",
48
+ "@assistant-ui/x-buildutils": "0.0.30",
49
+ "@assistant-ui/x-react18": "0.0.0",
49
50
  "@testing-library/dom": "^10.4.2",
50
51
  "@testing-library/react": "^16.3.3",
51
52
  "@types/react": "^19.3.0",
52
53
  "jsdom": "^30.0.1",
53
54
  "react": "^19.3.0",
54
- "vitest": "^5.0.1"
55
+ "vitest": "^5.0.3"
55
56
  },
56
57
  "publishConfig": {
57
58
  "access": "public",
@@ -70,6 +71,8 @@
70
71
  "build": "aui-build",
71
72
  "test": "vitest run",
72
73
  "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
74
+ "test:peer-react18": "vitest run --config vitest.peer-react18.config.ts",
75
+ "test:types:peer-react18": "aui-react18-types",
73
76
  "test:watch": "vitest"
74
77
  }
75
78
  }