brainy/src/mcp
David Snelling fcb7197fb0 feat: add node: protocol to all Node.js built-in imports for bundler compatibility
- Updated all fs, path, crypto, os, url, util, events, http, https, net, child_process, stream, and zlib imports
- Changed both static imports and dynamic imports to use node: protocol
- This makes Brainy more bundler-friendly by explicitly marking Node.js built-ins
- Prevents bundlers from attempting to polyfill or bundle these modules
- Reduces bundle size for web applications using Brainy
- Improves tree-shaking and dead code elimination

Benefits for external bundlers:
- Clear distinction between Node.js built-ins and external dependencies
- No ambiguity about what needs polyfilling
- Smaller bundles for browser builds
- Better compatibility with modern bundlers (Webpack 5, Vite, Rollup, esbuild)

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-17 14:20:21 -07:00
..
brainyMCPAdapter.ts feat: modernize API architecture and deprecation handling 2025-09-17 11:54:20 -07:00
brainyMCPBroadcast.ts feat: add node: protocol to all Node.js built-in imports for bundler compatibility 2025-09-17 14:20:21 -07:00
brainyMCPClient.ts feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
brainyMCPService.ts feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
index.ts 🧠 Brainy 2.0.0 - Zero-Configuration AI Database with Triple Intelligence™ 2025-08-26 12:32:21 -07:00
mcpAugmentationToolset.ts feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
README.md 🧠 Brainy 2.0.0 - Zero-Configuration AI Database with Triple Intelligence™ 2025-08-26 12:32:21 -07:00

Model Control Protocol (MCP) for Brainy

This document provides information about the Model Control Protocol (MCP) implementation in Brainy, which allows external models to access Brainy data and use the augmentation pipeline as tools.

Components

The MCP implementation consists of three main components:

  1. BrainyMCPAdapter: Provides access to Brainy data through MCP
  2. MCPAugmentationToolset: Exposes the augmentation pipeline as tools
  3. BrainyMCPService: Integrates the adapter and toolset, providing WebSocket and REST server implementations for external model access

Environment Compatibility

BrainyMCPAdapter

The BrainyMCPAdapter has no environment-specific dependencies and can run in any environment where Brainy itself runs, including:

  • Browser environments
  • Node.js environments
  • Server environments

MCPAugmentationToolset

The MCPAugmentationToolset also has no environment-specific dependencies and can run in any environment where Brainy itself runs, including:

  • Browser environments
  • Node.js environments
  • Server environments

BrainyMCPService

The BrainyMCPService has been refactored to separate the core functionality from the Node.js-specific server functionality:

  1. Core Functionality: The core request handling functionality (handleMCPRequest) can run in any environment where Brainy itself runs. This is what remains in the main Brainy package.

  2. Server Functionality: The WebSocket and REST server functionality is not included in the main Brainy package to keep the browser bundle lightweight and avoid Node.js-specific dependencies. In browser or other environments, you can use the core functionality through the handleMCPRequest method.

Usage

In Any Environment (Browser, Node.js, Server)

import { BrainyData, BrainyMCPAdapter, MCPAugmentationToolset } from '@soulcraft/brainy'

// Create a BrainyData instance
const brainyData = new BrainyData()
await brainyData.init()

// Create an MCP adapter
const adapter = new BrainyMCPAdapter(brainyData)

// Create a toolset
const toolset = new MCPAugmentationToolset()

// Use the adapter to access Brainy data
const response = await adapter.handleRequest({
  type: 'data_access',
  operation: 'search',
  requestId: adapter.generateRequestId(),
  version: '1.0.0',
  parameters: {
    query: 'example query',
    k: 5
  }
})

// Use the toolset to execute augmentation pipeline tools
const toolResponse = await toolset.handleRequest({
  type: 'tool_execution',
  toolName: 'brainy_memory_storeData',
  requestId: toolset.generateRequestId(),
  version: '1.0.0',
  parameters: {
    args: ['key1', { some: 'data' }]
  }
})

In Browser Environment (Core Functionality Only)

import { BrainyData, BrainyMCPService } from '@soulcraft/brainy'

// Create a BrainyData instance
const brainyData = new BrainyData()
await brainyData.init()

// Create an MCP service (server functionality will be disabled in browser)
const mcpService = new BrainyMCPService(brainyData)

// Use the core functionality
const response = await mcpService.handleMCPRequest({
  type: 'data_access',
  operation: 'search',
  requestId: mcpService.generateRequestId(),
  version: '1.0.0',
  parameters: {
    query: 'example query',
    k: 5
  }
})