Skip to main content
Glama
shibuiwilliam

MCP Data Wrangler

data_mean_horizontal

Calculate row-wise mean values across columns for input data files using MCP Data Wrangler, enabling efficient horizontal data aggregation and preprocessing.

Instructions

Mean values across columns for each row

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
input_data_file_pathNoPath to the input data file

Implementation Reference

  • The core handler function for the 'data_mean_horizontal' tool. It loads the input data file, computes the mean across columns (horizontal mean) for each row using pandas DataFrame.mean_horizontal(), converts the result to a JSON dictionary, and returns it as TextContent. Includes error handling.
    async def handle_data_mean_horizontal(
        arguments: dict[str, Any],
    ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        data_mean_input = DataMeanInputSchema.from_args(arguments)
        try:
            mean_horizontal_df = data_mean_input.df.mean_horizontal()
    
            # Convert the DataFrame to a dictionary format
            mean_horizontal_dict = {
                "description": "Mean values across columns for each row",
                "mean_values": {str(i): str(val) if val is not None else None for i, val in enumerate(mean_horizontal_df)},
            }
    
            return [
                types.TextContent(
                    type="text",
                    text=json.dumps(mean_horizontal_dict),
                )
            ]
        except Exception as e:
            logger.error(f"Error calculating mean: {e}")
            return [
                types.TextContent(
                    type="text",
                    text=json.dumps(
                        {
                            "error": "Failed to calculate mean values.",
                            "message": str(e),
                        }
                    ),
                )
            ]
  • Pydantic-based input schema (DataMeanInputSchema) for validating the tool's input, which requires 'input_data_file_path'. Provides static methods for schema definition used in MCP Tool inputSchema, loading data, and conversion from arguments.
    class DataMeanInputSchema(Data):
        model_config = ConfigDict(
            validate_assignment=True,
            frozen=True,
            extra="forbid",
            arbitrary_types_allowed=True,
        )
    
        @staticmethod
        def input_schema() -> dict:
            return {
                "type": "object",
                "properties": {
                    "input_data_file_path": {
                        "type": "string",
                        "description": "Path to the input data file",
                    },
                },
            }
    
        @staticmethod
        def from_schema(input_data_file_path: str) -> "DataMeanInputSchema":
            data = Data.from_file(input_data_file_path)
            return DataMeanInputSchema(df=data.df)
    
        @staticmethod
        def from_args(arguments: dict[str, Any]) -> "DataMeanInputSchema":
            input_data_file_path = arguments["input_data_file_path"]
            return DataMeanInputSchema.from_schema(input_data_file_path=input_data_file_path)
  • Tool registration within MCPServerDataWrangler.tools() method, defining the 'data_mean_horizontal' tool's name, description from enum, and inputSchema from DataMeanInputSchema.
    types.Tool(
        name=MCPServerDataWrangler.data_mean_horizontal.value[0],
        description=MCPServerDataWrangler.data_mean_horizontal.value[1],
        inputSchema=DataMeanInputSchema.input_schema(),
    ),
  • Handler mapping dictionary in MCPServerDataWrangler.tool_to_handler(), mapping 'data_mean_horizontal' tool name to the handle_data_mean_horizontal function.
    @staticmethod
    def tool_to_handler() -> dict[str, Callable]:
        return {
            MCPServerDataWrangler.data_shape.value[0]: handle_data_shape,
            MCPServerDataWrangler.data_schema.value[0]: handle_data_schema,
            MCPServerDataWrangler.describe_data.value[0]: handle_describe_data,
            MCPServerDataWrangler.data_estimated_size.value[0]: handle_data_estimated_size,
            MCPServerDataWrangler.data_count.value[0]: handle_data_count,
            MCPServerDataWrangler.data_max.value[0]: handle_data_max,
            MCPServerDataWrangler.data_max_horizontal.value[0]: handle_data_max_horizontal,
            MCPServerDataWrangler.data_min.value[0]: handle_data_min,
            MCPServerDataWrangler.data_min_horizontal.value[0]: handle_data_min_horizontal,
            MCPServerDataWrangler.data_mean.value[0]: handle_data_mean,
            MCPServerDataWrangler.data_mean_horizontal.value[0]: handle_data_mean_horizontal,
            MCPServerDataWrangler.data_median.value[0]: handle_data_median,
            MCPServerDataWrangler.data_product.value[0]: handle_data_product,
            MCPServerDataWrangler.data_quantile.value[0]: handle_data_quantile,
            MCPServerDataWrangler.data_std.value[0]: handle_data_std,
            MCPServerDataWrangler.data_var.value[0]: handle_data_var,
        }
  • Enum definition MCPServerDataWrangler that holds tool names and descriptions, used for registration; specifically data_mean_horizontal at line 50.
    class MCPServerDataWrangler(Enum):
        data_shape = ("data_shape", "Data shape of the input data")
        data_schema = ("data_schema", "Data schema of the input data")
        describe_data = ("describe_data", "Summary statistics of the input data")
        data_estimated_size = ("data_estimated_size", "Estimated size of the input data")
        data_count = ("data_count", "Number of non-null elements for each column")
        data_max = ("data_max", "Maximum values for each column")
        data_max_horizontal = ("data_max_horizontal", "Maximum values across columns for each row")
        data_min = ("data_min", "Minimum values for each column")
        data_min_horizontal = ("data_min_horizontal", "Minimum values across columns for each row")
        data_mean = ("data_mean", "Mean values for each column")
        data_mean_horizontal = ("data_mean_horizontal", "Mean values across columns for each row")
        data_median = ("data_median", "Median values for each column")
        data_product = ("data_product", "Product values for each column")
        data_quantile = ("data_quantile", "Quantile values for each column")
        data_std = ("data_std", "Standard deviation values for each column")
        data_var = ("data_var", "Variance values for each column")
Behavior2/5

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

With no annotations provided, the description carries full burden but reveals minimal behavioral traits. It states what computation is performed but doesn't disclose format requirements, error conditions, memory/performance characteristics, or what happens with missing/invalid data. The description doesn't contradict annotations (none exist), but provides inadequate behavioral context for a computational tool.

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 phrase that communicates the core computation. There's no wasted verbiage or redundancy. However, it could be slightly more complete by mentioning the input type or output format to be fully self-contained.

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?

For a computational tool with no annotations, no output schema, and siblings performing similar operations, the description is insufficient. It doesn't explain what the tool returns (vector of row means? modified dataset?), data format expectations, or how it differs from similar tools. The agent would need to infer too much from the name and minimal description.

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

Parameters3/5

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

Schema description coverage is 100% (the single parameter 'input_data_file_path' is fully described in the schema). The description adds no parameter-specific information beyond what the schema provides. With high schema coverage and only one parameter, the baseline score of 3 is appropriate - the description doesn't need to compensate but adds no extra value.

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 'Mean values across columns for each row' clearly states the mathematical operation (mean) and the direction of computation (across columns for each row). It distinguishes from siblings like 'data_mean' (likely overall mean) and 'data_max_horizontal' (different operation). However, it doesn't specify the resource/input type (data file) or output format.

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 about when to use this tool versus alternatives like 'data_mean' (likely overall mean), 'data_median' (different central tendency), or other horizontal operations like 'data_max_horizontal'. The description implies row-wise computation but doesn't explicitly contrast with column-wise or overall alternatives.

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

Related 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/shibuiwilliam/mcp-server-data-wrangler'

If you have feedback or need assistance with the MCP directory API, please join our Discord server