data_mean
Calculate mean values for each column in a dataset using the input data file path. Simplify data analysis and preprocessing within the MCP Data Wrangler server for accurate descriptive statistics.
Instructions
Mean values for each column
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input_data_file_path | No | Path to the input data file |
Implementation Reference
- The handler function that implements the core logic of the 'data_mean' tool: loads data from file, computes column means using Polars DataFrame.mean(), formats as JSON, and returns as TextContent.
async def handle_data_mean( arguments: dict[str, Any], ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]: data_mean_input = DataMeanInputSchema.from_args(arguments) mean_df = data_mean_input.df.mean() # Convert the DataFrame to a dictionary format mean_dict = { "description": "Mean values for each column", "mean_values": { col: str(val) if val is not None else None for col, val in zip(mean_df.columns, mean_df.row(0)) }, } return [ types.TextContent( type="text", text=json.dumps(mean_dict), ) ] - Pydantic model subclassing Data for input validation of 'data_mean' tool. Provides inputSchema() for MCP Tool registration, and factory methods to load DataFrame from file path argument.
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) - src/mcp_server_data_wrangler/tools/tools.py:112-116 (registration)MCP Tool registration for 'data_mean': specifies name 'data_mean', description 'Mean values for each column', and references input schema from DataMeanInputSchema.input_schema().
types.Tool( name=MCPServerDataWrangler.data_mean.value[0], description=MCPServerDataWrangler.data_mean.value[1], inputSchema=DataMeanInputSchema.input_schema(), ), - src/mcp_server_data_wrangler/tools/tools.py:161-162 (registration)Handler mapping registration: associates tool name 'data_mean' with handle_data_mean function.
MCPServerDataWrangler.data_mean.value[0]: handle_data_mean, MCPServerDataWrangler.data_mean_horizontal.value[0]: handle_data_mean_horizontal, - Enum definition providing the canonical name and description for the 'data_mean' tool.
data_mean = ("data_mean", "Mean values for each column")