agentdb 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +38 -0
- package/LICENSE-APACHE +190 -0
- package/LICENSE-MIT +21 -0
- package/README.md +953 -0
- package/bin/agentdb.js +485 -0
- package/bin/plugin-cli-wrapper.mjs +21 -0
- package/dist/cache/query-cache.d.ts +105 -0
- package/dist/cache/query-cache.d.ts.map +1 -0
- package/dist/cache/query-cache.js +224 -0
- package/dist/cache/query-cache.js.map +1 -0
- package/dist/cache/query-cache.mjs +219 -0
- package/dist/cli/cache/query-cache.d.ts +104 -0
- package/dist/cli/cache/query-cache.js +244 -0
- package/dist/cli/cli/db-commands.d.ts +48 -0
- package/dist/cli/cli/db-commands.js +613 -0
- package/dist/cli/commands.d.ts +7 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +113 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/commands.mjs +104 -0
- package/dist/cli/core/backend-interface.d.ts +70 -0
- package/dist/cli/core/backend-interface.js +15 -0
- package/dist/cli/core/native-backend.d.ts +140 -0
- package/dist/cli/core/native-backend.js +432 -0
- package/dist/cli/core/vector-db.d.ts +126 -0
- package/dist/cli/core/vector-db.js +338 -0
- package/dist/cli/core/wasm-backend.d.ts +95 -0
- package/dist/cli/core/wasm-backend.js +418 -0
- package/dist/cli/db-commands.d.ts +49 -0
- package/dist/cli/db-commands.d.ts.map +1 -0
- package/dist/cli/db-commands.js +533 -0
- package/dist/cli/db-commands.js.map +1 -0
- package/dist/cli/db-commands.mjs +522 -0
- package/dist/cli/generator.d.ts +11 -0
- package/dist/cli/generator.d.ts.map +1 -0
- package/dist/cli/generator.js +567 -0
- package/dist/cli/generator.js.map +1 -0
- package/dist/cli/generator.mjs +527 -0
- package/dist/cli/help.d.ts +18 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/help.js +676 -0
- package/dist/cli/help.js.map +1 -0
- package/dist/cli/help.mjs +667 -0
- package/dist/cli/index/hnsw.d.ts +164 -0
- package/dist/cli/index/hnsw.js +558 -0
- package/dist/cli/plugin-cli.d.ts +7 -0
- package/dist/cli/plugin-cli.d.ts.map +1 -0
- package/dist/cli/plugin-cli.js +295 -0
- package/dist/cli/plugin-cli.js.map +1 -0
- package/dist/cli/plugin-cli.mjs +289 -0
- package/dist/cli/quantization/product-quantization.d.ts +108 -0
- package/dist/cli/quantization/product-quantization.js +350 -0
- package/dist/cli/query/query-builder.d.ts +322 -0
- package/dist/cli/query/query-builder.js +600 -0
- package/dist/cli/templates.d.ts +14 -0
- package/dist/cli/templates.d.ts.map +1 -0
- package/dist/cli/templates.js +182 -0
- package/dist/cli/templates.js.map +1 -0
- package/dist/cli/templates.mjs +176 -0
- package/dist/cli/types/index.d.ts +116 -0
- package/dist/cli/types/index.js +5 -0
- package/dist/cli/types.d.ts +91 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +6 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/types.mjs +4 -0
- package/dist/cli/wizard/index.d.ts +6 -0
- package/dist/cli/wizard/index.d.ts.map +1 -0
- package/dist/cli/wizard/index.js +138 -0
- package/dist/cli/wizard/index.js.map +1 -0
- package/dist/cli/wizard/index.mjs +131 -0
- package/dist/cli/wizard/prompts.d.ts +11 -0
- package/dist/cli/wizard/prompts.d.ts.map +1 -0
- package/dist/cli/wizard/prompts.js +482 -0
- package/dist/cli/wizard/prompts.js.map +1 -0
- package/dist/cli/wizard/prompts.mjs +470 -0
- package/dist/cli/wizard/validator.d.ts +13 -0
- package/dist/cli/wizard/validator.d.ts.map +1 -0
- package/dist/cli/wizard/validator.js +234 -0
- package/dist/cli/wizard/validator.js.map +1 -0
- package/dist/cli/wizard/validator.mjs +224 -0
- package/dist/core/backend-interface.d.ts +71 -0
- package/dist/core/backend-interface.d.ts.map +1 -0
- package/dist/core/backend-interface.js +16 -0
- package/dist/core/backend-interface.js.map +1 -0
- package/dist/core/backend-interface.mjs +12 -0
- package/dist/core/native-backend.d.ts +141 -0
- package/dist/core/native-backend.d.ts.map +1 -0
- package/dist/core/native-backend.js +457 -0
- package/dist/core/native-backend.js.map +1 -0
- package/dist/core/native-backend.mjs +449 -0
- package/dist/core/vector-db.d.ts +127 -0
- package/dist/core/vector-db.d.ts.map +1 -0
- package/dist/core/vector-db.js +266 -0
- package/dist/core/vector-db.js.map +1 -0
- package/dist/core/vector-db.mjs +261 -0
- package/dist/core/wasm-backend.d.ts +96 -0
- package/dist/core/wasm-backend.d.ts.map +1 -0
- package/dist/core/wasm-backend.js +393 -0
- package/dist/core/wasm-backend.js.map +1 -0
- package/dist/core/wasm-backend.mjs +385 -0
- package/dist/index/hnsw-optimized.d.ts +75 -0
- package/dist/index/hnsw-optimized.d.ts.map +1 -0
- package/dist/index/hnsw-optimized.js +412 -0
- package/dist/index/hnsw-optimized.js.map +1 -0
- package/dist/index/hnsw-optimized.mjs +407 -0
- package/dist/index/hnsw.d.ts +165 -0
- package/dist/index/hnsw.d.ts.map +1 -0
- package/dist/index/hnsw.js +521 -0
- package/dist/index/hnsw.js.map +1 -0
- package/dist/index/hnsw.mjs +516 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +63 -0
- package/dist/mcp-server.d.ts +27 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +789 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/mcp-server.mjs +784 -0
- package/dist/plugins/base-plugin.d.ts +114 -0
- package/dist/plugins/base-plugin.d.ts.map +1 -0
- package/dist/plugins/base-plugin.js +313 -0
- package/dist/plugins/base-plugin.js.map +1 -0
- package/dist/plugins/base-plugin.mjs +275 -0
- package/dist/plugins/implementations/active-learning.d.ts +135 -0
- package/dist/plugins/implementations/active-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/active-learning.js +372 -0
- package/dist/plugins/implementations/active-learning.js.map +1 -0
- package/dist/plugins/implementations/active-learning.mjs +367 -0
- package/dist/plugins/implementations/actor-critic.d.ts +64 -0
- package/dist/plugins/implementations/actor-critic.d.ts.map +1 -0
- package/dist/plugins/implementations/actor-critic.js +363 -0
- package/dist/plugins/implementations/actor-critic.js.map +1 -0
- package/dist/plugins/implementations/actor-critic.mjs +358 -0
- package/dist/plugins/implementations/adversarial-training.d.ts +133 -0
- package/dist/plugins/implementations/adversarial-training.d.ts.map +1 -0
- package/dist/plugins/implementations/adversarial-training.js +409 -0
- package/dist/plugins/implementations/adversarial-training.js.map +1 -0
- package/dist/plugins/implementations/adversarial-training.mjs +404 -0
- package/dist/plugins/implementations/curriculum-learning.d.ts +132 -0
- package/dist/plugins/implementations/curriculum-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/curriculum-learning.js +354 -0
- package/dist/plugins/implementations/curriculum-learning.js.map +1 -0
- package/dist/plugins/implementations/curriculum-learning.mjs +349 -0
- package/dist/plugins/implementations/decision-transformer.d.ts +77 -0
- package/dist/plugins/implementations/decision-transformer.d.ts.map +1 -0
- package/dist/plugins/implementations/decision-transformer.js +422 -0
- package/dist/plugins/implementations/decision-transformer.js.map +1 -0
- package/dist/plugins/implementations/decision-transformer.mjs +417 -0
- package/dist/plugins/implementations/federated-learning.d.ts +126 -0
- package/dist/plugins/implementations/federated-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/federated-learning.js +436 -0
- package/dist/plugins/implementations/federated-learning.js.map +1 -0
- package/dist/plugins/implementations/federated-learning.mjs +431 -0
- package/dist/plugins/implementations/index.d.ts +30 -0
- package/dist/plugins/implementations/index.d.ts.map +1 -0
- package/dist/plugins/implementations/index.js +45 -0
- package/dist/plugins/implementations/index.js.map +1 -0
- package/dist/plugins/implementations/index.mjs +31 -0
- package/dist/plugins/implementations/multi-task-learning.d.ts +115 -0
- package/dist/plugins/implementations/multi-task-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/multi-task-learning.js +369 -0
- package/dist/plugins/implementations/multi-task-learning.js.map +1 -0
- package/dist/plugins/implementations/multi-task-learning.mjs +364 -0
- package/dist/plugins/implementations/neural-architecture-search.d.ts +148 -0
- package/dist/plugins/implementations/neural-architecture-search.d.ts.map +1 -0
- package/dist/plugins/implementations/neural-architecture-search.js +379 -0
- package/dist/plugins/implementations/neural-architecture-search.js.map +1 -0
- package/dist/plugins/implementations/neural-architecture-search.mjs +374 -0
- package/dist/plugins/implementations/q-learning.d.ts +98 -0
- package/dist/plugins/implementations/q-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/q-learning.js +435 -0
- package/dist/plugins/implementations/q-learning.js.map +1 -0
- package/dist/plugins/implementations/q-learning.mjs +430 -0
- package/dist/plugins/implementations/sarsa.d.ts +103 -0
- package/dist/plugins/implementations/sarsa.d.ts.map +1 -0
- package/dist/plugins/implementations/sarsa.js +347 -0
- package/dist/plugins/implementations/sarsa.js.map +1 -0
- package/dist/plugins/implementations/sarsa.mjs +342 -0
- package/dist/plugins/index.d.ts +107 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +179 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/index.mjs +168 -0
- package/dist/plugins/interface.d.ts +439 -0
- package/dist/plugins/interface.d.ts.map +1 -0
- package/dist/plugins/interface.js +12 -0
- package/dist/plugins/interface.js.map +1 -0
- package/dist/plugins/interface.mjs +10 -0
- package/dist/plugins/learning-plugin.interface.d.ts +257 -0
- package/dist/plugins/learning-plugin.interface.d.ts.map +1 -0
- package/dist/plugins/learning-plugin.interface.js +7 -0
- package/dist/plugins/learning-plugin.interface.js.map +1 -0
- package/dist/plugins/learning-plugin.interface.mjs +5 -0
- package/dist/plugins/plugin-exports.d.ts +71 -0
- package/dist/plugins/plugin-exports.d.ts.map +1 -0
- package/dist/plugins/plugin-exports.js +78 -0
- package/dist/plugins/plugin-exports.js.map +1 -0
- package/dist/plugins/plugin-exports.mjs +69 -0
- package/dist/plugins/registry.d.ts +206 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +365 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/plugins/registry.mjs +356 -0
- package/dist/plugins/validator.d.ts +63 -0
- package/dist/plugins/validator.d.ts.map +1 -0
- package/dist/plugins/validator.js +464 -0
- package/dist/plugins/validator.js.map +1 -0
- package/dist/plugins/validator.mjs +458 -0
- package/dist/quantization/binary-quantization.d.ts +104 -0
- package/dist/quantization/binary-quantization.d.ts.map +1 -0
- package/dist/quantization/binary-quantization.js +246 -0
- package/dist/quantization/binary-quantization.js.map +1 -0
- package/dist/quantization/binary-quantization.mjs +240 -0
- package/dist/quantization/optimized-pq.d.ts +138 -0
- package/dist/quantization/optimized-pq.d.ts.map +1 -0
- package/dist/quantization/optimized-pq.js +320 -0
- package/dist/quantization/optimized-pq.js.map +1 -0
- package/dist/quantization/optimized-pq.mjs +313 -0
- package/dist/quantization/product-quantization.d.ts +109 -0
- package/dist/quantization/product-quantization.d.ts.map +1 -0
- package/dist/quantization/product-quantization.js +287 -0
- package/dist/quantization/product-quantization.js.map +1 -0
- package/dist/quantization/product-quantization.mjs +282 -0
- package/dist/quantization/scalar-quantization.d.ts +100 -0
- package/dist/quantization/scalar-quantization.d.ts.map +1 -0
- package/dist/quantization/scalar-quantization.js +324 -0
- package/dist/quantization/scalar-quantization.js.map +1 -0
- package/dist/quantization/scalar-quantization.mjs +319 -0
- package/dist/query/index.d.ts +6 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +9 -0
- package/dist/query/index.js.map +1 -0
- package/dist/query/index.mjs +4 -0
- package/dist/query/query-builder.d.ts +323 -0
- package/dist/query/query-builder.d.ts.map +1 -0
- package/dist/query/query-builder.js +524 -0
- package/dist/query/query-builder.js.map +1 -0
- package/dist/query/query-builder.mjs +519 -0
- package/dist/reasoning/context-synthesizer.d.ts +57 -0
- package/dist/reasoning/context-synthesizer.d.ts.map +1 -0
- package/dist/reasoning/context-synthesizer.js +224 -0
- package/dist/reasoning/context-synthesizer.js.map +1 -0
- package/dist/reasoning/context-synthesizer.mjs +219 -0
- package/dist/reasoning/experience-curator.d.ts +66 -0
- package/dist/reasoning/experience-curator.d.ts.map +1 -0
- package/dist/reasoning/experience-curator.js +288 -0
- package/dist/reasoning/experience-curator.js.map +1 -0
- package/dist/reasoning/experience-curator.mjs +283 -0
- package/dist/reasoning/memory-optimizer.d.ts +69 -0
- package/dist/reasoning/memory-optimizer.d.ts.map +1 -0
- package/dist/reasoning/memory-optimizer.js +331 -0
- package/dist/reasoning/memory-optimizer.js.map +1 -0
- package/dist/reasoning/memory-optimizer.mjs +326 -0
- package/dist/reasoning/pattern-matcher.d.ts +59 -0
- package/dist/reasoning/pattern-matcher.d.ts.map +1 -0
- package/dist/reasoning/pattern-matcher.js +229 -0
- package/dist/reasoning/pattern-matcher.js.map +1 -0
- package/dist/reasoning/pattern-matcher.mjs +224 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.d.ts +118 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.d.ts.map +1 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.js +477 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.js.map +1 -0
- package/dist/reasoningbank/adapter/types.d.ts +113 -0
- package/dist/reasoningbank/adapter/types.d.ts.map +1 -0
- package/dist/reasoningbank/adapter/types.js +9 -0
- package/dist/reasoningbank/adapter/types.js.map +1 -0
- package/dist/reasoningbank/cli/commands.d.ts +16 -0
- package/dist/reasoningbank/cli/commands.d.ts.map +1 -0
- package/dist/reasoningbank/cli/commands.js +272 -0
- package/dist/reasoningbank/cli/commands.js.map +1 -0
- package/dist/reasoningbank/mcp/agentdb-tools.d.ts +319 -0
- package/dist/reasoningbank/mcp/agentdb-tools.d.ts.map +1 -0
- package/dist/reasoningbank/mcp/agentdb-tools.js +301 -0
- package/dist/reasoningbank/mcp/agentdb-tools.js.map +1 -0
- package/dist/reasoningbank/migration/migrate.d.ts +25 -0
- package/dist/reasoningbank/migration/migrate.d.ts.map +1 -0
- package/dist/reasoningbank/migration/migrate.js +178 -0
- package/dist/reasoningbank/migration/migrate.js.map +1 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.d.ts +37 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.js +114 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.js.map +1 -0
- package/dist/reasoningbank/reasoning/experience-curator.d.ts +39 -0
- package/dist/reasoningbank/reasoning/experience-curator.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/experience-curator.js +98 -0
- package/dist/reasoningbank/reasoning/experience-curator.js.map +1 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.d.ts +44 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.js +184 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.js.map +1 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.d.ts +40 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.js +87 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.js.map +1 -0
- package/dist/reasoningbank/sync/quic-sync.d.ts +77 -0
- package/dist/reasoningbank/sync/quic-sync.d.ts.map +1 -0
- package/dist/reasoningbank/sync/quic-sync.js +165 -0
- package/dist/reasoningbank/sync/quic-sync.js.map +1 -0
- package/dist/sync/conflict.d.ts +78 -0
- package/dist/sync/conflict.d.ts.map +1 -0
- package/dist/sync/conflict.js +202 -0
- package/dist/sync/conflict.js.map +1 -0
- package/dist/sync/conflict.mjs +196 -0
- package/dist/sync/coordinator.d.ts +111 -0
- package/dist/sync/coordinator.d.ts.map +1 -0
- package/dist/sync/coordinator.js +256 -0
- package/dist/sync/coordinator.js.map +1 -0
- package/dist/sync/coordinator.mjs +250 -0
- package/dist/sync/delta.d.ts +81 -0
- package/dist/sync/delta.d.ts.map +1 -0
- package/dist/sync/delta.js +245 -0
- package/dist/sync/delta.js.map +1 -0
- package/dist/sync/delta.mjs +238 -0
- package/dist/sync/index.d.ts +11 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +22 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/index.mjs +9 -0
- package/dist/sync/quic-sync.d.ts +81 -0
- package/dist/sync/quic-sync.d.ts.map +1 -0
- package/dist/sync/quic-sync.js +329 -0
- package/dist/sync/quic-sync.js.map +1 -0
- package/dist/sync/quic-sync.mjs +323 -0
- package/dist/sync/types.d.ts +168 -0
- package/dist/sync/types.d.ts.map +1 -0
- package/dist/sync/types.js +8 -0
- package/dist/sync/types.js.map +1 -0
- package/dist/sync/types.mjs +6 -0
- package/dist/types/index.d.ts +117 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +4 -0
- package/dist/wasm-loader.d.ts +32 -0
- package/dist/wasm-loader.d.ts.map +1 -0
- package/dist/wasm-loader.js +75 -0
- package/dist/wasm-loader.js.map +1 -0
- package/dist/wasm-loader.mjs +64 -0
- package/examples/adaptive-learning.ts +284 -0
- package/examples/browser/README.md +732 -0
- package/examples/browser/adaptive-recommendations/index.html +427 -0
- package/examples/browser/collaborative-filtering/index.html +310 -0
- package/examples/browser/continual-learning/index.html +736 -0
- package/examples/browser/experience-replay/index.html +616 -0
- package/examples/browser/index.html +369 -0
- package/examples/browser/meta-learning/index.html +789 -0
- package/examples/browser/neuro-symbolic/index.html +692 -0
- package/examples/browser/pattern-learning/index.html +620 -0
- package/examples/browser/quantum-inspired/index.html +728 -0
- package/examples/browser/rag/index.html +624 -0
- package/examples/browser/swarm-intelligence/index.html +811 -0
- package/examples/browser-basic.html +170 -0
- package/examples/hnsw-example.ts +148 -0
- package/examples/node-basic.js +70 -0
- package/examples/quic-sync-example.ts +310 -0
- package/examples/quick-start.js +68 -0
- package/examples/wasm-example.ts +222 -0
- package/package.json +118 -0
|
@@ -0,0 +1,784 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* AgentDB MCP Server
|
|
4
|
+
* Production-ready MCP server for Claude Code integration
|
|
5
|
+
* Exposes AgentDB vector database and ReasoningBank operations via MCP protocol
|
|
6
|
+
*/
|
|
7
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
8
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
9
|
+
import { CallToolRequestSchema, ListResourcesRequestSchema, ListToolsRequestSchema, ReadResourceRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
10
|
+
import { SQLiteVectorDB } from './core/vector-db.mjs';
|
|
11
|
+
import { PatternMatcher } from './reasoning/pattern-matcher.mjs';
|
|
12
|
+
import { BackendType } from './core/backend-interface.mjs';
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Type Definitions
|
|
16
|
+
// ============================================================================
|
|
17
|
+
const VectorSchema = z.object({
|
|
18
|
+
id: z.string().optional(),
|
|
19
|
+
embedding: z.array(z.number()),
|
|
20
|
+
metadata: z.record(z.any()).optional(),
|
|
21
|
+
timestamp: z.number().optional(),
|
|
22
|
+
});
|
|
23
|
+
const PatternSchema = z.object({
|
|
24
|
+
embedding: z.array(z.number()),
|
|
25
|
+
taskType: z.string(),
|
|
26
|
+
approach: z.string(),
|
|
27
|
+
successRate: z.number().min(0).max(1),
|
|
28
|
+
avgDuration: z.number().positive(),
|
|
29
|
+
metadata: z.object({
|
|
30
|
+
domain: z.string(),
|
|
31
|
+
complexity: z.enum(['simple', 'medium', 'complex']),
|
|
32
|
+
learningSource: z.enum(['success', 'failure', 'adaptation']),
|
|
33
|
+
tags: z.array(z.string()),
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
36
|
+
// ============================================================================
|
|
37
|
+
// MCP Tool Definitions
|
|
38
|
+
// ============================================================================
|
|
39
|
+
const tools = [
|
|
40
|
+
{
|
|
41
|
+
name: 'agentdb_init',
|
|
42
|
+
description: 'Initialize a new AgentDB vector database with specified configuration. Supports both in-memory and persistent storage with optional quantization and caching.',
|
|
43
|
+
inputSchema: {
|
|
44
|
+
type: 'object',
|
|
45
|
+
properties: {
|
|
46
|
+
path: {
|
|
47
|
+
type: 'string',
|
|
48
|
+
description: 'Database file path (optional, uses in-memory if not provided)',
|
|
49
|
+
},
|
|
50
|
+
memoryMode: {
|
|
51
|
+
type: 'boolean',
|
|
52
|
+
description: 'Use in-memory database (default: true if no path provided)',
|
|
53
|
+
default: true,
|
|
54
|
+
},
|
|
55
|
+
backend: {
|
|
56
|
+
type: 'string',
|
|
57
|
+
enum: ['native', 'wasm'],
|
|
58
|
+
description: 'Backend type: native (Node.js) or wasm (browser/universal)',
|
|
59
|
+
default: 'native',
|
|
60
|
+
},
|
|
61
|
+
enableQueryCache: {
|
|
62
|
+
type: 'boolean',
|
|
63
|
+
description: 'Enable query caching for 50-100x speedup',
|
|
64
|
+
default: true,
|
|
65
|
+
},
|
|
66
|
+
enableQuantization: {
|
|
67
|
+
type: 'boolean',
|
|
68
|
+
description: 'Enable vector quantization for 4-32x compression',
|
|
69
|
+
default: false,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'agentdb_insert',
|
|
76
|
+
description: 'Insert a single vector into AgentDB with optional metadata. Returns the generated vector ID.',
|
|
77
|
+
inputSchema: {
|
|
78
|
+
type: 'object',
|
|
79
|
+
properties: {
|
|
80
|
+
vector: {
|
|
81
|
+
type: 'object',
|
|
82
|
+
properties: {
|
|
83
|
+
id: {
|
|
84
|
+
type: 'string',
|
|
85
|
+
description: 'Optional vector ID (auto-generated if not provided)',
|
|
86
|
+
},
|
|
87
|
+
embedding: {
|
|
88
|
+
type: 'array',
|
|
89
|
+
items: { type: 'number' },
|
|
90
|
+
description: 'Vector embedding values',
|
|
91
|
+
},
|
|
92
|
+
metadata: {
|
|
93
|
+
type: 'object',
|
|
94
|
+
description: 'Optional metadata as key-value pairs',
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
required: ['embedding'],
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
required: ['vector'],
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: 'agentdb_insert_batch',
|
|
105
|
+
description: 'Insert multiple vectors in batch for better performance. Optimized for high-throughput operations.',
|
|
106
|
+
inputSchema: {
|
|
107
|
+
type: 'object',
|
|
108
|
+
properties: {
|
|
109
|
+
vectors: {
|
|
110
|
+
type: 'array',
|
|
111
|
+
items: {
|
|
112
|
+
type: 'object',
|
|
113
|
+
properties: {
|
|
114
|
+
id: { type: 'string' },
|
|
115
|
+
embedding: {
|
|
116
|
+
type: 'array',
|
|
117
|
+
items: { type: 'number' },
|
|
118
|
+
},
|
|
119
|
+
metadata: { type: 'object' },
|
|
120
|
+
},
|
|
121
|
+
required: ['embedding'],
|
|
122
|
+
},
|
|
123
|
+
description: 'Array of vectors to insert',
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
required: ['vectors'],
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: 'agentdb_search',
|
|
131
|
+
description: 'Perform k-nearest neighbor search to find similar vectors. Uses cosine similarity by default with optional query caching.',
|
|
132
|
+
inputSchema: {
|
|
133
|
+
type: 'object',
|
|
134
|
+
properties: {
|
|
135
|
+
queryEmbedding: {
|
|
136
|
+
type: 'array',
|
|
137
|
+
items: { type: 'number' },
|
|
138
|
+
description: 'Query vector embedding',
|
|
139
|
+
},
|
|
140
|
+
k: {
|
|
141
|
+
type: 'number',
|
|
142
|
+
description: 'Number of nearest neighbors to return',
|
|
143
|
+
minimum: 1,
|
|
144
|
+
maximum: 1000,
|
|
145
|
+
default: 5,
|
|
146
|
+
},
|
|
147
|
+
metric: {
|
|
148
|
+
type: 'string',
|
|
149
|
+
enum: ['cosine', 'euclidean', 'dot'],
|
|
150
|
+
description: 'Similarity metric',
|
|
151
|
+
default: 'cosine',
|
|
152
|
+
},
|
|
153
|
+
threshold: {
|
|
154
|
+
type: 'number',
|
|
155
|
+
description: 'Minimum similarity threshold',
|
|
156
|
+
minimum: 0,
|
|
157
|
+
maximum: 1,
|
|
158
|
+
default: 0.0,
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
required: ['queryEmbedding'],
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
name: 'agentdb_delete',
|
|
166
|
+
description: 'Delete a vector by ID from the database.',
|
|
167
|
+
inputSchema: {
|
|
168
|
+
type: 'object',
|
|
169
|
+
properties: {
|
|
170
|
+
id: {
|
|
171
|
+
type: 'string',
|
|
172
|
+
description: 'Vector ID to delete',
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
required: ['id'],
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
name: 'agentdb_stats',
|
|
180
|
+
description: 'Get comprehensive database statistics including vector count, cache stats, and compression metrics.',
|
|
181
|
+
inputSchema: {
|
|
182
|
+
type: 'object',
|
|
183
|
+
properties: {},
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
name: 'agentdb_pattern_store',
|
|
188
|
+
description: 'Store a reasoning pattern in ReasoningBank for future retrieval and learning.',
|
|
189
|
+
inputSchema: {
|
|
190
|
+
type: 'object',
|
|
191
|
+
properties: {
|
|
192
|
+
pattern: {
|
|
193
|
+
type: 'object',
|
|
194
|
+
properties: {
|
|
195
|
+
embedding: {
|
|
196
|
+
type: 'array',
|
|
197
|
+
items: { type: 'number' },
|
|
198
|
+
description: 'Pattern embedding vector',
|
|
199
|
+
},
|
|
200
|
+
taskType: {
|
|
201
|
+
type: 'string',
|
|
202
|
+
description: 'Type of task this pattern applies to',
|
|
203
|
+
},
|
|
204
|
+
approach: {
|
|
205
|
+
type: 'string',
|
|
206
|
+
description: 'Approach or solution strategy',
|
|
207
|
+
},
|
|
208
|
+
successRate: {
|
|
209
|
+
type: 'number',
|
|
210
|
+
description: 'Success rate (0-1)',
|
|
211
|
+
minimum: 0,
|
|
212
|
+
maximum: 1,
|
|
213
|
+
},
|
|
214
|
+
avgDuration: {
|
|
215
|
+
type: 'number',
|
|
216
|
+
description: 'Average execution duration in milliseconds',
|
|
217
|
+
minimum: 0,
|
|
218
|
+
},
|
|
219
|
+
metadata: {
|
|
220
|
+
type: 'object',
|
|
221
|
+
properties: {
|
|
222
|
+
domain: { type: 'string' },
|
|
223
|
+
complexity: {
|
|
224
|
+
type: 'string',
|
|
225
|
+
enum: ['simple', 'medium', 'complex'],
|
|
226
|
+
},
|
|
227
|
+
learningSource: {
|
|
228
|
+
type: 'string',
|
|
229
|
+
enum: ['success', 'failure', 'adaptation'],
|
|
230
|
+
},
|
|
231
|
+
tags: {
|
|
232
|
+
type: 'array',
|
|
233
|
+
items: { type: 'string' },
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
required: ['domain', 'complexity', 'learningSource', 'tags'],
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
required: ['embedding', 'taskType', 'approach', 'successRate', 'avgDuration', 'metadata'],
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
required: ['pattern'],
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
name: 'agentdb_pattern_search',
|
|
247
|
+
description: 'Search for similar reasoning patterns in ReasoningBank based on task embedding.',
|
|
248
|
+
inputSchema: {
|
|
249
|
+
type: 'object',
|
|
250
|
+
properties: {
|
|
251
|
+
taskEmbedding: {
|
|
252
|
+
type: 'array',
|
|
253
|
+
items: { type: 'number' },
|
|
254
|
+
description: 'Task embedding to find similar patterns for',
|
|
255
|
+
},
|
|
256
|
+
k: {
|
|
257
|
+
type: 'number',
|
|
258
|
+
description: 'Number of similar patterns to return',
|
|
259
|
+
minimum: 1,
|
|
260
|
+
maximum: 50,
|
|
261
|
+
default: 5,
|
|
262
|
+
},
|
|
263
|
+
threshold: {
|
|
264
|
+
type: 'number',
|
|
265
|
+
description: 'Minimum similarity threshold',
|
|
266
|
+
minimum: 0,
|
|
267
|
+
maximum: 1,
|
|
268
|
+
default: 0.7,
|
|
269
|
+
},
|
|
270
|
+
filters: {
|
|
271
|
+
type: 'object',
|
|
272
|
+
properties: {
|
|
273
|
+
domain: { type: 'string' },
|
|
274
|
+
taskType: { type: 'string' },
|
|
275
|
+
minSuccessRate: { type: 'number' },
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
required: ['taskEmbedding'],
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
name: 'agentdb_pattern_stats',
|
|
284
|
+
description: 'Get statistics about stored reasoning patterns in ReasoningBank.',
|
|
285
|
+
inputSchema: {
|
|
286
|
+
type: 'object',
|
|
287
|
+
properties: {},
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
name: 'agentdb_clear_cache',
|
|
292
|
+
description: 'Clear the query cache to free memory or force fresh queries.',
|
|
293
|
+
inputSchema: {
|
|
294
|
+
type: 'object',
|
|
295
|
+
properties: {},
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
];
|
|
299
|
+
// ============================================================================
|
|
300
|
+
// Database Registry
|
|
301
|
+
// ============================================================================
|
|
302
|
+
class AgentDBRegistry {
|
|
303
|
+
constructor() {
|
|
304
|
+
this.db = null;
|
|
305
|
+
this.patternMatcher = null;
|
|
306
|
+
this.config = null;
|
|
307
|
+
}
|
|
308
|
+
async getOrCreate(config = {}) {
|
|
309
|
+
if (!this.db) {
|
|
310
|
+
// Set default config
|
|
311
|
+
const dbConfig = {
|
|
312
|
+
path: config.path,
|
|
313
|
+
memoryMode: config.memoryMode ?? (!config.path),
|
|
314
|
+
backend: config.backend === 'wasm' ? BackendType.WASM : BackendType.NATIVE,
|
|
315
|
+
queryCache: {
|
|
316
|
+
enabled: config.enableQueryCache ?? true,
|
|
317
|
+
},
|
|
318
|
+
quantization: config.enableQuantization ? {
|
|
319
|
+
enabled: true,
|
|
320
|
+
dimensions: 768, // Default, will be updated
|
|
321
|
+
subvectors: 8,
|
|
322
|
+
bits: 8,
|
|
323
|
+
} : undefined,
|
|
324
|
+
};
|
|
325
|
+
this.db = new SQLiteVectorDB(dbConfig);
|
|
326
|
+
this.config = dbConfig;
|
|
327
|
+
// Initialize async if WASM backend
|
|
328
|
+
if (dbConfig.backend === BackendType.WASM) {
|
|
329
|
+
await this.db.initializeAsync();
|
|
330
|
+
}
|
|
331
|
+
// Initialize PatternMatcher for ReasoningBank
|
|
332
|
+
if (dbConfig.backend === BackendType.NATIVE) {
|
|
333
|
+
this.patternMatcher = new PatternMatcher(this.db);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return this.db;
|
|
337
|
+
}
|
|
338
|
+
get() {
|
|
339
|
+
return this.db;
|
|
340
|
+
}
|
|
341
|
+
getPatternMatcher() {
|
|
342
|
+
return this.patternMatcher;
|
|
343
|
+
}
|
|
344
|
+
close() {
|
|
345
|
+
if (this.db) {
|
|
346
|
+
this.db.close();
|
|
347
|
+
this.db = null;
|
|
348
|
+
this.patternMatcher = null;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
// ============================================================================
|
|
353
|
+
// Resource Handler
|
|
354
|
+
// ============================================================================
|
|
355
|
+
class ResourceHandler {
|
|
356
|
+
constructor(registry) {
|
|
357
|
+
this.registry = registry;
|
|
358
|
+
}
|
|
359
|
+
async listResources() {
|
|
360
|
+
return {
|
|
361
|
+
resources: [
|
|
362
|
+
{
|
|
363
|
+
uri: 'agentdb://stats',
|
|
364
|
+
name: 'Database Statistics',
|
|
365
|
+
description: 'Current AgentDB statistics and metrics',
|
|
366
|
+
mimeType: 'application/json',
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
uri: 'agentdb://cache-stats',
|
|
370
|
+
name: 'Query Cache Statistics',
|
|
371
|
+
description: 'Query cache hit rates and performance metrics',
|
|
372
|
+
mimeType: 'application/json',
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
uri: 'agentdb://pattern-stats',
|
|
376
|
+
name: 'ReasoningBank Pattern Statistics',
|
|
377
|
+
description: 'Statistics about stored reasoning patterns',
|
|
378
|
+
mimeType: 'application/json',
|
|
379
|
+
},
|
|
380
|
+
],
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
async readResource(uri) {
|
|
384
|
+
const db = this.registry.get();
|
|
385
|
+
if (!db) {
|
|
386
|
+
throw new Error('Database not initialized. Call agentdb_init first.');
|
|
387
|
+
}
|
|
388
|
+
switch (uri) {
|
|
389
|
+
case 'agentdb://stats': {
|
|
390
|
+
const stats = db.stats();
|
|
391
|
+
return {
|
|
392
|
+
contents: [
|
|
393
|
+
{
|
|
394
|
+
uri,
|
|
395
|
+
mimeType: 'application/json',
|
|
396
|
+
text: JSON.stringify(stats, null, 2),
|
|
397
|
+
},
|
|
398
|
+
],
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
case 'agentdb://cache-stats': {
|
|
402
|
+
const cacheStats = db.getCacheStats();
|
|
403
|
+
return {
|
|
404
|
+
contents: [
|
|
405
|
+
{
|
|
406
|
+
uri,
|
|
407
|
+
mimeType: 'application/json',
|
|
408
|
+
text: JSON.stringify(cacheStats || { message: 'Cache not enabled' }, null, 2),
|
|
409
|
+
},
|
|
410
|
+
],
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
case 'agentdb://pattern-stats': {
|
|
414
|
+
const patternMatcher = this.registry.getPatternMatcher();
|
|
415
|
+
if (!patternMatcher) {
|
|
416
|
+
throw new Error('PatternMatcher not available (WASM backend or not initialized)');
|
|
417
|
+
}
|
|
418
|
+
const patternStats = patternMatcher.getStats();
|
|
419
|
+
return {
|
|
420
|
+
contents: [
|
|
421
|
+
{
|
|
422
|
+
uri,
|
|
423
|
+
mimeType: 'application/json',
|
|
424
|
+
text: JSON.stringify({
|
|
425
|
+
totalPatterns: patternStats.totalPatterns,
|
|
426
|
+
avgSuccessRate: patternStats.avgSuccessRate,
|
|
427
|
+
domainDistribution: Object.fromEntries(patternStats.domainDistribution),
|
|
428
|
+
topPatterns: patternStats.topPatterns,
|
|
429
|
+
}, null, 2),
|
|
430
|
+
},
|
|
431
|
+
],
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
default:
|
|
435
|
+
throw new Error(`Unknown resource: ${uri}`);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
// ============================================================================
|
|
440
|
+
// Main MCP Server
|
|
441
|
+
// ============================================================================
|
|
442
|
+
export class AgentDBMCPServer {
|
|
443
|
+
constructor() {
|
|
444
|
+
this.registry = new AgentDBRegistry();
|
|
445
|
+
this.resourceHandler = new ResourceHandler(this.registry);
|
|
446
|
+
this.server = new Server({
|
|
447
|
+
name: 'agentdb-mcp',
|
|
448
|
+
version: '1.0.0',
|
|
449
|
+
}, {
|
|
450
|
+
capabilities: {
|
|
451
|
+
tools: {},
|
|
452
|
+
resources: {},
|
|
453
|
+
},
|
|
454
|
+
});
|
|
455
|
+
this.setupHandlers();
|
|
456
|
+
this.setupErrorHandlers();
|
|
457
|
+
}
|
|
458
|
+
setupHandlers() {
|
|
459
|
+
// List available tools
|
|
460
|
+
this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
461
|
+
tools,
|
|
462
|
+
}));
|
|
463
|
+
// List available resources
|
|
464
|
+
this.server.setRequestHandler(ListResourcesRequestSchema, async () => this.resourceHandler.listResources());
|
|
465
|
+
// Read resource
|
|
466
|
+
this.server.setRequestHandler(ReadResourceRequestSchema, async (request) => this.resourceHandler.readResource(request.params.uri));
|
|
467
|
+
// Handle tool calls
|
|
468
|
+
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
469
|
+
const { name, arguments: args } = request.params;
|
|
470
|
+
try {
|
|
471
|
+
switch (name) {
|
|
472
|
+
case 'agentdb_init':
|
|
473
|
+
return await this.handleInit(args);
|
|
474
|
+
case 'agentdb_insert':
|
|
475
|
+
return await this.handleInsert(args);
|
|
476
|
+
case 'agentdb_insert_batch':
|
|
477
|
+
return await this.handleInsertBatch(args);
|
|
478
|
+
case 'agentdb_search':
|
|
479
|
+
return await this.handleSearch(args);
|
|
480
|
+
case 'agentdb_delete':
|
|
481
|
+
return await this.handleDelete(args);
|
|
482
|
+
case 'agentdb_stats':
|
|
483
|
+
return await this.handleStats(args);
|
|
484
|
+
case 'agentdb_pattern_store':
|
|
485
|
+
return await this.handlePatternStore(args);
|
|
486
|
+
case 'agentdb_pattern_search':
|
|
487
|
+
return await this.handlePatternSearch(args);
|
|
488
|
+
case 'agentdb_pattern_stats':
|
|
489
|
+
return await this.handlePatternStats(args);
|
|
490
|
+
case 'agentdb_clear_cache':
|
|
491
|
+
return await this.handleClearCache(args);
|
|
492
|
+
default:
|
|
493
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
catch (error) {
|
|
497
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
498
|
+
return {
|
|
499
|
+
content: [
|
|
500
|
+
{
|
|
501
|
+
type: 'text',
|
|
502
|
+
text: JSON.stringify({
|
|
503
|
+
error: errorMessage,
|
|
504
|
+
tool: name,
|
|
505
|
+
timestamp: Date.now(),
|
|
506
|
+
}, null, 2),
|
|
507
|
+
},
|
|
508
|
+
],
|
|
509
|
+
isError: true,
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
setupErrorHandlers() {
|
|
515
|
+
this.server.onerror = (error) => {
|
|
516
|
+
console.error('[AgentDB MCP Error]', error);
|
|
517
|
+
};
|
|
518
|
+
process.on('SIGINT', async () => {
|
|
519
|
+
await this.cleanup();
|
|
520
|
+
process.exit(0);
|
|
521
|
+
});
|
|
522
|
+
process.on('SIGTERM', async () => {
|
|
523
|
+
await this.cleanup();
|
|
524
|
+
process.exit(0);
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
// ============================================================================
|
|
528
|
+
// Tool Handlers
|
|
529
|
+
// ============================================================================
|
|
530
|
+
async handleInit(args) {
|
|
531
|
+
const db = await this.registry.getOrCreate(args);
|
|
532
|
+
return {
|
|
533
|
+
content: [
|
|
534
|
+
{
|
|
535
|
+
type: 'text',
|
|
536
|
+
text: JSON.stringify({
|
|
537
|
+
success: true,
|
|
538
|
+
message: 'AgentDB initialized successfully',
|
|
539
|
+
backend: db.getBackendType(),
|
|
540
|
+
config: {
|
|
541
|
+
path: args.path || 'in-memory',
|
|
542
|
+
memoryMode: args.memoryMode ?? true,
|
|
543
|
+
queryCache: args.enableQueryCache ?? true,
|
|
544
|
+
quantization: args.enableQuantization ?? false,
|
|
545
|
+
},
|
|
546
|
+
}, null, 2),
|
|
547
|
+
},
|
|
548
|
+
],
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
async handleInsert(args) {
|
|
552
|
+
const db = this.registry.get();
|
|
553
|
+
if (!db) {
|
|
554
|
+
throw new Error('Database not initialized. Call agentdb_init first.');
|
|
555
|
+
}
|
|
556
|
+
const vector = VectorSchema.parse(args.vector);
|
|
557
|
+
const id = db.insert(vector);
|
|
558
|
+
return {
|
|
559
|
+
content: [
|
|
560
|
+
{
|
|
561
|
+
type: 'text',
|
|
562
|
+
text: JSON.stringify({
|
|
563
|
+
success: true,
|
|
564
|
+
id,
|
|
565
|
+
message: 'Vector inserted successfully',
|
|
566
|
+
}, null, 2),
|
|
567
|
+
},
|
|
568
|
+
],
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
async handleInsertBatch(args) {
|
|
572
|
+
const db = this.registry.get();
|
|
573
|
+
if (!db) {
|
|
574
|
+
throw new Error('Database not initialized. Call agentdb_init first.');
|
|
575
|
+
}
|
|
576
|
+
const vectors = z.array(VectorSchema).parse(args.vectors);
|
|
577
|
+
const ids = db.insertBatch(vectors);
|
|
578
|
+
return {
|
|
579
|
+
content: [
|
|
580
|
+
{
|
|
581
|
+
type: 'text',
|
|
582
|
+
text: JSON.stringify({
|
|
583
|
+
success: true,
|
|
584
|
+
inserted: ids.length,
|
|
585
|
+
ids,
|
|
586
|
+
message: `${ids.length} vectors inserted successfully`,
|
|
587
|
+
}, null, 2),
|
|
588
|
+
},
|
|
589
|
+
],
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
async handleSearch(args) {
|
|
593
|
+
const db = this.registry.get();
|
|
594
|
+
if (!db) {
|
|
595
|
+
throw new Error('Database not initialized. Call agentdb_init first.');
|
|
596
|
+
}
|
|
597
|
+
const { queryEmbedding, k = 5, metric = 'cosine', threshold = 0.0 } = args;
|
|
598
|
+
const results = db.search(queryEmbedding, k, metric, threshold);
|
|
599
|
+
return {
|
|
600
|
+
content: [
|
|
601
|
+
{
|
|
602
|
+
type: 'text',
|
|
603
|
+
text: JSON.stringify({
|
|
604
|
+
success: true,
|
|
605
|
+
results,
|
|
606
|
+
count: results.length,
|
|
607
|
+
message: `Found ${results.length} similar vectors`,
|
|
608
|
+
}, null, 2),
|
|
609
|
+
},
|
|
610
|
+
],
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
async handleDelete(args) {
|
|
614
|
+
const db = this.registry.get();
|
|
615
|
+
if (!db) {
|
|
616
|
+
throw new Error('Database not initialized. Call agentdb_init first.');
|
|
617
|
+
}
|
|
618
|
+
const success = db.delete(args.id);
|
|
619
|
+
return {
|
|
620
|
+
content: [
|
|
621
|
+
{
|
|
622
|
+
type: 'text',
|
|
623
|
+
text: JSON.stringify({
|
|
624
|
+
success,
|
|
625
|
+
id: args.id,
|
|
626
|
+
message: success ? 'Vector deleted successfully' : 'Vector not found',
|
|
627
|
+
}, null, 2),
|
|
628
|
+
},
|
|
629
|
+
],
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
async handleStats(args) {
|
|
633
|
+
const db = this.registry.get();
|
|
634
|
+
if (!db) {
|
|
635
|
+
throw new Error('Database not initialized. Call agentdb_init first.');
|
|
636
|
+
}
|
|
637
|
+
const stats = db.stats();
|
|
638
|
+
const cacheStats = db.getCacheStats();
|
|
639
|
+
const compressionStats = db.getCompressionStats();
|
|
640
|
+
return {
|
|
641
|
+
content: [
|
|
642
|
+
{
|
|
643
|
+
type: 'text',
|
|
644
|
+
text: JSON.stringify({
|
|
645
|
+
success: true,
|
|
646
|
+
stats: {
|
|
647
|
+
vectors: stats,
|
|
648
|
+
cache: cacheStats || { enabled: false },
|
|
649
|
+
compression: compressionStats || { enabled: false },
|
|
650
|
+
},
|
|
651
|
+
message: 'Statistics retrieved successfully',
|
|
652
|
+
}, null, 2),
|
|
653
|
+
},
|
|
654
|
+
],
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
async handlePatternStore(args) {
|
|
658
|
+
const patternMatcher = this.registry.getPatternMatcher();
|
|
659
|
+
if (!patternMatcher) {
|
|
660
|
+
throw new Error('PatternMatcher not available (WASM backend or not initialized)');
|
|
661
|
+
}
|
|
662
|
+
const pattern = PatternSchema.parse(args.pattern);
|
|
663
|
+
// Add default iterations field required by PatternMetadata
|
|
664
|
+
const patternWithIterations = {
|
|
665
|
+
...pattern,
|
|
666
|
+
metadata: {
|
|
667
|
+
...pattern.metadata,
|
|
668
|
+
iterations: 1, // Initial iteration count
|
|
669
|
+
},
|
|
670
|
+
};
|
|
671
|
+
const id = await patternMatcher.storePattern(patternWithIterations);
|
|
672
|
+
return {
|
|
673
|
+
content: [
|
|
674
|
+
{
|
|
675
|
+
type: 'text',
|
|
676
|
+
text: JSON.stringify({
|
|
677
|
+
success: true,
|
|
678
|
+
id,
|
|
679
|
+
message: 'Reasoning pattern stored successfully',
|
|
680
|
+
}, null, 2),
|
|
681
|
+
},
|
|
682
|
+
],
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
async handlePatternSearch(args) {
|
|
686
|
+
const patternMatcher = this.registry.getPatternMatcher();
|
|
687
|
+
if (!patternMatcher) {
|
|
688
|
+
throw new Error('PatternMatcher not available (WASM backend or not initialized)');
|
|
689
|
+
}
|
|
690
|
+
const { taskEmbedding, k = 5, threshold = 0.7, filters } = args;
|
|
691
|
+
const patterns = await patternMatcher.findSimilar(taskEmbedding, k, threshold, filters);
|
|
692
|
+
return {
|
|
693
|
+
content: [
|
|
694
|
+
{
|
|
695
|
+
type: 'text',
|
|
696
|
+
text: JSON.stringify({
|
|
697
|
+
success: true,
|
|
698
|
+
patterns: patterns.map((p) => ({
|
|
699
|
+
id: p.id,
|
|
700
|
+
taskType: p.taskType,
|
|
701
|
+
approach: p.approach,
|
|
702
|
+
successRate: p.successRate,
|
|
703
|
+
avgDuration: p.avgDuration,
|
|
704
|
+
similarity: p.similarity,
|
|
705
|
+
metadata: p.metadata,
|
|
706
|
+
})),
|
|
707
|
+
count: patterns.length,
|
|
708
|
+
message: `Found ${patterns.length} similar patterns`,
|
|
709
|
+
}, null, 2),
|
|
710
|
+
},
|
|
711
|
+
],
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
async handlePatternStats(args) {
|
|
715
|
+
const patternMatcher = this.registry.getPatternMatcher();
|
|
716
|
+
if (!patternMatcher) {
|
|
717
|
+
throw new Error('PatternMatcher not available (WASM backend or not initialized)');
|
|
718
|
+
}
|
|
719
|
+
const stats = patternMatcher.getStats();
|
|
720
|
+
return {
|
|
721
|
+
content: [
|
|
722
|
+
{
|
|
723
|
+
type: 'text',
|
|
724
|
+
text: JSON.stringify({
|
|
725
|
+
success: true,
|
|
726
|
+
stats: {
|
|
727
|
+
totalPatterns: stats.totalPatterns,
|
|
728
|
+
avgSuccessRate: stats.avgSuccessRate,
|
|
729
|
+
domainDistribution: Object.fromEntries(stats.domainDistribution),
|
|
730
|
+
topPatterns: stats.topPatterns,
|
|
731
|
+
},
|
|
732
|
+
message: 'Pattern statistics retrieved successfully',
|
|
733
|
+
}, null, 2),
|
|
734
|
+
},
|
|
735
|
+
],
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
async handleClearCache(args) {
|
|
739
|
+
const db = this.registry.get();
|
|
740
|
+
if (!db) {
|
|
741
|
+
throw new Error('Database not initialized. Call agentdb_init first.');
|
|
742
|
+
}
|
|
743
|
+
db.clearCache();
|
|
744
|
+
return {
|
|
745
|
+
content: [
|
|
746
|
+
{
|
|
747
|
+
type: 'text',
|
|
748
|
+
text: JSON.stringify({
|
|
749
|
+
success: true,
|
|
750
|
+
message: 'Query cache cleared successfully',
|
|
751
|
+
}, null, 2),
|
|
752
|
+
},
|
|
753
|
+
],
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
async start() {
|
|
757
|
+
const transport = new StdioServerTransport();
|
|
758
|
+
await this.server.connect(transport);
|
|
759
|
+
console.error('AgentDB MCP Server started');
|
|
760
|
+
}
|
|
761
|
+
async cleanup() {
|
|
762
|
+
console.error('Shutting down AgentDB MCP Server...');
|
|
763
|
+
this.registry.close();
|
|
764
|
+
await this.server.close();
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
// ============================================================================
|
|
768
|
+
// Entry Point
|
|
769
|
+
// ============================================================================
|
|
770
|
+
async function main() {
|
|
771
|
+
const server = new AgentDBMCPServer();
|
|
772
|
+
try {
|
|
773
|
+
await server.start();
|
|
774
|
+
}
|
|
775
|
+
catch (error) {
|
|
776
|
+
console.error('Failed to start AgentDB MCP Server:', error);
|
|
777
|
+
process.exit(1);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
// Only run if this is the main module
|
|
781
|
+
// Note: This check works in ESM modules. For CommonJS, check require.main === module
|
|
782
|
+
if (typeof require !== 'undefined' && require.main === module) {
|
|
783
|
+
main();
|
|
784
|
+
}
|