Skip to main content
Glama
santoshray02

CSV Editor

by santoshray02

clear_history

Remove all operation history from a CSV editing session to reset the undo/redo stack and maintain data privacy.

Instructions

Clear all operation history for a session.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Main handler function for the clear_history tool. Retrieves the CSV session, validates it has a history_manager, and invokes clear_history on the manager. Returns OperationResult indicating success or failure.
    async def clear_history(
        session_id: str,
        ctx: Context = None
    ) -> Dict[str, Any]:
        """
        Clear all operation history for a session.
        
        Args:
            session_id: Session identifier
            ctx: FastMCP context
            
        Returns:
            Dict with success status
        """
        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 not session.history_manager:
                return OperationResult(
                    success=False,
                    message="History is not enabled for this session",
                    error="History management is disabled"
                ).model_dump()
            
            if ctx:
                await ctx.info(f"Clearing history for session {session_id}")
            
            session.history_manager.clear_history()
            
            return OperationResult(
                success=True,
                message="History cleared successfully",
                session_id=session_id
            ).model_dump()
            
        except Exception as e:
            logger.error(f"Error clearing history: {str(e)}")
            if ctx:
                await ctx.error(f"Failed to clear history: {str(e)}")
            return OperationResult(
                success=False,
                message="Failed to clear history",
                error=str(e)
            ).model_dump()
  • Registers the clear_history tool with FastMCP using the @mcp.tool decorator. This is a thin wrapper that delegates to the imported _clear_history implementation.
    @mcp.tool
    async def clear_history(
        session_id: str,
        ctx: Context = None
    ) -> Dict[str, Any]:
        """Clear all operation history for a session."""
        return await _clear_history(session_id, ctx)
  • Pydantic BaseModel defining the standardized output schema (OperationResult) used by clear_history and other tools for consistent response structure and validation.
    class OperationResult(BaseModel):
        """Result of a data operation."""
        
        success: bool = Field(..., description="Whether operation succeeded")
        message: str = Field(..., description="Result message")
        session_id: Optional[str] = Field(None, description="Session ID")
        rows_affected: Optional[int] = Field(None, description="Number of rows affected")
        columns_affected: Optional[List[str]] = Field(None, description="Columns affected")
        data: Optional[Dict[str, Any]] = Field(None, description="Additional result data")
        error: Optional[str] = Field(None, description="Error message if failed")
        warnings: Optional[List[str]] = Field(None, description="Warning messages")
  • Core helper method in HistoryManager class that clears in-memory history structures and removes any persistent storage files associated with the session's history.
    def clear_history(self):
        """Clear all history."""
        self.history.clear()
        self.redo_stack.clear()
        self.current_index = -1
        
        # Clean up files
        if self.storage_type != HistoryStorage.MEMORY:
            # Remove history file
            for ext in ["json", "pkl"]:
                history_file = self._get_history_file_path(ext)
                if os.path.exists(history_file):
                    os.remove(history_file)
            
            # Remove snapshot files
            snapshot_dir = os.path.join(self.history_dir, "snapshots", self.session_id)
            if os.path.exists(snapshot_dir):
                import shutil
                shutil.rmtree(snapshot_dir)
        
        logger.info(f"Cleared history for session {self.session_id}")
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. It states the action 'clear all operation history', implying a destructive mutation, but does not disclose critical behavioral traits like whether this is irreversible, requires specific permissions, affects session state, or has side effects. This is a significant gap for a tool that likely performs a permanent deletion.

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 zero waste—it directly states the tool's action and scope without unnecessary words. It is appropriately sized and front-loaded, making it easy to understand at a glance.

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's complexity (destructive operation with 1 parameter) and the presence of an output schema (which may cover return values), the description is minimally adequate. However, it lacks details on behavioral aspects like irreversibility or permissions, and with no annotations, it does not fully compensate for the missing context, making it incomplete for safe usage.

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

Parameters4/5

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

The input schema has 1 parameter with 0% description coverage, so the schema provides no semantic information. The description does not explicitly mention the 'session_id' parameter, but it implies it by referring to 'for a session', adding some context. However, it does not detail parameter usage, such as format or source, leaving room for improvement.

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

Purpose4/5

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

The description clearly states the verb 'clear' and the resource 'all operation history for a session', making the purpose specific and understandable. However, it does not explicitly differentiate from sibling tools like 'export_history' or 'get_history', which are related but serve different purposes (exporting or retrieving vs. clearing).

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?

The description provides no guidance on when to use this tool versus alternatives, such as 'export_history' for saving history before clearing, or 'undo' for reversing specific operations. It lacks context on prerequisites, like ensuring data is saved, or exclusions, such as not using it for partial history removal.

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