Skip to main content
Glama

convert_data

Transform data files between formats like CSV, JSON, and XLSX using pandas for analysis and processing in VisiData workflows.

Instructions

Convert data from one format to another using pandas.

Args: input_path: Path to the input data file output_path: Path for the output file output_format: Target format (csv, json, xlsx, etc.)

Returns: Success message or error details

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
input_pathYes
output_pathYes
output_formatNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The convert_data tool handler implementation. This function converts data from one format to another using pandas, supporting CSV, JSON, Excel, and TSV formats. It loads data from the input file, determines the output format from the file extension or explicit parameter, and saves the data in the target format. Returns a JSON result with conversion details including row and column counts.
    @mcp.tool()
    def convert_data(input_path: str, output_path: str, output_format: Optional[str] = None) -> str:
        """
        Convert data from one format to another using pandas.
        
        Args:
            input_path: Path to the input data file
            output_path: Path for the output file
            output_format: Target format (csv, json, xlsx, etc.)
        
        Returns:
            Success message or error details
        """
        try:
            import pandas as pd
            from pathlib import Path
            
            # Load data with pandas
            input_extension = Path(input_path).suffix.lower()
            
            if input_extension == '.csv':
                df = pd.read_csv(input_path)
            elif input_extension == '.json':
                df = pd.read_json(input_path)
            elif input_extension in ['.xlsx', '.xls']:
                df = pd.read_excel(input_path)
            elif input_extension == '.tsv':
                df = pd.read_csv(input_path, sep='\t')
            else:
                df = pd.read_csv(input_path)
            
            # Determine output format from extension if not specified
            if output_format is None:
                output_format = Path(output_path).suffix.lstrip('.')
            
            # Save in the new format
            if output_format == 'csv':
                df.to_csv(output_path, index=False)
            elif output_format == 'json':
                df.to_json(output_path, orient='records', indent=2)
            elif output_format in ['xlsx', 'xls']:
                df.to_excel(output_path, index=False)
            elif output_format == 'tsv':
                df.to_csv(output_path, sep='\t', index=False)
            else:
                # Default to CSV
                df.to_csv(output_path, index=False)
                output_format = 'csv'
            
            result = {
                "input_file": input_path,
                "output_file": output_path,
                "output_format": output_format,
                "rows_converted": len(df),
                "columns_converted": len(df.columns)
            }
            
            return json.dumps(result, indent=2)
            
        except Exception as e:
            return f"Error converting data: {str(e)}\n{traceback.format_exc()}"
  • The convert_data tool is registered as an MCP tool using the @mcp.tool() decorator at line 260.
    @mcp.tool()
  • Import statement showing convert_data is imported from visidata_mcp.server module in the demo script.
    convert_data,
  • Example usage of convert_data in the demo script, showing how it converts CSV data to JSON format.
    print("6. Converting to JSON...")
    json_output = Path(__file__).parent / "sample_data.json"
    result = convert_data(str(sample_file), str(json_output))
    print(f"Conversion result: {result}")
    print()
Behavior2/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 mentions the tool uses pandas and describes basic input/output paths, but lacks critical behavioral details: it doesn't specify what formats are supported (beyond vague examples), whether the conversion is destructive to the original file, error handling behavior, or performance characteristics. The description is too minimal for a tool that performs file operations.

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 appropriately sized and well-structured with clear sections (purpose, Args, Returns). Each sentence serves a purpose, though the 'Returns' section could be more specific. The front-loaded purpose statement is clear, and there's no unnecessary verbiage, making it efficient for an agent to parse.

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 complexity (file format conversion with 3 parameters), no annotations, and an output schema present (which handles return values), the description is moderately complete. It covers the basic purpose and parameters but lacks important context: supported format details, error conditions, pandas dependency requirements, and how it differs from sibling data tools. The output schema reduces the need to explain returns, but other gaps remain significant.

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?

The description provides parameter information in the Args section, listing all three parameters with brief explanations. However, with 0% schema description coverage, the description doesn't fully compensate: it doesn't explain parameter constraints (e.g., what file paths are valid, what specific formats are supported beyond 'csv, json, xlsx, etc.'), or that output_format is optional with a default of null. The parameter explanations are present but insufficient given the complete lack of schema documentation.

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: 'Convert data from one format to another using pandas.' This specifies the verb (convert), resource (data), and implementation method (pandas). However, it doesn't explicitly differentiate from sibling tools like 'load_data' or 'filter_data' that might also handle data files, so it doesn't reach the highest level of sibling differentiation.

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. There's no mention of prerequisites (e.g., needing pandas installed), when not to use it (e.g., for non-file data), or comparison to sibling tools like 'get_supported_formats' that might help determine compatible formats. The only implicit usage context is format conversion, but no explicit alternatives are named.

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