Skip to main content
Glama

get_data_sample

Extract a data sample from files to preview content and structure. Specify file path and row count to retrieve JSON-formatted sample data for analysis.

Instructions

Get a sample of data from a file.

Args: file_path: Path to the data file rows: Number of rows to return (default: 10)

Returns: Sample data in JSON format

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
rowsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Main implementation of get_data_sample tool that loads data using pandas and returns a sample of N rows in JSON format. Handles multiple file types (CSV, JSON, Excel, TSV) and properly converts numpy/pandas types for JSON serialization.
    @mcp.tool()
    def get_data_sample(file_path: str, rows: int = 10) -> str:
        """
        Get a sample of data from a file.
        
        Args:
            file_path: Path to the data file
            rows: Number of rows to return (default: 10)
        
        Returns:
            Sample data in JSON format
        """
        try:
            import pandas as pd
            from pathlib import Path
            
            file_extension = Path(file_path).suffix.lower()
            
            # Load with pandas
            if file_extension == '.csv':
                df = pd.read_csv(file_path)
            elif file_extension == '.json':
                df = pd.read_json(file_path)
            elif file_extension in ['.xlsx', '.xls']:
                df = pd.read_excel(file_path)
            elif file_extension == '.tsv':
                df = pd.read_csv(file_path, sep='\t')
            else:
                df = pd.read_csv(file_path)
            
            # Get sample rows
            sample_df = df.head(rows)
            
            # Convert to records for JSON serialization
            sample_data = []
            for _, row in sample_df.iterrows():
                row_data = {}
                for col in df.columns:
                    value = row[col]
                    # Handle pandas/numpy types for JSON serialization
                    if pd.isna(value):
                        row_data[col] = None
                    elif hasattr(value, 'item'):  # numpy types
                        row_data[col] = value.item()
                    else:
                        row_data[col] = str(value) if value is not None else None
                sample_data.append(row_data)
            
            result = {
                "filename": Path(file_path).name,
                "total_rows": len(df),
                "total_columns": len(df.columns),
                "sample_rows": len(sample_data),
                "columns": list(df.columns),
                "data": sample_data
            }
            
            return json.dumps(result, indent=2)
            
        except Exception as e:
            return f"Error getting data sample: {str(e)}\n{traceback.format_exc()}"
  • Tool registration via the @mcp.tool() decorator, which registers get_data_sample as an MCP tool in the FastMCP server instance.
    @mcp.tool()
  • Function signature and docstring defining the input/output schema: takes file_path (str) and optional rows (int=10), returns JSON string with sample data including filename, row/column counts, and actual data rows.
    def get_data_sample(file_path: str, rows: int = 10) -> str:
        """
        Get a sample of data from a file.
        
        Args:
            file_path: Path to the data file
            rows: Number of rows to return (default: 10)
        
        Returns:
            Sample data in JSON format
        """
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the return format ('JSON format') but lacks details on permissions, file format support, error handling, or whether the operation is read-only or has side effects. For a tool with no annotations, this leaves significant gaps in understanding its behavior.

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 front-loaded with the core purpose in the first sentence, followed by a structured breakdown of args and returns. Every sentence adds value without redundancy, making it efficient and easy to parse for an AI agent.

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

Completeness3/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, no annotations, but has an output schema), the description is minimally adequate. It covers the basic purpose and parameters but lacks usage context and behavioral details. The output schema likely handles return values, so the description's mention of 'JSON format' is sufficient but not comprehensive.

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

Parameters4/5

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

Schema description coverage is 0%, so the description must compensate. It adds meaningful context: 'file_path: Path to the data file' clarifies the parameter's purpose, and 'rows: Number of rows to return (default: 10)' explains the default behavior. This goes beyond the schema's basic titles, though it doesn't cover constraints like valid file paths or row limits.

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's purpose: 'Get a sample of data from a file.' It specifies the verb ('Get') and resource ('data from a file'), making the action explicit. However, it doesn't differentiate from siblings like 'load_data' or 'filter_data' that might also involve data retrieval, which prevents a perfect score.

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. With siblings such as 'load_data' (likely for full loading) and 'filter_data' (likely for filtering), there's no indication of scenarios where sampling is preferred over these other operations, leaving the agent without context for selection.

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/moeloubani/visidata-mcp'

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