|
|
@@ -16,9 +16,9 @@ Modifications :
|
|
|
-----------------------------------------------------------------------------------------
|
|
|
|
|
|
"""
|
|
|
-
|
|
|
-from .context_schema import DEFAULT_CONTEXT
|
|
|
-
|
|
|
+from mcp_server.core.constants import ModxType, actionType
|
|
|
+from mcp_server.core.context.context_schema import DEFAULT_CONTEXT
|
|
|
+from mcp_server.config.logger import LOGGER as logger
|
|
|
|
|
|
class ContextManager:
|
|
|
"""Context manager for the MCP server."""
|
|
|
@@ -27,14 +27,36 @@ class ContextManager:
|
|
|
"""Initialize the context manager."""
|
|
|
self.context = DEFAULT_CONTEXT.copy()
|
|
|
|
|
|
- def add_context(self, key: str, value):
|
|
|
- """"""
|
|
|
- pass
|
|
|
-
|
|
|
- def remove_context(self, key: str):
|
|
|
- """Supprimer du contexte."""
|
|
|
- pass
|
|
|
+ def add_to_context(self, modx_type, items):
|
|
|
+ """Add items of a given MODX type to the context."""
|
|
|
+ if modx_type in self.context:
|
|
|
+ for element_id, actions in items.items():
|
|
|
+ filtered_actions = {}
|
|
|
+ for action, value in actions.items():
|
|
|
+ if action not in actionType.__members__.values():
|
|
|
+ logger.warning(f"ContextManager - add_to_context - Unknown action type '{action}' for MODX type '{modx_type}'. Skipping this action.")
|
|
|
+ else:
|
|
|
+ filtered_actions[action] = value
|
|
|
+ self.context[modx_type][element_id] = filtered_actions
|
|
|
+ logger.debug(f"ContextManager - add_to_context - Items added to context.")
|
|
|
+ else:
|
|
|
+ logger.warning(f"ContextManager - add_to_context - MODX type '{modx_type}' not in context. Cannot add items to context.")
|
|
|
|
|
|
+ def remove_from_context(self, modx_type, item_ids):
|
|
|
+ """Remove items of a given MODX type from the context by their IDs."""
|
|
|
+ if modx_type in self.context:
|
|
|
+ for item_id in item_ids:
|
|
|
+ if item_id in self.context[modx_type]:
|
|
|
+ del self.context[modx_type][item_id]
|
|
|
+ logger.debug(f"ContextManager - remove_from_context - Items removed from context.")
|
|
|
+ else:
|
|
|
+ logger.warning(f"ContextManager - remove_from_context - MODX type '{modx_type}' not in context. Cannot remove items from context.")
|
|
|
+
|
|
|
+ def clear_context(self):
|
|
|
+ """Clear the entire context."""
|
|
|
+ self.context = DEFAULT_CONTEXT.copy()
|
|
|
+ logger.debug("ContextManager - clear_context - Context cleared.")
|
|
|
+
|
|
|
def get_context(self):
|
|
|
"""Obtenir le contexte complet."""
|
|
|
return self.context
|