From 00affa1b199d00b45c62bef8c05543acbd6e5d22 Mon Sep 17 00:00:00 2001 From: ceri Date: Sun, 15 Feb 2026 15:51:38 +0100 Subject: [PATCH] feat: add Brain Protocol MCP integration Add Brain Protocol as an MCP server for persistent, searchable, graph-connected agent memory with optional Starknet proof anchoring. - brain_mcp.json: local mode config (zero dependencies, SQLite) - brain_cloud_mcp.json: cloud mode with API key auth - brain_example.ts: full example with archive, query, and stats - README: add Brain Protocol section to examples list Package: https://www.npmjs.com/package/@brain-protocol/mcp Repo: https://github.com/seritalien/brain-protocol --- README.md | 20 +++++++- examples/brain_cloud_mcp.json | 13 +++++ examples/brain_example.ts | 96 +++++++++++++++++++++++++++++++++++ examples/brain_mcp.json | 9 ++++ 4 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 examples/brain_cloud_mcp.json create mode 100644 examples/brain_example.ts create mode 100644 examples/brain_mcp.json diff --git a/README.md b/README.md index 3e03489..748a961 100644 --- a/README.md +++ b/README.md @@ -399,4 +399,22 @@ The package includes several example files that demonstrate how to use MCP adapt 5. `gemini_example.ts` - Example using Google's Gemini models 6. `logging_example.ts` - Example demonstrating logging capabilities 7. `sse_with_headers_example.ts` - Example showing how to use custom headers with SSE connections -8. `uvx_npx_example.ts` - Example demonstrating how to use UVX and NPX transport types \ No newline at end of file +8. `uvx_npx_example.ts` - Example demonstrating how to use UVX and NPX transport types +9. `brain_example.ts` - Example using Brain Protocol MCP for persistent agent memory + +### Brain Protocol (Agent Memory) + +[Brain Protocol](https://github.com/seritalien/brain-protocol) provides persistent, searchable, graph-connected memory for AI agents with optional Starknet on-chain verification. + +```json +{ + "servers": { + "brain": { + "transport": "npx", + "packageName": "@brain-protocol/mcp" + } + } +} +``` + +See `examples/brain_mcp.json` for local mode and `examples/brain_cloud_mcp.json` for cloud mode with API key authentication. \ No newline at end of file diff --git a/examples/brain_cloud_mcp.json b/examples/brain_cloud_mcp.json new file mode 100644 index 0000000..9766e27 --- /dev/null +++ b/examples/brain_cloud_mcp.json @@ -0,0 +1,13 @@ +{ + "servers": { + "brain": { + "transport": "npx", + "packageName": "@brain-protocol/mcp", + "args": [], + "env": { + "BRAIN_API_URL": "https://brain.api.vauban.tech", + "BRAIN_API_KEY": "${BRAIN_API_KEY}" + } + } + } +} diff --git a/examples/brain_example.ts b/examples/brain_example.ts new file mode 100644 index 0000000..d7de25a --- /dev/null +++ b/examples/brain_example.ts @@ -0,0 +1,96 @@ +/** + * This example demonstrates how to use Brain Protocol MCP with Snak agents. + * + * Brain Protocol provides persistent, searchable, graph-connected memory for + * AI agents. It works in two modes: + * - Local: SQLite database (zero config, works offline) + * - Cloud: HTTP API with Starknet on-chain proof anchoring + * + * Available tools (16 total): + * Core: query_knowledge, archive_knowledge, update_knowledge, delete_knowledge + * Graph: create_edge, get_graph + * Utility: get_stats, export, import + * Proof: prove, verify (cloud mode) + * Agents: get_agent_stats, log_agent_task (cloud mode) + * Development: suggest_patterns, detect_antipatterns, architectural_advice (cloud mode) + * + * To run this example: + * npx tsx examples/brain_example.ts + * + * @see https://www.npmjs.com/package/@brain-protocol/mcp + * @see https://github.com/seritalien/brain-protocol + */ + +import { MultiServerMCPClient } from '../src/client.js'; + +async function main() { + console.log('=== Brain Protocol MCP — Memory for AI Agents ===\n'); + + // Connect to Brain MCP in local mode (default, zero config) + const client = new MultiServerMCPClient({ + brain: { + transport: 'npx' as const, + packageName: '@brain-protocol/mcp', + args: [], + }, + }); + + try { + console.log('Connecting to Brain Protocol MCP server...'); + await client.initializeConnections(); + console.log('Connected!\n'); + + // Get all available tools + const serverTools = client.getTools(); + const brainTools = serverTools.get('brain'); + + if (!brainTools || brainTools.length === 0) { + console.error('No tools available from Brain MCP server'); + return; + } + + console.log(`Available tools (${brainTools.length}):`); + for (const tool of brainTools) { + console.log(` - ${tool.name}: ${tool.description}`); + } + + // Step 1: Archive knowledge + console.log('\n--- Step 1: Archive Knowledge ---'); + const archiveTool = brainTools.find((t) => t.name === 'archive_knowledge'); + if (archiveTool) { + const result = await archiveTool.invoke({ + content: 'Starknet uses Poseidon hash for zero-knowledge proof efficiency. It operates on felt252 field elements.', + category: 'pattern', + tags: 'starknet,cairo,cryptography', + confidence: 0.9, + }); + console.log('Archived:', result); + } + + // Step 2: Query knowledge + console.log('\n--- Step 2: Query Knowledge ---'); + const queryTool = brainTools.find((t) => t.name === 'query_knowledge'); + if (queryTool) { + const result = await queryTool.invoke({ + q: 'starknet', + limit: 5, + }); + console.log('Query results:', result); + } + + // Step 3: Get stats + console.log('\n--- Step 3: Get Stats ---'); + const statsTool = brainTools.find((t) => t.name === 'get_stats'); + if (statsTool) { + const result = await statsTool.invoke({}); + console.log('Stats:', result); + } + } catch (error) { + console.error('Error:', error instanceof Error ? error.message : String(error)); + } finally { + await client.close(); + console.log('\nDone.'); + } +} + +main(); diff --git a/examples/brain_mcp.json b/examples/brain_mcp.json new file mode 100644 index 0000000..5b20dba --- /dev/null +++ b/examples/brain_mcp.json @@ -0,0 +1,9 @@ +{ + "servers": { + "brain": { + "transport": "npx", + "packageName": "@brain-protocol/mcp", + "args": [] + } + } +}