claude-mpm 4.4.0__py3-none-any.whl → 4.4.3__py3-none-any.whl

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 (50) hide show
  1. claude_mpm/VERSION +1 -1
  2. claude_mpm/agents/WORKFLOW.md +2 -14
  3. claude_mpm/cli/commands/configure.py +2 -29
  4. claude_mpm/cli/commands/mpm_init.py +3 -3
  5. claude_mpm/cli/parsers/configure_parser.py +4 -15
  6. claude_mpm/core/framework/__init__.py +38 -0
  7. claude_mpm/core/framework/formatters/__init__.py +11 -0
  8. claude_mpm/core/framework/formatters/capability_generator.py +356 -0
  9. claude_mpm/core/framework/formatters/content_formatter.py +283 -0
  10. claude_mpm/core/framework/formatters/context_generator.py +180 -0
  11. claude_mpm/core/framework/loaders/__init__.py +13 -0
  12. claude_mpm/core/framework/loaders/agent_loader.py +202 -0
  13. claude_mpm/core/framework/loaders/file_loader.py +213 -0
  14. claude_mpm/core/framework/loaders/instruction_loader.py +151 -0
  15. claude_mpm/core/framework/loaders/packaged_loader.py +208 -0
  16. claude_mpm/core/framework/processors/__init__.py +11 -0
  17. claude_mpm/core/framework/processors/memory_processor.py +222 -0
  18. claude_mpm/core/framework/processors/metadata_processor.py +146 -0
  19. claude_mpm/core/framework/processors/template_processor.py +238 -0
  20. claude_mpm/core/framework_loader.py +277 -1798
  21. claude_mpm/hooks/__init__.py +9 -1
  22. claude_mpm/hooks/kuzu_memory_hook.py +352 -0
  23. claude_mpm/services/core/path_resolver.py +1 -0
  24. claude_mpm/services/diagnostics/diagnostic_runner.py +1 -0
  25. claude_mpm/services/mcp_config_manager.py +67 -4
  26. claude_mpm/services/mcp_gateway/core/process_pool.py +281 -0
  27. claude_mpm/services/mcp_gateway/core/startup_verification.py +2 -2
  28. claude_mpm/services/mcp_gateway/main.py +3 -13
  29. claude_mpm/services/mcp_gateway/server/stdio_server.py +4 -10
  30. claude_mpm/services/mcp_gateway/tools/__init__.py +13 -2
  31. claude_mpm/services/mcp_gateway/tools/external_mcp_services.py +36 -6
  32. claude_mpm/services/mcp_gateway/tools/kuzu_memory_service.py +542 -0
  33. claude_mpm/services/shared/__init__.py +2 -1
  34. claude_mpm/services/shared/service_factory.py +8 -5
  35. claude_mpm/services/unified/config_strategies/__init__.py +190 -0
  36. claude_mpm/services/unified/config_strategies/config_schema.py +689 -0
  37. claude_mpm/services/unified/config_strategies/context_strategy.py +748 -0
  38. claude_mpm/services/unified/config_strategies/error_handling_strategy.py +999 -0
  39. claude_mpm/services/unified/config_strategies/file_loader_strategy.py +871 -0
  40. claude_mpm/services/unified/config_strategies/unified_config_service.py +802 -0
  41. claude_mpm/services/unified/config_strategies/validation_strategy.py +1105 -0
  42. {claude_mpm-4.4.0.dist-info → claude_mpm-4.4.3.dist-info}/METADATA +15 -15
  43. {claude_mpm-4.4.0.dist-info → claude_mpm-4.4.3.dist-info}/RECORD +47 -27
  44. claude_mpm/cli/commands/configure_tui.py +0 -1927
  45. claude_mpm/services/mcp_gateway/tools/ticket_tools.py +0 -645
  46. claude_mpm/services/mcp_gateway/tools/unified_ticket_tool.py +0 -602
  47. {claude_mpm-4.4.0.dist-info → claude_mpm-4.4.3.dist-info}/WHEEL +0 -0
  48. {claude_mpm-4.4.0.dist-info → claude_mpm-4.4.3.dist-info}/entry_points.txt +0 -0
  49. {claude_mpm-4.4.0.dist-info → claude_mpm-4.4.3.dist-info}/licenses/LICENSE +0 -0
  50. {claude_mpm-4.4.0.dist-info → claude_mpm-4.4.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,542 @@
1
+ """
2
+ Kuzu-Memory MCP Service Integration
3
+ ====================================
4
+
5
+ Provides MCP tool wrappers for kuzu-memory knowledge graph operations,
6
+ enabling the PM agent to store and retrieve memories programmatically.
7
+
8
+ WHY: The PM agent needs structured tools to manage conversation memories,
9
+ allowing it to build up project knowledge over time.
10
+
11
+ DESIGN DECISIONS:
12
+ - Extends ExternalMCPService for consistent integration patterns
13
+ - Provides high-level tools that abstract kuzu-memory complexity
14
+ - Includes context enrichment for better memory retrieval
15
+ - Supports tagging for organized knowledge management
16
+ """
17
+
18
+ import json
19
+ import subprocess
20
+ import sys
21
+ from datetime import datetime
22
+ from pathlib import Path
23
+ from typing import Any, Dict, List, Optional
24
+
25
+ from claude_mpm.services.mcp_gateway.tools.base_adapter import BaseToolAdapter
26
+ from claude_mpm.services.mcp_gateway.core.interfaces import (
27
+ MCPToolDefinition,
28
+ MCPToolInvocation,
29
+ MCPToolResult,
30
+ )
31
+
32
+
33
+ class KuzuMemoryService(BaseToolAdapter):
34
+ """
35
+ MCP service wrapper for kuzu-memory knowledge graph.
36
+
37
+ Provides tools for:
38
+ - Storing memories with tags
39
+ - Retrieving relevant memories
40
+ - Searching memories by query
41
+ - Getting enriched context for topics
42
+ """
43
+
44
+ def __init__(self):
45
+ """Initialize kuzu-memory MCP service."""
46
+ # Define the tool
47
+ definition = MCPToolDefinition(
48
+ name="kuzu_memory",
49
+ description="Knowledge graph memory system for persistent context",
50
+ input_schema={
51
+ "type": "object",
52
+ "properties": {
53
+ "action": {
54
+ "type": "string",
55
+ "enum": ["store", "recall", "search", "context"],
56
+ "description": "The memory operation to perform",
57
+ },
58
+ "content": {
59
+ "type": "string",
60
+ "description": "Content for store operation",
61
+ },
62
+ "query": {
63
+ "type": "string",
64
+ "description": "Query for recall/search/context operations",
65
+ },
66
+ "tags": {
67
+ "type": "array",
68
+ "items": {"type": "string"},
69
+ "description": "Tags for filtering or categorization",
70
+ },
71
+ "limit": {
72
+ "type": "integer",
73
+ "default": 5,
74
+ "description": "Maximum number of results",
75
+ },
76
+ },
77
+ "required": ["action"],
78
+ },
79
+ )
80
+ super().__init__(definition)
81
+
82
+ self.service_name = "kuzu-memory"
83
+ self.package_name = "kuzu-memory"
84
+ # Use the current project directory as kuzu-memory works with project-specific databases
85
+ self.project_path = Path.cwd()
86
+ self._is_installed = False
87
+ self.kuzu_cmd = None
88
+
89
+ async def _check_installation(self) -> bool:
90
+ """Check if kuzu-memory is installed via pipx."""
91
+ # Check pipx installation first
92
+ pipx_path = (
93
+ Path.home()
94
+ / ".local"
95
+ / "pipx"
96
+ / "venvs"
97
+ / "kuzu-memory"
98
+ / "bin"
99
+ / "kuzu-memory"
100
+ )
101
+ if pipx_path.exists():
102
+ self.kuzu_cmd = str(pipx_path)
103
+ return True
104
+
105
+ # Check system PATH
106
+ import shutil
107
+
108
+ kuzu_cmd = shutil.which("kuzu-memory")
109
+ if kuzu_cmd:
110
+ self.kuzu_cmd = kuzu_cmd
111
+ return True
112
+
113
+ return False
114
+
115
+ async def _install_package(self) -> bool:
116
+ """Install kuzu-memory using pipx (preferred over pip)."""
117
+ try:
118
+ # Check if pipx is available
119
+ import shutil
120
+
121
+ if not shutil.which("pipx"):
122
+ self.log_warning(
123
+ "pipx not found. Install it first: python -m pip install --user pipx"
124
+ )
125
+ return False
126
+
127
+ self.log_info("Installing kuzu-memory via pipx...")
128
+ result = subprocess.run(
129
+ ["pipx", "install", "kuzu-memory"],
130
+ capture_output=True,
131
+ text=True,
132
+ timeout=60,
133
+ check=False,
134
+ )
135
+
136
+ if result.returncode == 0:
137
+ self.log_info("Successfully installed kuzu-memory via pipx")
138
+ return await self._check_installation()
139
+
140
+ self.log_error(f"Failed to install kuzu-memory: {result.stderr}")
141
+ return False
142
+
143
+ except Exception as e:
144
+ self.log_error(f"Error installing kuzu-memory: {e}")
145
+ return False
146
+
147
+ async def initialize(self) -> bool:
148
+ """Initialize the kuzu-memory service."""
149
+ try:
150
+ # Check if package is installed
151
+ self._is_installed = await self._check_installation()
152
+
153
+ if not self._is_installed:
154
+ self.log_warning(
155
+ f"{self.package_name} not installed, attempting installation..."
156
+ )
157
+ await self._install_package()
158
+ self._is_installed = await self._check_installation()
159
+
160
+ if not self._is_installed:
161
+ self.log_error(f"Failed to install {self.package_name}")
162
+ return False
163
+
164
+ self.log_info(f"{self.package_name} is available")
165
+ self._initialized = True
166
+ return True
167
+
168
+ except Exception as e:
169
+ self.log_error(f"Failed to initialize {self.service_name}: {e}")
170
+ return False
171
+
172
+ async def invoke(self, invocation: MCPToolInvocation) -> MCPToolResult:
173
+ """
174
+ Invoke kuzu-memory tool based on the invocation request.
175
+
176
+ Routes to appropriate method based on action parameter.
177
+ """
178
+ params = invocation.parameters
179
+ action = params.get("action")
180
+
181
+ try:
182
+ if action == "store":
183
+ result = await self.store_memory(
184
+ params.get("content"),
185
+ params.get("tags"),
186
+ {} # metadata
187
+ )
188
+ elif action == "recall":
189
+ result = await self.recall_memories(
190
+ params.get("query"),
191
+ params.get("limit", 5),
192
+ params.get("tags")
193
+ )
194
+ elif action == "search":
195
+ result = await self.search_memories(
196
+ params.get("query", ""),
197
+ "both", # search_type
198
+ params.get("limit", 10)
199
+ )
200
+ elif action == "context":
201
+ result = await self.get_context(
202
+ params.get("query", ""),
203
+ 2, # depth
204
+ True # include_related
205
+ )
206
+ else:
207
+ return MCPToolResult(
208
+ success=False,
209
+ error=f"Unknown action: {action}"
210
+ )
211
+
212
+ return MCPToolResult(
213
+ success=result.get("success", False),
214
+ data=result,
215
+ error=result.get("error")
216
+ )
217
+
218
+ except Exception as e:
219
+ return MCPToolResult(
220
+ success=False,
221
+ error=str(e)
222
+ )
223
+
224
+ def validate_parameters(self, parameters: Dict[str, Any]) -> bool:
225
+ """Validate tool parameters - basic implementation."""
226
+ return True # Validation is handled in individual methods
227
+
228
+ async def shutdown(self) -> None:
229
+ """Shutdown the service."""
230
+ pass # No resources to clean up
231
+
232
+
233
+ async def store_memory(
234
+ self,
235
+ content: str,
236
+ tags: Optional[List[str]] = None,
237
+ metadata: Optional[Dict[str, Any]] = None,
238
+ ) -> Dict[str, Any]:
239
+ """
240
+ Store a memory in the knowledge graph.
241
+
242
+ Args:
243
+ content: Memory content to store
244
+ tags: Optional tags for categorization
245
+ metadata: Optional metadata
246
+
247
+ Returns:
248
+ Result of the storage operation
249
+ """
250
+ if not self._is_installed:
251
+ return {
252
+ "success": False,
253
+ "error": "kuzu-memory not installed",
254
+ }
255
+
256
+ try:
257
+ # Use remember command for storing memories
258
+ # kuzu-memory works with project-specific databases in the current working directory
259
+ cmd = [self.kuzu_cmd, "remember", content]
260
+
261
+ # Execute command in project directory
262
+ result = subprocess.run(
263
+ cmd,
264
+ capture_output=True,
265
+ text=True,
266
+ timeout=10,
267
+ cwd=str(self.project_path),
268
+ )
269
+
270
+ if result.returncode == 0:
271
+ return {
272
+ "success": True,
273
+ "message": f"Memory stored successfully",
274
+ "content": content[:100],
275
+ "tags": tags or [],
276
+ }
277
+
278
+ return {
279
+ "success": False,
280
+ "error": result.stderr or "Failed to store memory",
281
+ }
282
+
283
+ except Exception as e:
284
+ self.logger.error(f"Error storing memory: {e}")
285
+ return {
286
+ "success": False,
287
+ "error": str(e),
288
+ }
289
+
290
+ async def recall_memories(
291
+ self,
292
+ query: str,
293
+ limit: int = 5,
294
+ tags: Optional[List[str]] = None,
295
+ ) -> Dict[str, Any]:
296
+ """
297
+ Recall memories relevant to a query.
298
+
299
+ Args:
300
+ query: Query to find relevant memories
301
+ limit: Maximum number of memories
302
+ tags: Optional tag filter
303
+
304
+ Returns:
305
+ Retrieved memories
306
+ """
307
+ if not self._is_installed:
308
+ return {
309
+ "success": False,
310
+ "error": "kuzu-memory not installed",
311
+ "memories": [],
312
+ }
313
+
314
+ try:
315
+ # Use recall command for retrieving memories
316
+ # kuzu-memory works with project-specific databases in the current working directory
317
+ cmd = [
318
+ self.kuzu_cmd,
319
+ "recall",
320
+ query,
321
+ "--format",
322
+ "json",
323
+ "--max-memories",
324
+ str(limit),
325
+ ]
326
+
327
+ # Execute command in project directory
328
+ result = subprocess.run(
329
+ cmd,
330
+ capture_output=True,
331
+ text=True,
332
+ timeout=10,
333
+ cwd=str(self.project_path),
334
+ )
335
+
336
+ if result.returncode == 0 and result.stdout:
337
+ memories = json.loads(result.stdout)
338
+ return {
339
+ "success": True,
340
+ "query": query,
341
+ "count": len(memories),
342
+ "memories": memories,
343
+ }
344
+
345
+ return {
346
+ "success": True,
347
+ "query": query,
348
+ "count": 0,
349
+ "memories": [],
350
+ }
351
+
352
+ except Exception as e:
353
+ self.logger.error(f"Error recalling memories: {e}")
354
+ return {
355
+ "success": False,
356
+ "error": str(e),
357
+ "memories": [],
358
+ }
359
+
360
+ async def search_memories(
361
+ self,
362
+ search_term: str,
363
+ search_type: str = "both",
364
+ limit: int = 10,
365
+ ) -> Dict[str, Any]:
366
+ """
367
+ Search memories by using recall with the search term.
368
+
369
+ Args:
370
+ search_term: Term to search for
371
+ search_type: Type of search (not used, kept for compatibility)
372
+ limit: Maximum number of results
373
+
374
+ Returns:
375
+ Search results
376
+ """
377
+ if not self._is_installed:
378
+ return {
379
+ "success": False,
380
+ "error": "kuzu-memory not installed",
381
+ "results": [],
382
+ }
383
+
384
+ try:
385
+ # Use recall for searching (kuzu-memory doesn't have a separate search command)
386
+ cmd = [
387
+ self.kuzu_cmd,
388
+ "recall",
389
+ search_term,
390
+ "--format",
391
+ "json",
392
+ "--max-memories",
393
+ str(limit),
394
+ ]
395
+
396
+ # Execute command in project directory
397
+ result = subprocess.run(
398
+ cmd,
399
+ capture_output=True,
400
+ text=True,
401
+ timeout=10,
402
+ cwd=str(self.project_path),
403
+ )
404
+
405
+ if result.returncode == 0 and result.stdout:
406
+ # Parse the output
407
+ results = []
408
+ if "No relevant memories found" not in result.stdout:
409
+ # Try to extract memories from output
410
+ lines = result.stdout.strip().split("\n")
411
+ for line in lines:
412
+ if line.strip() and not line.startswith("🔍"):
413
+ results.append({"content": line.strip()})
414
+
415
+ return {
416
+ "success": True,
417
+ "search_term": search_term,
418
+ "count": len(results),
419
+ "results": results[:limit],
420
+ }
421
+
422
+ return {
423
+ "success": True,
424
+ "search_term": search_term,
425
+ "count": 0,
426
+ "results": [],
427
+ }
428
+
429
+ except Exception as e:
430
+ self.log_error(f"Error searching memories: {e}")
431
+ return {
432
+ "success": False,
433
+ "error": str(e),
434
+ "results": [],
435
+ }
436
+
437
+ async def get_context(
438
+ self,
439
+ topic: str,
440
+ depth: int = 2,
441
+ include_related: bool = True,
442
+ ) -> Dict[str, Any]:
443
+ """
444
+ Get enriched context for a topic using the enhance command.
445
+
446
+ Args:
447
+ topic: Topic to get context for
448
+ depth: Maximum memories to include
449
+ include_related: Not used, kept for compatibility
450
+
451
+ Returns:
452
+ Enriched context for the topic
453
+ """
454
+ if not self._is_installed:
455
+ return {
456
+ "success": False,
457
+ "error": "kuzu-memory not installed",
458
+ "context": {},
459
+ }
460
+
461
+ try:
462
+ # Use enhance command for context enrichment
463
+ cmd = [
464
+ self.kuzu_cmd,
465
+ "enhance",
466
+ topic,
467
+ "--max-memories",
468
+ str(depth * 3),
469
+ "--format",
470
+ "plain", # Get just the context
471
+ ]
472
+
473
+ # Execute command in project directory
474
+ result = subprocess.run(
475
+ cmd,
476
+ capture_output=True,
477
+ text=True,
478
+ timeout=15,
479
+ cwd=str(self.project_path),
480
+ )
481
+
482
+ if result.returncode == 0 and result.stdout:
483
+ return {
484
+ "success": True,
485
+ "topic": topic,
486
+ "context": result.stdout.strip(),
487
+ "memories": [] # Enhanced context is already processed
488
+ }
489
+
490
+ # Fallback to recall if enhance fails
491
+ self.log_debug("Enhance command failed, falling back to recall")
492
+ return await self.recall_memories(topic, limit=depth * 3)
493
+
494
+ except Exception as e:
495
+ self.log_error(f"Error getting context: {e}")
496
+ # Fallback to basic recall
497
+ return await self.recall_memories(topic, limit=depth * 3)
498
+
499
+
500
+ # Tool function wrappers for MCP Gateway
501
+ async def store_memory(
502
+ content: str,
503
+ tags: Optional[List[str]] = None,
504
+ metadata: Optional[Dict[str, Any]] = None,
505
+ ) -> Dict[str, Any]:
506
+ """Store a memory using the kuzu-memory service."""
507
+ service = KuzuMemoryService()
508
+ await service.initialize()
509
+ return await service.store_memory(content, tags, metadata)
510
+
511
+
512
+ async def recall_memories(
513
+ query: str,
514
+ limit: int = 5,
515
+ tags: Optional[List[str]] = None,
516
+ ) -> Dict[str, Any]:
517
+ """Recall memories relevant to a query."""
518
+ service = KuzuMemoryService()
519
+ await service.initialize()
520
+ return await service.recall_memories(query, limit, tags)
521
+
522
+
523
+ async def search_memories(
524
+ search_term: str,
525
+ search_type: str = "both",
526
+ limit: int = 10,
527
+ ) -> Dict[str, Any]:
528
+ """Search memories by content or tags."""
529
+ service = KuzuMemoryService()
530
+ await service.initialize()
531
+ return await service.search_memories(search_term, search_type, limit)
532
+
533
+
534
+ async def get_context(
535
+ topic: str,
536
+ depth: int = 2,
537
+ include_related: bool = True,
538
+ ) -> Dict[str, Any]:
539
+ """Get enriched context for a topic."""
540
+ service = KuzuMemoryService()
541
+ await service.initialize()
542
+ return await service.get_context(topic, depth, include_related)
@@ -9,7 +9,7 @@ from .async_service_base import AsyncServiceBase
9
9
  from .config_service_base import ConfigServiceBase
10
10
  from .lifecycle_service_base import LifecycleServiceBase
11
11
  from .manager_base import ManagerBase
12
- from .service_factory import ServiceFactory
12
+ from .service_factory import ServiceFactory, get_service_factory
13
13
 
14
14
  __all__ = [
15
15
  "AsyncServiceBase",
@@ -17,4 +17,5 @@ __all__ = [
17
17
  "LifecycleServiceBase",
18
18
  "ManagerBase",
19
19
  "ServiceFactory",
20
+ "get_service_factory",
20
21
  ]
@@ -287,20 +287,23 @@ class ServiceFactory:
287
287
  self.logger.debug("Cleared all service registrations")
288
288
 
289
289
 
290
- # Global factory instance
291
- _global_factory = ServiceFactory()
290
+ # Global factory instance (lazy initialization)
291
+ _global_factory: Optional[ServiceFactory] = None
292
292
 
293
293
 
294
294
  def get_service_factory() -> ServiceFactory:
295
- """Get global service factory instance."""
295
+ """Get global service factory instance (created on first use)."""
296
+ global _global_factory
297
+ if _global_factory is None:
298
+ _global_factory = ServiceFactory()
296
299
  return _global_factory
297
300
 
298
301
 
299
302
  def create_service(service_class: Type[T], **kwargs) -> T:
300
303
  """Convenience function to create service using global factory."""
301
- return _global_factory.create_service(service_class, **kwargs)
304
+ return get_service_factory().create_service(service_class, **kwargs)
302
305
 
303
306
 
304
307
  def register_service(service_name: str, service_class: Type) -> None:
305
308
  """Convenience function to register service with global factory."""
306
- _global_factory.register_service(service_name, service_class)
309
+ get_service_factory().register_service(service_name, service_class)