Skip to main content
Glama
santoshray02

CSV Editor

by santoshray02

remove_duplicates

Eliminates duplicate rows in CSV data by comparing specified columns, keeping the first or last occurrence.

Instructions

Remove duplicate rows.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYes
subsetNo
keepNofirst

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core implementation of the remove_duplicates tool. Gets session data, validates subset columns, uses pandas drop_duplicates() to remove duplicates, records the operation, and returns success/result info.
    async def remove_duplicates(
        session_id: str, subset: list[str] | None = None, keep: str = "first", ctx: Context = None
    ) -> dict[str, Any]:
        """
        Remove duplicate rows.
    
        Args:
            session_id: Session identifier
            subset: Column names to consider for duplicates (None for all)
            keep: Which duplicates to keep ('first', 'last', False to drop all)
            ctx: FastMCP context
    
        Returns:
            Dict with success status and duplicate info
        """
        try:
            manager = get_session_manager()
            session = manager.get_session(session_id)
    
            if not session or session.df is None:
                return {"success": False, "error": "Invalid session or no data loaded"}
    
            df = session.df
            rows_before = len(df)
    
            if subset:
                missing_cols = [col for col in subset if col not in df.columns]
                if missing_cols:
                    return {"success": False, "error": f"Columns not found: {missing_cols}"}
    
            # Convert keep parameter
            keep_param = keep if keep != "none" else False
    
            session.df = df.drop_duplicates(subset=subset, keep=keep_param).reset_index(drop=True)
            rows_after = len(session.df)
    
            session.record_operation(
                OperationType.REMOVE_DUPLICATES,
                {"subset": subset, "keep": keep, "rows_removed": rows_before - rows_after},
            )
    
            return {
                "success": True,
                "rows_before": rows_before,
                "rows_after": rows_after,
                "duplicates_removed": rows_before - rows_after,
                "subset": subset,
                "keep": keep,
            }
    
        except Exception as e:
            logger.error(f"Error removing duplicates: {e!s}")
            return {"success": False, "error": str(e)}
  • MCP tool registration of remove_duplicates via @mcp.tool decorator. Defines the public API with session_id, subset, and keep parameters, delegating to the implementation.
    @mcp.tool
    async def remove_duplicates(
        session_id: str, subset: list[str] | None = None, keep: str = "first", ctx: Context = None
    ) -> dict[str, Any]:
        """Remove duplicate rows."""
        return await _remove_duplicates(session_id, subset, keep, ctx)
  • OperationType enum defining REMOVE_DUPLICATES = 'remove_duplicates' used to record the operation in session history.
    REMOVE_DUPLICATES = "remove_duplicates"
    GROUP_BY = "group_by"
    VALIDATE = "validate"
    PROFILE = "profile"
    QUALITY_CHECK = "quality_check"
    ANOMALY_DETECTION = "anomaly_detection"
  • Data quality validation helper that recommends using the remove_duplicates tool when duplicate rows are detected.
    quality_results["recommendations"].append(
        "Consider removing duplicate rows using the remove_duplicates tool"
    )
  • Capabilities listing mentioning remove_duplicates as a data_manipulation capability.
        "remove_duplicates",
    ],
Behavior2/5

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

No annotations are present, so the description must disclose behavioral traits. It fails to describe if data is modified in place, irreversible, or how duplicates are identified (e.g., row selection criteria).

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?

The description is a single, efficient sentence with no waste. However, it lacks any structural elements like sections or examples, which limits its helpfulness.

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?

There is an output schema, so return values are partially covered. However, for a data modification tool, the description omits important context like whether the operation is reversible or requires a session ID.

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?

With 0% schema description coverage and 3 unexplained parameters, the description adds no meaning. 'subset' and 'keep' are not clarified despite defaults and potential impact on behavior.

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

Purpose5/5

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

The description explicitly states 'Remove duplicate rows,' clearly indicating the verb and resource. Among sibling tools like 'filter_rows' or 'detect_outliers', this uniquely identifies the operation.

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 guidelines provided on when to use this tool versus alternatives like 'filter_rows' or 'check_data_quality'. There is no mention of prerequisites or context.

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