Skip to main content
Glama
santoshray02

CSV Editor

by santoshray02

remove_duplicates

Eliminate duplicate rows from CSV files to maintain data integrity and accuracy in datasets.

Instructions

Remove duplicate rows.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYes
subsetNo
keepNofirst

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler function that executes the duplicate removal using pandas.DataFrame.drop_duplicates, updates the session dataframe, records the operation, and returns statistics on rows removed.
    async def remove_duplicates(
        session_id: str,
        subset: Optional[List[str]] = 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: {str(e)}")
            return {"success": False, "error": str(e)}
  • MCP tool registration decorator and wrapper function that delegates to the core implementation in transformations.py, defining the tool schema via type annotations.
    @mcp.tool
    async def remove_duplicates(
        session_id: str,
        subset: Optional[List[str]] = None,
        keep: str = "first",
        ctx: Context = None
    ) -> Dict[str, Any]:
        """Remove duplicate rows."""
        return await _remove_duplicates(session_id, subset, keep, ctx)
  • OperationType enum value used to record the remove_duplicates operation in session history.
    REMOVE_DUPLICATES = "remove_duplicates"
Behavior1/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 'Remove duplicate rows' but fails to explain critical aspects like whether this is a destructive operation, what happens to the removed rows, if it requires specific permissions, or the output format. This is inadequate for a mutation tool with zero annotation coverage.

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 appropriately sized and front-loaded, making it easy to parse quickly without unnecessary elaboration.

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's complexity (a mutation operation with 3 parameters), lack of annotations, and 0% schema coverage, the description is incomplete. While an output schema exists, the description doesn't cover behavioral traits, parameter meanings, or usage context, making it insufficient for effective tool selection.

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?

With 0% schema description coverage for 3 parameters, the description must compensate but adds no parameter information. It doesn't explain 'session_id', 'subset', or 'keep', leaving their purposes and usage undocumented. This fails to address the significant coverage gap.

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 'Remove duplicate rows' clearly states the action (remove) and target (duplicate rows), which is specific and unambiguous. However, it doesn't differentiate from sibling tools like 'filter_rows' or 'detect_outliers' that might also manipulate rows, so it falls short of a perfect score.

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. With siblings like 'filter_rows' and 'detect_outliers' that might handle similar data operations, there's no indication of prerequisites, exclusions, or comparative contexts, leaving usage unclear.

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