Skip to main content
Glama
santoshray02

CSV Editor

by santoshray02

export_history

Export the history of CSV editing operations to a file for auditing or review.

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

  • Main handler for the export_history tool. Retrieves the session, validates it, and calls history_manager.export_history() to write history to a file in JSON or CSV format.
    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: {e!s}")
            if ctx:
                await ctx.error(f"Failed to export history: {e!s}")
            return OperationResult(
                success=False, message="Failed to export history", error=str(e)
            ).model_dump()
  • Core logic for exporting history. Supports JSON format (serializes all operations with metadata) and CSV format (flattens operations into a DataFrame). Returns boolean success status.
    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: {e!s}")
            return False
  • Registration of export_history as an MCP tool via @mcp.tool decorator. Defines the tool's signature (session_id, file_path, format) and delegates to the handler.
    @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)
  • Import of the export_history handler from the tools.history_operations module into server.py, aliased as _export_history.
    from .tools.history_operations import export_history as _export_history
Behavior2/5

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

No annotations provided; description does not disclose side effects (e.g., whether export is read-only or modifies state). Does not mention permissions or expected behavior (e.g., file overwrite). Name suggests read-only, but not confirmed.

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

Conciseness4/5

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

Single sentence, no fluff. However, conciseness sacrifices necessary detail. It earns its place but could be expanded slightly.

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

Completeness1/5

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

Given the presence of 3 parameters, no annotations, and no param descriptions, the description is severely lacking. It does not explain the output schema or how the export works relative to siblings. An agent would struggle to use this tool correctly.

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

Parameters1/5

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

Zero schema description coverage, and the description does not explain any parameter. 'session_id', 'file_path', and 'format' are left to guess. The agent cannot infer valid values or usage without additional information.

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 action (export) and resource (operation history) and target (to a file). It distinguishes from siblings like 'get_history' (returns data) and 'export_csv' (likely exports data rather than history). Could be more specific about what 'operation history' means.

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 on when to use this tool versus alternatives (e.g., export_csv, get_history). No prerequisites or context provided (e.g., session must exist). The description is minimal and does not help the agent decide.

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