v3/implementation/adrs/ADR-024-embeddings-mcp-tools.md
Implemented | 2026-01-12
Following ADR-023 (ONNX Hyperbolic Embeddings Initialization), the CLI now has a comprehensive embeddings command with init, status, and neural subcommands. However, Claude Code and other MCP clients need programmatic access to embedding operations without invoking CLI commands.
How do we expose embedding operations through the MCP protocol for:
Following ADR-005 (MCP-First API Design):
Implement 7 MCP tools in @claude-flow/cli/src/mcp-tools/embeddings-tools.ts:
embeddings/initInitialize the ONNX embedding subsystem with hyperbolic support.
{
name: 'embeddings/init',
inputSchema: {
type: 'object',
properties: {
model: { type: 'string', enum: ['all-MiniLM-L6-v2', 'all-mpnet-base-v2'] },
hyperbolic: { type: 'boolean', default: true },
curvature: { type: 'number', default: -1 },
cacheSize: { type: 'number', default: 256 },
force: { type: 'boolean', default: false },
},
},
}
embeddings/generateGenerate embeddings for text (Euclidean or hyperbolic).
{
name: 'embeddings/generate',
inputSchema: {
type: 'object',
properties: {
text: { type: 'string', required: true },
hyperbolic: { type: 'boolean', default: false },
normalize: { type: 'boolean', default: true },
},
},
}
embeddings/compareCompare similarity between two texts.
{
name: 'embeddings/compare',
inputSchema: {
type: 'object',
properties: {
text1: { type: 'string', required: true },
text2: { type: 'string', required: true },
metric: { type: 'string', enum: ['cosine', 'euclidean', 'poincare'] },
},
},
}
embeddings/searchSemantic search across stored embeddings.
{
name: 'embeddings/search',
inputSchema: {
type: 'object',
properties: {
query: { type: 'string', required: true },
topK: { type: 'number', default: 5 },
threshold: { type: 'number', default: 0.5 },
namespace: { type: 'string' },
},
},
}
embeddings/neuralNeural substrate operations (RuVector integration).
{
name: 'embeddings/neural',
inputSchema: {
type: 'object',
properties: {
action: { type: 'string', enum: ['status', 'init', 'drift', 'consolidate', 'adapt'] },
driftThreshold: { type: 'number', default: 0.3 },
decayRate: { type: 'number', default: 0.01 },
},
},
}
Actions:
status - Get neural substrate statusinit - Initialize RuVector with SONA, Flash Attention, EWC++drift - Check semantic drift statusconsolidate - Run memory consolidation (hippocampal dynamics)adapt - Trigger SONA adaptation cycleembeddings/hyperbolicHyperbolic embedding operations (Poincaré ball).
{
name: 'embeddings/hyperbolic',
inputSchema: {
type: 'object',
properties: {
action: { type: 'string', enum: ['status', 'convert', 'distance', 'midpoint'] },
embedding: { type: 'array', items: { type: 'number' } },
embedding1: { type: 'array', items: { type: 'number' } },
embedding2: { type: 'array', items: { type: 'number' } },
},
},
}
Actions:
status - Get hyperbolic configurationconvert - Convert Euclidean embedding to Poincaré balldistance - Calculate hyperbolic distance between two pointsmidpoint - Calculate hyperbolic midpointembeddings/statusGet embeddings system status and configuration.
{
name: 'embeddings/status',
inputSchema: { type: 'object', properties: {} },
}
┌─────────────────────────────────────────────────────────────┐
│ Embeddings MCP Tools │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌────────────────┐ ┌────────────────┐ ┌───────────┐ │
│ │ embeddings/ │ │ embeddings/ │ │embeddings/│ │
│ │ init │ │ generate │ │ compare │ │
│ └───────┬────────┘ └───────┬────────┘ └─────┬─────┘ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────────────────────────────────────────────────────┐│
│ │ Configuration Layer ││
│ │ .claude-flow/embeddings.json (persistent config) ││
│ └─────────────────────────────────────────────────────────┘│
│ │ │
│ ┌───────────────┼───────────────┐ │
│ ▼ ▼ ▼ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Embedding │ │ Hyperbolic │ │ Neural │ │
│ │ Generation │ │ Projection │ │ Substrate │ │
│ │ (mock/ONNX) │ │ (Poincaré) │ │ (RuVector) │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │
│ ┌────────────────┐ ┌────────────────┐ ┌───────────┐ │
│ │ embeddings/ │ │ embeddings/ │ │embeddings/│ │
│ │ search │ │ neural │ │hyperbolic │ │
│ └────────────────┘ └────────────────┘ └───────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
Exponential Map (Euclidean → Poincaré):
exp_0(v) = tanh(√c · ||v|| / 2) · v / (√c · ||v||)
Poincaré Distance:
d(x, y) = (1/√c) · arcosh(1 + 2c · ||x-y||² / ((1-c||x||²)(1-c||y||²)))
Hyperbolic Midpoint (simplified):
m(x, y) = scale · (x + y) / 2
where scale ensures ||m|| < maxNorm
Tools store configuration in .claude-flow/embeddings.json:
{
"model": "all-MiniLM-L6-v2",
"modelPath": ".claude-flow/models",
"dimension": 384,
"cacheSize": 256,
"hyperbolic": {
"enabled": true,
"curvature": -1,
"epsilon": 1e-15,
"maxNorm": 0.99999
},
"neural": {
"enabled": true,
"driftThreshold": 0.3,
"decayRate": 0.01,
"ruvector": {
"enabled": true,
"sona": true,
"flashAttention": true,
"ewcPlusPlus": true
},
"features": {
"semanticDrift": true,
"memoryPhysics": true,
"stateMachine": true,
"swarmCoordination": true,
"coherenceMonitor": true
}
},
"initialized": "2026-01-12T18:30:00.000Z"
}
Tools are registered in mcp-client.ts:
import { embeddingsTools } from './mcp-tools/embeddings-tools.js';
registerTools([
// ... existing tools
...embeddingsTools,
]);
And exported from mcp-tools/index.ts:
export { embeddingsTools } from './embeddings-tools.js';
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "embeddings/init",
"arguments": {
"model": "all-MiniLM-L6-v2",
"hyperbolic": true,
"curvature": -1
}
}
}
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "embeddings/generate",
"arguments": {
"text": "async function processData()",
"hyperbolic": true
}
}
}
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "embeddings/compare",
"arguments": {
"text1": "authentication middleware",
"text2": "auth guard handler",
"metric": "cosine"
}
}
}
{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "embeddings/neural",
"arguments": { "action": "status" }
}
}
embeddings category to tool list