diff --git a/cloud-wrapper/src/index.ts b/cloud-wrapper/src/index.ts index d072e821..f820daff 100644 --- a/cloud-wrapper/src/index.ts +++ b/cloud-wrapper/src/index.ts @@ -9,6 +9,7 @@ import { BrainyData } from '@soulcraft/brainy'; import { setupRoutes } from './routes.js'; import { initializeBrainy } from './services/brainyService.js'; import { setupWebSocketHandlers } from './websocket.js'; +import { initializeMCPService } from './services/mcpService.js'; // Load environment variables dotenv.config(); @@ -56,6 +57,25 @@ async function startServer() { setupWebSocketHandlers(wss, brainyInstance); console.log('WebSocket server initialized'); + // Initialize MCP service + const mcpWsPort = process.env.MCP_WS_PORT ? parseInt(process.env.MCP_WS_PORT, 10) : undefined; + const mcpRestPort = process.env.MCP_REST_PORT ? parseInt(process.env.MCP_REST_PORT, 10) : undefined; + + if (mcpWsPort || mcpRestPort) { + initializeMCPService(brainyInstance, { + wsPort: mcpWsPort, + restPort: mcpRestPort, + enableAuth: process.env.MCP_ENABLE_AUTH === 'true', + apiKeys: process.env.MCP_API_KEYS ? process.env.MCP_API_KEYS.split(',') : undefined, + rateLimit: process.env.MCP_RATE_LIMIT_REQUESTS ? { + windowMs: parseInt(process.env.MCP_RATE_LIMIT_WINDOW_MS || '60000', 10), + maxRequests: parseInt(process.env.MCP_RATE_LIMIT_REQUESTS, 10) + } : undefined, + cors: process.env.MCP_ENABLE_CORS === 'true' ? {} : undefined + }); + console.log('MCP service initialized'); + } + // Start HTTP server server.listen(port, () => { console.log(`Server running on port ${port}`); diff --git a/src/index.ts b/src/index.ts index 5fc2c2a3..1adf052c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -261,3 +261,44 @@ export type { Content } export { NounType, VerbType } + +// Export MCP (Model Control Protocol) components +import { + BrainyMCPAdapter, + MCPAugmentationToolset, + BrainyMCPService +} from './mcp/index.js' // Import from mcp/index.js +import { + MCPRequest, + MCPResponse, + MCPDataAccessRequest, + MCPToolExecutionRequest, + MCPSystemInfoRequest, + MCPAuthenticationRequest, + MCPRequestType, + MCPServiceOptions, + MCPTool, + MCP_VERSION +} from './types/mcpTypes.js' + +export { + // MCP classes + BrainyMCPAdapter, + MCPAugmentationToolset, + BrainyMCPService, + + // MCP types + MCPRequestType, + MCP_VERSION +} + +export type { + MCPRequest, + MCPResponse, + MCPDataAccessRequest, + MCPToolExecutionRequest, + MCPSystemInfoRequest, + MCPAuthenticationRequest, + MCPServiceOptions, + MCPTool +} diff --git a/src/unified.ts b/src/unified.ts index 8c737095..a2dbd38f 100644 --- a/src/unified.ts +++ b/src/unified.ts @@ -1,16 +1,36 @@ /** * Unified entry point for Brainy * This file exports everything from index.ts - * Environment detection is handled by the build process + * Environment detection is handled here and made available to all components */ // Export environment information -// These values will be populated by the build process intro code export const environment = { isBrowser: typeof window !== 'undefined', - isNode: typeof process !== 'undefined' && process.versions && process.versions.node, - isServerless: typeof window === 'undefined' && (typeof process === 'undefined' || !process.versions || !process.versions.node) + isNode: + typeof process !== 'undefined' && process.versions && process.versions.node, + isServerless: + typeof window === 'undefined' && + (typeof process === 'undefined' || + !process.versions || + !process.versions.node) } +// Make environment information available globally +if (typeof globalThis !== 'undefined') { + globalThis.__ENV__ = environment +} + +// Log the detected environment +console.log( + `Brainy running in ${ + environment.isBrowser + ? 'browser' + : environment.isNode + ? 'Node.js' + : 'serverless/unknown' + } environment` +) + // Re-export everything from index.ts export * from './index.js'