Skip to main content
Glama
Fervoyush

Plotnine MCP Server

by Fervoyush

preview_data

Preview and inspect data structure before plotting to verify loading and understand column types, statistics, and missing values.

Instructions

Preview and inspect data before creating plots.

Returns a comprehensive summary including:

  • Dataset shape (rows and columns)

  • Column names and data types

  • First few rows of data

  • Basic statistics for numeric columns

  • Missing value counts

This helps verify data loaded correctly and understand its structure.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
data_sourceYesData source configuration (file, URL, or inline data)
rowsNoNumber of rows to preview (default: 5)

Implementation Reference

  • The main handler function for the 'preview_data' tool. Loads data from the provided data_source, generates a comprehensive preview including dataset shape, column types, sample rows, numeric statistics, and missing value summary, then returns it as TextContent.
    async def preview_data_handler(arguments: dict[str, Any]) -> list[TextContent]:
        """Handle preview_data tool calls."""
        try:
            # Parse data source
            data_source = DataSource(**arguments["data_source"])
            rows = arguments.get("rows", 5)
    
            # Load data
            try:
                data = load_data(data_source)
            except DataLoadError as e:
                return [
                    TextContent(
                        type="text",
                        text=f"Data loading error: {str(e)}\n\nPlease check:\n- File path or URL is correct\n- File format is supported\n- Data is properly formatted",
                    )
                ]
    
            # Build preview message
            message = "Data Preview\n" + "=" * 50 + "\n\n"
    
            # Dataset shape
            message += f"Shape: {data.shape[0]} rows × {data.shape[1]} columns\n\n"
    
            # Column information
            message += "Columns:\n"
            for col in data.columns:
                dtype = str(data[col].dtype)
                message += f"  - {col} ({dtype})\n"
            message += "\n"
    
            # First N rows
            message += f"First {min(rows, len(data))} rows:\n"
            message += "-" * 50 + "\n"
            preview_df = data.head(rows)
            message += preview_df.to_string(index=False) + "\n\n"
    
            # Basic statistics for numeric columns
            numeric_cols = data.select_dtypes(include=['number']).columns
            if len(numeric_cols) > 0:
                message += "Numeric Column Statistics:\n"
                message += "-" * 50 + "\n"
                stats_df = data[numeric_cols].describe()
                message += stats_df.to_string() + "\n\n"
    
            # Missing values
            missing = data.isnull().sum()
            if missing.sum() > 0:
                message += "Missing Values:\n"
                message += "-" * 50 + "\n"
                for col, count in missing[missing > 0].items():
                    pct = (count / len(data)) * 100
                    message += f"  - {col}: {count} ({pct:.1f}%)\n"
            else:
                message += "No missing values found.\n"
    
            return [TextContent(type="text", text=message)]
    
        except Exception as e:
            return [
                TextContent(
                    type="text",
                    text=f"Error previewing data: {str(e)}\n\nPlease check your data source configuration.",
                )
            ]
  • Input schema definition for the 'preview_data' tool, specifying data_source (file/url/inline with format) and optional rows parameter.
    inputSchema={
        "type": "object",
        "properties": {
            "data_source": {
                "type": "object",
                "description": "Data source configuration (file, URL, or inline data)",
                "properties": {
                    "type": {
                        "type": "string",
                        "enum": ["file", "url", "inline"],
                        "description": "Source type",
                    },
                    "path": {
                        "type": "string",
                        "description": "File path or URL (for file/url types)",
                    },
                    "data": {
                        "type": "array",
                        "items": {"type": "object"},
                        "description": "Inline data as array of objects (for inline type)",
                    },
                    "format": {
                        "type": "string",
                        "enum": ["csv", "json", "parquet", "excel"],
                        "description": "Data format (auto-detected if not specified)",
                    },
                },
                "required": ["type"],
            },
            "rows": {
                "type": "integer",
                "default": 5,
                "description": "Number of rows to preview (default: 5)",
            },
        },
        "required": ["data_source"],
    },
  • Registration of the 'preview_data' tool in the list_tools() function, including name, description, and schema.
            Tool(
                name="preview_data",
                description="""Preview and inspect data before creating plots.
    
    Returns a comprehensive summary including:
    - Dataset shape (rows and columns)
    - Column names and data types
    - First few rows of data
    - Basic statistics for numeric columns
    - Missing value counts
    
    This helps verify data loaded correctly and understand its structure.""",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "data_source": {
                            "type": "object",
                            "description": "Data source configuration (file, URL, or inline data)",
                            "properties": {
                                "type": {
                                    "type": "string",
                                    "enum": ["file", "url", "inline"],
                                    "description": "Source type",
                                },
                                "path": {
                                    "type": "string",
                                    "description": "File path or URL (for file/url types)",
                                },
                                "data": {
                                    "type": "array",
                                    "items": {"type": "object"},
                                    "description": "Inline data as array of objects (for inline type)",
                                },
                                "format": {
                                    "type": "string",
                                    "enum": ["csv", "json", "parquet", "excel"],
                                    "description": "Data format (auto-detected if not specified)",
                                },
                            },
                            "required": ["type"],
                        },
                        "rows": {
                            "type": "integer",
                            "default": 5,
                            "description": "Number of rows to preview (default: 5)",
                        },
                    },
                    "required": ["data_source"],
                },
            ),
  • Dispatch/registration logic in the call_tool handler that routes 'preview_data' calls to the preview_data_handler function.
    elif name == "preview_data":
        return await preview_data_handler(arguments)
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes what the tool returns (a comprehensive summary with specific components like dataset shape and statistics), which is valuable. However, it does not mention potential limitations, error conditions, performance characteristics, or authentication needs that might be relevant for a data inspection tool.

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 well-structured and front-loaded, starting with the core purpose, followed by a bulleted list of return details, and ending with the tool's utility. Every sentence earns its place by adding value without redundancy, making it efficient and easy to parse.

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 moderate complexity (2 parameters with nested objects, no output schema, and no annotations), the description is largely complete. It clearly explains the tool's purpose, usage context, and return format. However, without an output schema, it could benefit from more detail on the structure of the returned summary (e.g., format or keys), and it lacks information on error handling or data size limits.

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%, so the schema already fully documents both parameters (data_source and rows). The description does not add any parameter-specific semantics beyond what the schema provides, such as explaining how data_source configuration affects preview behavior or clarifying the rows parameter's impact. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('preview and inspect data') and resource ('data'), distinguishing it from sibling tools focused on plot creation, configuration, and listing. It explicitly positions this as a verification step 'before creating plots,' making its role distinct within the toolset.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool ('before creating plots' to 'verify data loaded correctly and understand its structure'), but does not explicitly state when not to use it or name alternatives among sibling tools. The guidance is helpful but lacks explicit exclusions or comparisons.

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/Fervoyush/plotnine-mcp'

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