Skip to main content
Glama
santoshray02

CSV Editor

by santoshray02

restore_to_operation

Restore CSV editing sessions to a specific operation point using session and operation IDs. Revert changes or continue work from a saved state in the CSV Editor.

Instructions

Restore session data to a specific operation point.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYes
operation_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP tool handler for 'restore_to_operation', decorated with @mcp.tool and delegates to the implementation in history_operations.py
    async def restore_to_operation(
        session_id: str,
        operation_id: str,
        ctx: Context = None
    ) -> Dict[str, Any]:
        """Restore session data to a specific operation point."""
        return await _restore_to_operation(session_id, operation_id, ctx)
  • Main implementation of restore_to_operation tool logic: retrieves session, calls session.restore_to_operation, handles errors and logging, returns wrapped result
    async def restore_to_operation(
        session_id: str,
        operation_id: str,
        ctx: Context = None
    ) -> Dict[str, Any]:
        """
        Restore session data to a specific operation point.
        
        Args:
            session_id: Session identifier
            operation_id: Operation ID to restore to
            ctx: FastMCP context
            
        Returns:
            Dict with success status and restore result
        """
        try:
            manager = get_session_manager()
            session = manager.get_session(session_id)
            
            if not session:
                return OperationResult(
                    success=False,
                    message="Session not found",
                    error=f"No session with ID: {session_id}"
                ).model_dump()
            
            if ctx:
                await ctx.info(f"Restoring session {session_id} to operation {operation_id}")
            
            result = await session.restore_to_operation(operation_id)
            
            if result["success"]:
                if ctx:
                    await ctx.info(f"Successfully restored to operation {operation_id}")
                
                return OperationResult(
                    success=True,
                    message=result["message"],
                    session_id=session_id,
                    data=result
                ).model_dump()
            else:
                return OperationResult(
                    success=False,
                    message="Failed to restore to operation",
                    error=result.get("error")
                ).model_dump()
                
        except Exception as e:
            logger.error(f"Error restoring to operation: {str(e)}")
            if ctx:
                await ctx.error(f"Failed to restore to operation: {str(e)}")
            return OperationResult(
                success=False,
                message="Failed to restore to operation",
                error=str(e)
            ).model_dump()
  • CSVSession method that calls history_manager to restore data snapshot and updates session dataframe
    async def restore_to_operation(self, operation_id: str) -> Dict[str, Any]:
        """Restore data to a specific operation point."""
        if not self.history_manager:
            return {"success": False, "error": "History is not enabled"}
        
        try:
            data_snapshot = self.history_manager.restore_to_operation(operation_id)
            
            if data_snapshot is not None:
                self.df = data_snapshot
                
                # Trigger auto-save if configured
                if self.auto_save_manager.should_save_after_operation():
                    await self.auto_save_manager.trigger_save(self._save_callback, "restore")
                
                return {
                    "success": True,
                    "message": f"Restored to operation {operation_id}",
                    "shape": self.df.shape
                }
            else:
                return {
                    "success": False,
                    "error": f"Could not restore to operation {operation_id}"
                }
                
        except Exception as e:
            logger.error(f"Error during restore: {str(e)}")
            return {"success": False, "error": str(e)}
  • Core restore logic: finds operation index, locates nearest prior data snapshot, updates current_index and redo stack, returns snapshot DataFrame
    def restore_to_operation(self, operation_id: str) -> Optional[pd.DataFrame]:
        """Restore data to a specific operation point."""
        # Find the operation
        target_index = None
        for i, entry in enumerate(self.history):
            if entry.operation_id == operation_id:
                target_index = i
                break
        
        if target_index is None:
            logger.error(f"Operation {operation_id} not found")
            return None
        
        # Find the nearest snapshot at or before target
        snapshot = None
        for i in range(target_index, -1, -1):
            if self.history[i].data_snapshot is not None:
                snapshot = self.history[i].data_snapshot.copy()
                self.current_index = target_index
                
                # Clear redo stack since we're jumping to a specific point
                self.redo_stack.clear()
                
                # Save state
                if self.storage_type != HistoryStorage.MEMORY:
                    self._save_history()
                
                logger.info(f"Restored to operation {operation_id}")
                return snapshot
        
        logger.error(f"No snapshot available for operation {operation_id}")
        return None
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool 'restores session data', implying a mutation or state change, but doesn't specify if this is destructive (e.g., overwrites current data), requires permissions, has side effects, or what the restoration entails (e.g., partial vs. full). This leaves significant gaps in understanding the tool's behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with no wasted words. It front-loads the core action ('restore') and resource ('session data'), making it easy to parse quickly. Every element contributes directly to understanding the tool's purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has an output schema (which should cover return values), no annotations, and a simple input schema with 2 parameters, the description is minimally adequate. It states what the tool does but lacks details on behavior, usage context, and parameter specifics, making it incomplete for safe and effective use without additional documentation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 2 parameters with 0% description coverage, so the schema provides no semantic information. The description mentions 'session data' and 'specific operation point', which loosely maps to 'session_id' and 'operation_id', adding some meaning. However, it doesn't clarify what these IDs represent, their format, or how they relate to the restoration process, leaving parameters partially documented.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the tool 'restore session data to a specific operation point', which provides a clear verb ('restore') and resource ('session data'). However, it lacks specificity about what 'restore' entails (e.g., reverting changes, reloading state) and doesn't distinguish itself from sibling tools like 'undo', 'redo', or 'clear_history', which might have overlapping functionality in session management.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a valid session or operation ID), exclusions, or how it differs from tools like 'undo' or 'redo' in the sibling list. The description implies a specific use case but offers no context for selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/santoshray02/csv-editor'

If you have feedback or need assistance with the MCP directory API, please join our Discord server