import { PropsWithChildren, createContext, useContext, useEffect, useMemo, } from 'react' import { McpHub } from '../core/mcp/McpHub' export type McpHubContextType = { getMcpHub: () => Promise } const McpHubContext = createContext(null) export function McpHubProvider({ getMcpHub, children, }: PropsWithChildren<{ getMcpHub: () => Promise }>) { useEffect(() => { // start initialization of mcpHub in the background void getMcpHub() }, [getMcpHub]) const value = useMemo(() => { return { getMcpHub } }, [getMcpHub]) return {children} } export function useMcpHub() { const context = useContext(McpHubContext) if (!context) { throw new Error('useMcpHub must be used within a McpHubProvider') } return context }