Skip to main content
Glama
tofunori

Claude MCP Data Explorer

by tofunori

load-csv

Load CSV files into structured DataFrames for data analysis and exploration within Claude's environment.

Instructions

Load a CSV file into a DataFrame for analysis

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
csv_pathYesPath to the CSV file to load
df_nameNoName for the DataFrame (optional, defaults to df_1, df_2, etc.)

Implementation Reference

  • Primary handler for 'load-csv' tool in Python implementation. Loads CSV using pandas, supports chunking for large files, stores DataFrame globally, and provides summary statistics.
    async def handle_load_csv(arguments):
        """Handle the load-csv tool"""
        global _df_counter
        
        csv_path = arguments.get("csv_path")
        df_name = arguments.get("df_name")
        
        if not csv_path:
            return [TextContent(type="text", text="Error: csv_path is required")]
        
        # Normalize path for Windows
        csv_path = os.path.normpath(csv_path)
        
        # Generate a default name if none provided
        if not df_name:
            df_name = f"df_{_df_counter}"
            _df_counter += 1
        
        try:
            # Get file size
            file_size_mb = os.path.getsize(csv_path) / (1024 * 1024)
            logging.info(f"Loading CSV file: {csv_path} ({file_size_mb:.2f} MB)")
            
            # Use chunking for large files
            if file_size_mb > 100:
                return await _load_large_csv(csv_path, df_name)
            else:
                return await _load_small_csv(csv_path, df_name)
        
        except FileNotFoundError:
            return [TextContent(
                type="text", 
                text=f"Error: File not found: {csv_path}"
            )]
        except Exception as e:
            error_message = f"Error loading CSV: {str(e)}\n{traceback.format_exc()}"
            logging.error(error_message)
            return [TextContent(
                type="text", 
                text=f"Error loading CSV: {str(e)}"
            )]
  • Primary handler for 'load-csv' tool in TypeScript implementation. Parses CSV using PapaParse, stores data globally, generates summary using simple-statistics library.
    export async function loadCsv(args: LoadCsvArgs): Promise<{ type: string, text: string }[]> {
      const { csv_path, df_name } = args;
      
      if (!csv_path) {
        return [{ type: 'text', text: 'Error: csv_path is required' }];
      }
      
      // Normalize path for Windows
      const normalizedPath = path.normalize(csv_path);
      
      // Generate a default name if none provided
      const dataFrameName = df_name || `df_${dfCounter++}`;
      
      try {
        // Check if file exists
        if (!fs.existsSync(normalizedPath)) {
          return [{ type: 'text', text: `Error: File not found: ${normalizedPath}` }];
        }
        
        // Get file size
        const stats = fs.statSync(normalizedPath);
        const fileSizeMb = stats.size / (1024 * 1024);
        
        // Read file content
        const fileContent = fs.readFileSync(normalizedPath, 'utf8');
        
        // Parse CSV
        const parseResult = Papa.parse(fileContent, {
          header: true,
          dynamicTyping: true,
          skipEmptyLines: true
        });
        
        if (parseResult.errors && parseResult.errors.length > 0) {
          return [{ type: 'text', text: `Error parsing CSV: ${parseResult.errors[0].message}` }];
        }
        
        const data = parseResult.data as any[];
        
        // Store in global storage
        dataFrames[dataFrameName] = data;
        
        // Generate summary
        const summary = generateSummary(data, parseResult.meta.fields || []);
        
        return [{ 
          type: 'text', 
          text: `Successfully loaded ${normalizedPath} as ${dataFrameName} (${data.length} rows × ${parseResult.meta.fields?.length || 0} columns)\n\n${summary}` 
        }];
        
      } catch (error: any) {
        return [{ type: 'text', text: `Error loading CSV: ${error.message}` }];
      }
    }
  • Registration of the 'load-csv' tool including schema in the Python MCP server's list_tools handler.
    types.Tool(
        name="load-csv",
        description="Load a CSV file into a DataFrame for analysis",
        inputSchema={
            "type": "object",
            "properties": {
                "csv_path": {
                    "type": "string",
                    "description": "Path to the CSV file to load"
                },
                "df_name": {
                    "type": "string",
                    "description": "Name for the DataFrame (optional, defaults to df_1, df_2, etc.)"
                }
            },
            "required": ["csv_path"]
        }
    ),
  • src/index.ts:56-71 (registration)
    Registration of the 'load-csv' tool including schema in the TypeScript MCP server's listTools handler.
    name: "load-csv",
    description: "Load a CSV file into a DataFrame for analysis",
    inputSchema: {
      type: "object",
      properties: {
        csv_path: {
          type: "string",
          description: "Path to the CSV file to load"
        },
        df_name: {
          type: "string",
          description: "Name for the DataFrame (optional, defaults to df_1, df_2, etc.)"
        }
      },
      required: ["csv_path"]
    }
  • Tool dispatch handler in Python server that routes 'load-csv' calls to the data_loader handler.
    async def handle_call_tool(
        name: str,
        arguments: dict | None
    ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        """Handle tool execution"""
        try:
            if name == "load-csv":
                return await handle_load_csv(arguments)
            elif name == "run-script":
                return await handle_run_script(arguments)
            else:
                raise ValueError(f"Unknown tool: {name}")
        except Exception as e:
            error_message = f"Error executing tool {name}: {str(e)}\n{traceback.format_exc()}"
            logging.error(error_message)
            return [
                types.TextContent(
                    type="text",
                    text=f"Error: {str(e)}"
                )
            ]
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 states the action 'load a CSV file into a DataFrame' but lacks details on permissions needed, error handling (e.g., invalid paths), rate limits, or what happens after loading (e.g., memory usage, persistence). For a tool with no annotation coverage, this is a significant gap.

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 a single, efficient sentence that front-loads the core action ('Load a CSV file') and purpose ('for analysis'). There is zero waste, making it highly concise and well-structured for quick understanding.

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

Completeness2/5

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

Given no annotations, no output schema, and a tool that performs data loading (a potentially complex operation with file I/O), the description is incomplete. It doesn't cover behavioral aspects like error conditions, return values, or dependencies, leaving gaps for an AI agent to use it correctly in varied contexts.

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 documents both parameters (csv_path and df_name) with clear descriptions. The description adds no additional meaning beyond implying CSV loading for analysis, which aligns with the schema but doesn't provide extra syntax or format details. 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.

Purpose4/5

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

The description clearly states the verb 'load' and resource 'CSV file', specifying it's for analysis via a DataFrame. It distinguishes from the sibling 'run-script' by focusing on data loading rather than script execution. However, it doesn't explicitly differentiate from potential other data loading tools (none listed), keeping it at 4.

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?

No guidance is provided on when to use this tool versus alternatives. The description implies it's for loading CSV files into DataFrames, but there's no mention of prerequisites (e.g., file accessibility), when not to use it (e.g., for non-CSV files), or alternatives like 'run-script' for other data processing. This leaves usage context vague.

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/tofunori/claude-mcp-data-explorer'

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