Skip to main content
Glama
apetta

Vibe Math MCP

by apetta

array_transform

Transform arrays for machine learning preprocessing and data normalization using L2 normalization, standardization, min-max scaling, or log transformation.

Instructions

Transform arrays for ML preprocessing and data normalization.

Transformations: - normalize: L2 normalization (unit vector) - standardize: Z-score (mean=0, std=1) - minmax_scale: Scale to [0,1] range - log_transform: Natural log transform

Examples:

L2 NORMALIZATION: data=[[3,4]], transform="normalize" Result: [[0.6,0.8]] (3²+4²=25, √25=5, 3/5=0.6, 4/5=0.8)

STANDARDIZATION (Z-SCORE): data=[[1,2],[3,4]], transform="standardize" Result: Values with mean=0, std=1

MIN-MAX SCALING: data=[[1,2],[3,4]], transform="minmax_scale" Result: [[0,0.33],[0.67,1]] (scaled to [0,1])

LOG TRANSFORM: data=[[1,10,100]], transform="log_transform" Result: [[0,2.3,4.6]] (natural log)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contextNoOptional annotation to label this calculation (e.g., 'Bond A PV', 'Q2 revenue'). Appears in results for easy identification.
output_modeNoOutput format: full (default), compact, minimal, value, or final. See batch_execute tool for details.full
dataYes2D array to transform (e.g., [[1,2],[3,4]])
transformYesTransformation type
axisNoAxis: 0=column-wise, 1=row-wise, None=overall

Implementation Reference

  • Registration of the array_transform tool with MCP server, including name, detailed description, examples, and annotations.
    @mcp.tool(
        name="array_transform",
        description="""Transform arrays for ML preprocessing and data normalization.
    
    Transformations:
        - normalize: L2 normalization (unit vector)
        - standardize: Z-score (mean=0, std=1)
        - minmax_scale: Scale to [0,1] range
        - log_transform: Natural log transform
    
    Examples:
    
    L2 NORMALIZATION:
        data=[[3,4]], transform="normalize"
        Result: [[0.6,0.8]] (3²+4²=25, √25=5, 3/5=0.6, 4/5=0.8)
    
    STANDARDIZATION (Z-SCORE):
        data=[[1,2],[3,4]], transform="standardize"
        Result: Values with mean=0, std=1
    
    MIN-MAX SCALING:
        data=[[1,2],[3,4]], transform="minmax_scale"
        Result: [[0,0.33],[0.67,1]] (scaled to [0,1])
    
    LOG TRANSFORM:
        data=[[1,10,100]], transform="log_transform"
        Result: [[0,2.3,4.6]] (natural log)""",
        annotations=ToolAnnotations(
            title="Array Transformation",
            readOnlyHint=True,
            idempotentHint=True,
        ),
    )
  • The handler function for array_transform. Converts input to NumPy array, applies the specified transformation along the given axis with edge case handling (zero division), formats and returns the result as JSON.
    async def array_transform(
        data: Annotated[
            List[List[float]], Field(description="2D array to transform (e.g., [[1,2],[3,4]])")
        ],
        transform: Annotated[
            Literal["normalize", "standardize", "minmax_scale", "log_transform"],
            Field(description="Transformation type"),
        ],
        axis: Annotated[
            int | None, Field(description="Axis: 0=column-wise, 1=row-wise, None=overall")
        ] = None,
    ) -> str:
        """Transform arrays."""
        try:
            arr = list_to_numpy(data)
    
            if transform == "normalize":
                # L2 normalization
                if axis is None:
                    norm = np.linalg.norm(arr)
                    result = (arr / norm if norm != 0 else arr).tolist()
                elif axis == 0:
                    norms = np.linalg.norm(arr, axis=0, keepdims=True)
                    result = (arr / np.where(norms != 0, norms, 1)).tolist()
                else:
                    norms = np.linalg.norm(arr, axis=1, keepdims=True)
                    result = (arr / np.where(norms != 0, norms, 1)).tolist()
    
            elif transform == "standardize":
                # Z-score standardization
                if axis is None:
                    mean = np.mean(arr)
                    std = np.std(arr, ddof=1)
                    result = ((arr - mean) / std if std != 0 else arr - mean).tolist()
                elif axis == 0:
                    mean = np.mean(arr, axis=0, keepdims=True)
                    std = np.std(arr, axis=0, ddof=1, keepdims=True)
                    result = ((arr - mean) / np.where(std != 0, std, 1)).tolist()
                else:
                    mean = np.mean(arr, axis=1, keepdims=True)
                    std = np.std(arr, axis=1, ddof=1, keepdims=True)
                    result = ((arr - mean) / np.where(std != 0, std, 1)).tolist()
    
            elif transform == "minmax_scale":
                # Min-Max scaling to [0, 1]
                if axis is None:
                    min_val = np.min(arr)
                    max_val = np.max(arr)
                    range_val = max_val - min_val
                    result = ((arr - min_val) / range_val if range_val != 0 else arr - min_val).tolist()
                elif axis == 0:
                    min_val = np.min(arr, axis=0, keepdims=True)
                    max_val = np.max(arr, axis=0, keepdims=True)
                    range_val = max_val - min_val
                    result = ((arr - min_val) / np.where(range_val != 0, range_val, 1)).tolist()
                else:
                    min_val = np.min(arr, axis=1, keepdims=True)
                    max_val = np.max(arr, axis=1, keepdims=True)
                    range_val = max_val - min_val
                    result = ((arr - min_val) / np.where(range_val != 0, range_val, 1)).tolist()
    
            elif transform == "log_transform":
                # Natural log transform (handles negatives by using log1p)
                result = np.log1p(np.abs(arr) * np.sign(arr)).tolist()
    
            else:
                raise ValueError(f"Unknown transform: {transform}")
    
            return format_array_result(result, {"transform": transform, "axis": axis})
        except Exception as e:
            raise ValueError(f"Transformation failed: {str(e)}")

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/apetta/vibe-math-mcp'

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