Skip to main content
Glama
K02D

MCP Tabular Data Analysis Server

by K02D

merge_datasets

Combine two datasets by joining them on specified columns to create a unified data source for analysis.

Instructions

Merge/join two datasets together - essential for combining data sources.

Args:
    file_path_left: Path to left/primary dataset
    file_path_right: Path to right/secondary dataset
    on: Column(s) to join on (if same name in both datasets)
    left_on: Column name in left dataset to join on
    right_on: Column name in right dataset to join on
    how: Join type - 'inner', 'left', 'right', 'outer'
    preview_limit: Number of rows to return in preview

Returns:
    Dictionary containing merged data preview and statistics

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_path_leftYes
file_path_rightYes
onNo
left_onNo
right_onNo
howNoinner
preview_limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the 'merge_datasets' tool. It is registered via the @mcp.tool() decorator. Loads two datasets using _load_data helper, performs a pandas merge based on specified keys and join type, computes merge statistics, and returns a preview of the merged data with metadata.
    @mcp.tool()
    def merge_datasets(
        file_path_left: str,
        file_path_right: str,
        on: list[str] | None = None,
        left_on: str | None = None,
        right_on: str | None = None,
        how: str = "inner",
        preview_limit: int = 50,
    ) -> dict[str, Any]:
        """
        Merge/join two datasets together - essential for combining data sources.
        
        Args:
            file_path_left: Path to left/primary dataset
            file_path_right: Path to right/secondary dataset
            on: Column(s) to join on (if same name in both datasets)
            left_on: Column name in left dataset to join on
            right_on: Column name in right dataset to join on
            how: Join type - 'inner', 'left', 'right', 'outer'
            preview_limit: Number of rows to return in preview
        
        Returns:
            Dictionary containing merged data preview and statistics
        """
        df_left = _load_data(file_path_left)
        df_right = _load_data(file_path_right)
        
        valid_how = ['inner', 'left', 'right', 'outer']
        if how not in valid_how:
            raise ValueError(f"Unknown join type: {how}. Use: {valid_how}")
        
        # Determine join keys
        if on:
            invalid_left = [c for c in on if c not in df_left.columns]
            invalid_right = [c for c in on if c not in df_right.columns]
            if invalid_left:
                raise ValueError(f"Columns {invalid_left} not found in left dataset")
            if invalid_right:
                raise ValueError(f"Columns {invalid_right} not found in right dataset")
            merged = pd.merge(df_left, df_right, on=on, how=how)
        elif left_on and right_on:
            if left_on not in df_left.columns:
                raise ValueError(f"Column '{left_on}' not found in left dataset")
            if right_on not in df_right.columns:
                raise ValueError(f"Column '{right_on}' not found in right dataset")
            merged = pd.merge(df_left, df_right, left_on=left_on, right_on=right_on, how=how)
        else:
            # Try to find common columns
            common_cols = list(set(df_left.columns) & set(df_right.columns))
            if not common_cols:
                raise ValueError("No common columns found. Specify 'on', or 'left_on' and 'right_on'")
            on = common_cols[:1]  # Use first common column
            merged = pd.merge(df_left, df_right, on=on, how=how)
        
        # Statistics about the merge
        left_rows = len(df_left)
        right_rows = len(df_right)
        merged_rows = len(merged)
        
        merge_stats = {
            "left_rows": left_rows,
            "right_rows": right_rows,
            "merged_rows": merged_rows,
            "join_type": how,
            "join_keys": on if on else {"left": left_on, "right": right_on},
        }
        
        if how == "inner":
            merge_stats["left_match_pct"] = round(merged_rows / left_rows * 100, 1) if left_rows > 0 else 0
            merge_stats["right_match_pct"] = round(merged_rows / right_rows * 100, 1) if right_rows > 0 else 0
        
        return {
            "merge_stats": merge_stats,
            "merged_columns": merged.columns.tolist(),
            "merged_shape": {"rows": merged_rows, "columns": len(merged.columns)},
            "preview": merged.head(preview_limit).to_dict(orient="records"),
            "has_more": merged_rows > preview_limit,
        }
Behavior3/5

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

With no annotations provided, the description carries full burden. It reveals this is a data transformation operation that returns a preview with statistics, which is useful behavioral context. However, it doesn't disclose important traits like whether this creates persistent data, has performance implications, handles missing data, or has any limitations on dataset size or format.

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 well-structured with clear sections for purpose, arguments, and returns. The opening sentence states the core function, followed by organized parameter explanations. While efficient, the 'essential for combining data sources' phrase adds little value and could be omitted for better conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (7 parameters, data transformation operation) and no annotations, the description does well by explaining all parameters and the return format. The presence of an output schema means the description doesn't need to detail return values. However, for a data transformation tool, it could better address behavioral aspects like data persistence and limitations.

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

Parameters5/5

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

With 0% schema description coverage, the description fully compensates by explaining all 7 parameters in detail. It clarifies the purpose of each parameter, distinguishes between 'on' vs 'left_on/right_on' approaches, explains the join types for 'how', and specifies that 'preview_limit' controls returned rows. This adds substantial meaning beyond the bare schema.

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 clearly states the tool merges/joins two datasets together and is essential for combining data sources. It specifies the verb (merge/join) and resource (datasets), but doesn't explicitly differentiate from sibling tools like 'group_aggregate' or 'create_pivot_table' which might also combine data in different ways.

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 doesn't mention sibling tools or clarify scenarios where merge_datasets is preferred over other data manipulation tools like 'group_aggregate' or 'create_pivot_table'. The 'essential for combining data sources' phrase is too generic to provide meaningful usage context.

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/K02D/mcp-tabular'

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