Skip to main content
Glama
santoshray02

CSV Editor

by santoshray02

export_history

Export CSV editing history to a file for backup, analysis, or documentation purposes. Supports JSON format and requires session ID and file path.

Instructions

Export operation history to a file.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYes
file_pathYes
formatNojson

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core implementation of the export_history tool logic, which serializes and writes the session's operation history to a JSON or CSV file.
    def export_history(self, file_path: str, format: str = "json") -> bool:
        """Export history to a file."""
        try:
            if format == "json":
                data = {
                    "session_id": self.session_id,
                    "exported_at": datetime.utcnow().isoformat(),
                    "total_operations": len(self.history),
                    "current_position": self.current_index,
                    "operations": self.get_history()
                }
                
                with open(file_path, 'w') as f:
                    json.dump(data, f, indent=2)
                    
            elif format == "csv":
                # Export as CSV with operation details
                history_data = []
                for entry in self.history:
                    history_data.append({
                        "timestamp": entry.timestamp.isoformat(),
                        "operation_type": entry.operation_type,
                        "details": json.dumps(entry.details),
                        "has_snapshot": entry.data_snapshot is not None
                    })
                
                df = pd.DataFrame(history_data)
                df.to_csv(file_path, index=False)
            
            logger.info(f"Exported history to {file_path}")
            return True
            
        except Exception as e:
            logger.error(f"Error exporting history: {str(e)}")
            return False
  • MCP tool registration for 'export_history' using @mcp.tool decorator, which delegates to the implementation in history_operations.
    @mcp.tool
    async def export_history(
        session_id: str,
        file_path: str,
        format: str = "json",
        ctx: Context = None
    ) -> Dict[str, Any]:
        """Export operation history to a file."""
        return await _export_history(session_id, file_path, format, ctx)
  • Helper function _export_history that handles session retrieval, validation, and delegation to HistoryManager.export_history, returning standardized OperationResult.
    async def export_history(
        session_id: str,
        file_path: str,
        format: str = "json",
        ctx: Context = None
    ) -> Dict[str, Any]:
        """
        Export operation history to a file.
        
        Args:
            session_id: Session identifier
            file_path: Path to export history to
            format: Export format ('json' or 'csv')
            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"Exporting history for session {session_id} to {file_path}")
            
            success = session.history_manager.export_history(file_path, format)
            
            if success:
                return OperationResult(
                    success=True,
                    message=f"History exported to {file_path}",
                    session_id=session_id,
                    data={"file_path": file_path, "format": format}
                ).model_dump()
            else:
                return OperationResult(
                    success=False,
                    message="Failed to export history",
                    error="Export operation failed"
                ).model_dump()
                
        except Exception as e:
            logger.error(f"Error exporting history: {str(e)}")
            if ctx:
                await ctx.error(f"Failed to export history: {str(e)}")
            return OperationResult(
                success=False,
                message="Failed to export history",
                error=str(e)
            ).model_dump()
Behavior2/5

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

With no annotations, the description carries full burden but only states the basic action without behavioral details. It doesn't disclose if this is a read/write operation, file system impacts, permissions needed, or error handling (e.g., invalid file paths). This is inadequate for a tool that likely writes files.

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, efficient sentence with zero wasted words. It's front-loaded with the core action, making it easy to parse quickly, though this brevity contributes to gaps in other dimensions.

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

Completeness2/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 may cover return values), but with no annotations, 0% schema coverage, and three parameters, the description is incomplete. It fails to address key aspects like behavioral traits, parameter meanings, or usage context, making it insufficient for safe and effective tool invocation.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate but adds no parameter information. It doesn't explain what 'session_id', 'file_path', or 'format' mean, their expected formats, or constraints (e.g., file path validity). This leaves all three parameters undocumented beyond their schema types.

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 'Export operation history to a file' clearly states the action (export) and target (operation history), but it's vague about what 'operation history' entails compared to siblings like 'get_history' or 'clear_history'. It doesn't specify if this exports all history or a subset, making it less distinct from related tools.

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 like 'export_csv' or 'get_history'. The description lacks context about prerequisites (e.g., needing a valid session) or exclusions, leaving the agent to infer usage from the tool name alone.

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