mirror of
https://github.com/EthanMarti/infio-copilot.git
synced 2026-05-09 16:38:19 +00:00
update , add mcp server stdio and sse
This commit is contained in:
39
src/contexts/McpHubContext.tsx
Normal file
39
src/contexts/McpHubContext.tsx
Normal file
@@ -0,0 +1,39 @@
|
||||
import {
|
||||
PropsWithChildren,
|
||||
createContext,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
} from 'react'
|
||||
|
||||
import { McpHub } from '../core/mcp/McpHub'
|
||||
|
||||
export type McpHubContextType = {
|
||||
getMcpHub: () => Promise<McpHub>
|
||||
}
|
||||
|
||||
const McpHubContext = createContext<McpHubContextType | null>(null)
|
||||
|
||||
export function McpHubProvider({
|
||||
getMcpHub,
|
||||
children,
|
||||
}: PropsWithChildren<{ getMcpHub: () => Promise<McpHub> }>) {
|
||||
useEffect(() => {
|
||||
// start initialization of mcpHub in the background
|
||||
void getMcpHub()
|
||||
}, [getMcpHub])
|
||||
|
||||
const value = useMemo(() => {
|
||||
return { getMcpHub }
|
||||
}, [getMcpHub])
|
||||
|
||||
return <McpHubContext.Provider value={value}>{children}</McpHubContext.Provider>
|
||||
}
|
||||
|
||||
export function useMcpHub() {
|
||||
const context = useContext(McpHubContext)
|
||||
if (!context) {
|
||||
throw new Error('useMcpHub must be used within a McpHubProvider')
|
||||
}
|
||||
return context
|
||||
}
|
||||
Reference in New Issue
Block a user