Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.
13 changes: 13 additions & 0 deletions examples/brain_cloud_mcp.json
Original file line number Diff line number Diff line change
@@ -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}"
}
}
}
}
96 changes: 96 additions & 0 deletions examples/brain_example.ts
Original file line number Diff line number Diff line change
@@ -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();
9 changes: 9 additions & 0 deletions examples/brain_mcp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"servers": {
"brain": {
"transport": "npx",
"packageName": "@brain-protocol/mcp",
"args": []
}
}
}