Skip to main content
Glama
santoshray02

CSV Editor

by santoshray02

fill_missing_values

Fill or remove missing values in CSV data using strategies like dropping rows or specifying replacement values to clean datasets.

Instructions

Fill or remove missing values.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYes
strategyNodrop
valueNo
columnsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core implementation of the fill_missing_values tool. Handles missing value strategies including drop, fillna with value/mean/median/mode/ffill/bfill using pandas DataFrame methods on the session data.
    async def fill_missing_values(
        session_id: str,
        strategy: str = "drop",
        value: Any = None,
        columns: Optional[List[str]] = None,
        ctx: Context = None
    ) -> Dict[str, Any]:
        """
        Fill or remove missing values.
        
        Args:
            session_id: Session identifier
            strategy: One of 'drop', 'fill', 'forward', 'backward', 'mean', 'median', 'mode'
            value: Value to fill with (for 'fill' strategy)
            columns: Specific columns to apply to (None for all)
            ctx: FastMCP context
            
        Returns:
            Dict with success status and fill 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
            null_counts_before = df.isnull().sum().to_dict()
            
            if columns:
                missing_cols = [col for col in columns if col not in df.columns]
                if missing_cols:
                    return {"success": False, "error": f"Columns not found: {missing_cols}"}
                target_cols = columns
            else:
                target_cols = df.columns.tolist()
            
            if strategy == "drop":
                session.df = df.dropna(subset=target_cols)
            elif strategy == "fill":
                if value is None:
                    return {"success": False, "error": "Value required for 'fill' strategy"}
                session.df[target_cols] = df[target_cols].fillna(value)
            elif strategy == "forward":
                session.df[target_cols] = df[target_cols].fillna(method='ffill')
            elif strategy == "backward":
                session.df[target_cols] = df[target_cols].fillna(method='bfill')
            elif strategy == "mean":
                for col in target_cols:
                    if df[col].dtype in ['int64', 'float64']:
                        session.df[col] = df[col].fillna(df[col].mean())
            elif strategy == "median":
                for col in target_cols:
                    if df[col].dtype in ['int64', 'float64']:
                        session.df[col] = df[col].fillna(df[col].median())
            elif strategy == "mode":
                for col in target_cols:
                    mode_val = df[col].mode()
                    if len(mode_val) > 0:
                        session.df[col] = df[col].fillna(mode_val[0])
            else:
                return {"success": False, "error": f"Unknown strategy: {strategy}"}
            
            null_counts_after = session.df.isnull().sum().to_dict()
            
            session.record_operation(OperationType.FILL_MISSING, {
                "strategy": strategy,
                "value": str(value) if value is not None else None,
                "columns": target_cols
            })
            
            return {
                "success": True,
                "strategy": strategy,
                "rows_before": len(df),
                "rows_after": len(session.df),
                "null_counts_before": null_counts_before,
                "null_counts_after": null_counts_after
            }
            
        except Exception as e:
            logger.error(f"Error filling missing values: {str(e)}")
            return {"success": False, "error": str(e)}
  • MCP tool registration via @mcp.tool decorator. Defines the tool interface and delegates execution to the core handler in transformations.py.
    @mcp.tool
    async def fill_missing_values(
        session_id: str,
        strategy: str = "drop",
        value: Any = None,
        columns: Optional[List[str]] = None,
        ctx: Context = None
    ) -> Dict[str, Any]:
        """Fill or remove missing values."""
        return await _fill_missing_values(session_id, strategy, value, columns, ctx)
  • Import statement that brings in the fill_missing_values implementation from transformations.py, aliased for use in server wrappers.
    from .tools.transformations import (
        filter_rows as _filter_rows,
        sort_data as _sort_data,
        select_columns as _select_columns,
        rename_columns as _rename_columns,
        add_column as _add_column,
        remove_columns as _remove_columns,
        change_column_type as _change_column_type,
        fill_missing_values as _fill_missing_values,
        remove_duplicates as _remove_duplicates,
        update_column as _update_column
    )
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 of behavioral disclosure. It mentions 'fill or remove' but does not specify the default behavior (e.g., 'drop' as indicated in the schema), potential side effects (e.g., data modification, session changes), or output details (though an output schema exists). This leaves gaps in understanding how the tool behaves in practice.

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 extremely concise with a single phrase 'Fill or remove missing values.' It is front-loaded and wastes no words, making it easy to scan. However, this conciseness comes at the cost of completeness, as noted 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 complexity (4 parameters, 0% schema coverage, no annotations) and the presence of an output schema, the description is incomplete. It does not explain the tool's context (e.g., operates on a data session), parameter usage, or behavioral traits. While the output schema may cover return values, the description lacks essential details for proper tool invocation and understanding.

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 for undocumented parameters. It does not explain any of the 4 parameters (session_id, strategy, value, columns), their purposes, or how they interact (e.g., 'strategy' options like 'fill' vs. 'drop', what 'value' is used for). The description adds no meaning beyond the bare schema, failing to address the coverage gap.

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 'Fill or remove missing values' states the general purpose (handling missing values) but is vague about the specific resource or context. It distinguishes from siblings like 'detect_outliers' or 'remove_duplicates' by focusing on missing values, but lacks specificity about what dataset or session it operates on, which is implied by the 'session_id' parameter but not explicitly stated in the description.

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. It does not mention prerequisites (e.g., having a session with missing values), exclusions, or comparisons to sibling tools like 'check_data_quality' or 'profile_data' that might also handle data issues. Usage is implied by the tool name but not explicitly stated.

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