collective-memory-mcp 0.3.2 → 0.4.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/server.js +296 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "collective-memory-mcp",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "A persistent, graph-based memory system for AI agents (MCP Server)",
5
5
  "type": "module",
6
6
  "main": "src/server.js",
package/src/server.js CHANGED
@@ -9,6 +9,8 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
9
9
  import {
10
10
  CallToolRequestSchema,
11
11
  ListToolsRequestSchema,
12
+ ListPromptsRequestSchema,
13
+ GetPromptRequestSchema,
12
14
  } from "@modelcontextprotocol/sdk/types.js";
13
15
  import { getStorage } from "./storage.js";
14
16
  import { Entity, Relation, ENTITY_TYPES, RELATION_TYPES } from "./models.js";
@@ -27,6 +29,7 @@ function createServer() {
27
29
  {
28
30
  capabilities: {
29
31
  tools: {},
32
+ prompts: {},
30
33
  },
31
34
  }
32
35
  );
@@ -349,6 +352,299 @@ function createServer() {
349
352
  };
350
353
  });
351
354
 
355
+ // ========== Prompts ==========
356
+
357
+ /**
358
+ * Available prompts that guide agents on using the collective memory system
359
+ */
360
+ const PROMPTS = [
361
+ {
362
+ name: "task-documentation-guide",
363
+ description: "Guide for documenting completed tasks in the collective memory",
364
+ arguments: [],
365
+ },
366
+ {
367
+ name: "search-workflow-guide",
368
+ description: "Guide for searching and learning from past work",
369
+ arguments: [],
370
+ },
371
+ {
372
+ name: "getting-started",
373
+ description: "Introduction to the Collective Memory System for agents",
374
+ arguments: [],
375
+ },
376
+ {
377
+ name: "observation-best-practices",
378
+ description: "Best practices for writing effective observations",
379
+ arguments: [],
380
+ },
381
+ ];
382
+
383
+ /**
384
+ * List available prompts
385
+ */
386
+ server.setRequestHandler(ListPromptsRequestSchema, async () => {
387
+ return { prompts: PROMPTS };
388
+ });
389
+
390
+ /**
391
+ * Get a specific prompt
392
+ */
393
+ server.setRequestHandler(GetPromptRequestSchema, async (request) => {
394
+ const { name, arguments: args } = request.params;
395
+
396
+ const prompts = {
397
+ "task-documentation-guide": {
398
+ messages: [
399
+ {
400
+ role: "user",
401
+ content: {
402
+ type: "text",
403
+ text: `# Collective Memory: Task Documentation Guide
404
+
405
+ When you complete a task, document it using the \`record_task_completion\` tool.
406
+
407
+ ## Required Parameters:
408
+ - \`agent_name\`: Your identifier (e.g., "Agent_Backend_Developer")
409
+ - \`task_name\`: Unique, descriptive name (e.g., "Task_Add_JWT_Auth_20241224")
410
+
411
+ ## Optional but Recommended:
412
+ - \`task_type\`: Type of work (implementation, debugging, refactoring, testing, etc.)
413
+ - \`description\`: High-level summary of what was accomplished
414
+ - \`observations\`: Array of specific, atomic facts about the work
415
+ - \`created_artifacts\`: Files, code, configs created
416
+ - \`modified_structures\`: Architectural patterns or structures changed
417
+ - \`session_id\`: Session identifier to group related tasks
418
+
419
+ ## Writing Good Observations:
420
+
421
+ ✅ **Good observations** (specific, actionable):
422
+ - "API uses JWT tokens with 1-hour expiry"
423
+ - "Database schema includes composite index on (user_id, created_at)"
424
+ - "Deployment succeeded after adding 2GB RAM to container"
425
+ - "Error handling uses custom exception hierarchy from exceptions.py"
426
+
427
+ ❌ **Poor observations** (vague, subjective):
428
+ - "API works well"
429
+ - "Database is fast"
430
+ - "Fixed some bugs"
431
+ - "Good code structure"
432
+
433
+ ## Example:
434
+
435
+ \`\`\`json
436
+ {
437
+ "agent_name": "Agent_Backend_Developer",
438
+ "task_name": "Task_Implement_Pagination_20241224",
439
+ "task_type": "implementation",
440
+ "description": "Added cursor-based pagination to all list endpoints",
441
+ "observations": [
442
+ "Used keyset pagination pattern for better performance",
443
+ "Cursor encodes last_seen_id and last_seen_timestamp",
444
+ "Default page size: 50 items, max: 200",
445
+ "Backward compatibility maintained with offset-based fallback"
446
+ ],
447
+ "created_artifacts": [
448
+ {
449
+ "name": "Artifact_Pagination_Middleware",
450
+ "observations": ["Located at /src/middleware/pagination.js", "Handles cursor encoding/decoding"]
451
+ }
452
+ ]
453
+ }
454
+ \`\`\``,
455
+ },
456
+ },
457
+ ],
458
+ },
459
+
460
+ "search-workflow-guide": {
461
+ messages: [
462
+ {
463
+ role: "user",
464
+ content: {
465
+ type: "text",
466
+ text: `# Collective Memory: Search Workflow Guide
467
+
468
+ Before starting a task, search the collective memory to learn from past work.
469
+
470
+ ## When to Search:
471
+ 1. **Before implementing** a feature - check if similar work was done
472
+ 2. **When debugging** - find how similar issues were resolved
473
+ 3. **When refactoring** - understand existing architectural patterns
474
+ 4. **When choosing libraries** - see what's been used successfully
475
+
476
+ ## Search Tools:
477
+
478
+ ### \`search_collective_memory\`
479
+ Natural language search across all entities and observations.
480
+ \`\`\`json
481
+ { "query": "authentication implementation" }
482
+ \`\`\`
483
+
484
+ ### \`find_similar_procedures\`
485
+ Returns complete implementation details including artifacts and structures.
486
+ \`\`\`json
487
+ { "query": "database migration" }
488
+ \`\`\`
489
+
490
+ ### \`open_nodes\`
491
+ Retrieve specific entities by exact name.
492
+ \`\`\`json
493
+ { "names": ["Task_JWT_Auth", "Artifact_Auth_Middleware"] }
494
+ \`\`\`
495
+
496
+ ### \`read_graph\`
497
+ Export the entire knowledge graph for analysis.
498
+
499
+ ## Search Strategy:
500
+ 1. Start with broad natural language queries
501
+ 2. Use \`find_similar_procedures\` to get full context
502
+ 3. Examine related entities (artifacts, structures)
503
+ 4. Look for patterns in observations (errors, solutions, decisions)
504
+
505
+ ## Example Workflow:
506
+ \`\`\`
507
+ 1. search_collective_memory: "user authentication"
508
+ 2. find_similar_procedures: "JWT implementation"
509
+ 3. Review returned artifacts and structures
510
+ 4. Adapt patterns to current task
511
+ 5. Document new task with record_task_completion
512
+ \`\`\``,
513
+ },
514
+ },
515
+ ],
516
+ },
517
+
518
+ "getting-started": {
519
+ messages: [
520
+ {
521
+ role: "user",
522
+ content: {
523
+ type: "text",
524
+ text: `# Collective Memory System - Quick Start
525
+
526
+ You are connected to the Collective Memory System, a persistent knowledge graph that helps AI agents learn from each other's work.
527
+
528
+ ## Key Concepts:
529
+
530
+ **Entities** are nodes in the knowledge graph:
531
+ - **agent**: An AI agent (you or other agents)
532
+ - **task**: A unit of completed work
533
+ - **artifact**: Concrete output (file, code, config)
534
+ - **structure**: Architectural pattern or decision
535
+ - **session**: Groups related tasks
536
+
537
+ **Relations** connect entities:
538
+ - executed_by, created, modified, documented, depends_on, part_of, similar_to, uses, implements
539
+
540
+ ## Your Workflow:
541
+
542
+ 1. **Before starting** → Search for similar past work
543
+ - Use \`search_collective_memory\` or \`find_similar_procedures\`
544
+
545
+ 2. **While working** → Learn from patterns
546
+ - Review how similar tasks were solved
547
+ - Examine artifacts and structures
548
+
549
+ 3. **After completing** → Document your work
550
+ - Use \`record_task_completion\` with specific observations
551
+
552
+ ## Available Tools:
553
+ - \`record_task_completion\` - Document completed work (PRIMARY)
554
+ - \`search_collective_memory\` - Natural language search
555
+ - \`find_similar_procedures\` - Find similar tasks with full context
556
+ - \`read_graph\` - Export entire knowledge graph
557
+ - \`create_entities\` - Create new entities
558
+ - \`create_relations\` - Connect entities
559
+ - \`open_nodes\` - Retrieve specific entities
560
+
561
+ ## Best Practices:
562
+ - Write specific, atomic observations
563
+ - Include file paths, versions, metrics
564
+ - Document both successes and failures
565
+ - Link related artifacts and structures
566
+
567
+ The system persists all data in ~/.collective-memory/memory.json`,
568
+ },
569
+ },
570
+ ],
571
+ },
572
+
573
+ "observation-best-practices": {
574
+ messages: [
575
+ {
576
+ role: "user",
577
+ content: {
578
+ type: "text",
579
+ text: `# Collective Memory: Observation Best Practices
580
+
581
+ Observations are the heart of the collective memory. Write them well to help future agents.
582
+
583
+ ## Characteristics of Good Observations:
584
+
585
+ 1. **Atomic** - One fact per observation
586
+ 2. **Specific** - Include concrete details (versions, paths, metrics)
587
+ 3. **Actionable** - Provide enough context to replicate or understand
588
+ 4. **Time-bound** - Include timestamps or relative time when relevant
589
+
590
+ ## Examples by Category:
591
+
592
+ ### Code Changes:
593
+ ✅ "Added JWT validation middleware at /src/auth/jwt.js"
594
+ ✅ "Refactored user service to use dependency injection pattern"
595
+ ❌ "Improved code quality"
596
+
597
+ ### Configuration:
598
+ ✅ "Set JWT expiry to 3600 seconds (1 hour)"
599
+ ✅ "Enabled CORS for https://example.com in production config"
600
+ ❌ "Configured settings"
601
+
602
+ ### Errors & Fixes:
603
+ ✅ "Fixed CORS error by adding Origin header to allowed list"
604
+ ✅ "Resolved memory leak by properly closing database connections"
605
+ ❌ "Fixed bugs"
606
+
607
+ ### Performance:
608
+ ✅ "Reduced API response time from 500ms to 120ms by adding Redis cache"
609
+ ✅ "Optimized database query by adding composite index on (user_id, created_at)"
610
+ ❌ "Made it faster"
611
+
612
+ ### Decisions:
613
+ ✅ "Chose PostgreSQL over MySQL for JSONB support"
614
+ ✅ "Used WebSockets instead of polling for real-time updates"
615
+ ❌ "Good technical choices"
616
+
617
+ ### Dependencies:
618
+ ✅ "Upgraded lodash from 4.17.15 to 4.17.21 for security fix"
619
+ ✅ "Added bcrypt@5.1.1 for password hashing (cost factor: 12)"
620
+ ❌ "Updated packages"
621
+
622
+ ## Template for Complex Tasks:
623
+
624
+ For each significant task, include observations about:
625
+ 1. **What was changed** - Specific files, functions, configs
626
+ 2. **Why it was done** - Reasoning behind decisions
627
+ 3. **How it works** - Key implementation details
628
+ 4. **Edge cases handled** - Special conditions addressed
629
+ 5. **Testing done** - How it was verified
630
+ 6. **Known limitations** - Any remaining issues
631
+
632
+ ## Remember:
633
+ Future agents will read your observations to learn. Write for them, not for yourself.`,
634
+ },
635
+ },
636
+ ],
637
+ },
638
+ };
639
+
640
+ const prompt = prompts[name];
641
+ if (!prompt) {
642
+ throw new Error(`Unknown prompt: ${name}`);
643
+ }
644
+
645
+ return prompt;
646
+ });
647
+
352
648
  /**
353
649
  * Handle tool calls
354
650
  */