Skip to main content
Glama

read_csv

Extract data from CSV files by specifying a filename and optional row limit, returning structured content with metadata for analysis or processing.

Instructions

Read and return CSV file contents. Args: filename: Name of the CSV file to read limit: Optional limit on number of rows to return Returns: Dictionary with file contents and metadata

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
limitNo

Implementation Reference

  • MCP tool handler for 'read_csv'. Decorated with @mcp.tool(), defines input parameters (filename, optional limit) and delegates to CSVManager.read_csv, handling exceptions.
    @mcp.tool() def read_csv(filename: str, limit: Optional[int] = None) -> Dict[str, Any]: """ Read and return CSV file contents. Args: filename: Name of the CSV file to read limit: Optional limit on number of rows to return Returns: Dictionary with file contents and metadata """ try: return csv_manager.read_csv(filename, limit) except Exception as e: return {"success": False, "error": str(e)}
  • Core implementation in CSVManager class: resolves file path, loads CSV with pandas.read_csv, applies row limit if specified, converts to dict records, returns structured response with metadata.
    def read_csv(self, filename: str, limit: Optional[int] = None) -> Dict[str, Any]: """Read CSV file contents.""" filepath = self._get_file_path(filename) if not filepath.exists(): raise FileNotFoundError(f"CSV file '{filename}' not found") try: df = pd.read_csv(filepath) # Apply limit if specified if limit and limit > 0: df = df.head(limit) return { "success": True, "filename": filename, "data": df.to_dict('records'), "columns": list(df.columns), "total_rows": len(df), "shape": df.shape } except Exception as e: logger.error(f"Failed to read CSV: {e}") raise
  • The @mcp.tool() decorator registers this function as the 'read_csv' tool in the FastMCP server.
    @mcp.tool() def read_csv(filename: str, limit: Optional[int] = None) -> Dict[str, Any]: """ Read and return CSV file contents. Args: filename: Name of the CSV file to read limit: Optional limit on number of rows to return Returns: Dictionary with file contents and metadata """ try: return csv_manager.read_csv(filename, limit) except Exception as e: return {"success": False, "error": str(e)}

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/NovaAI-innovation/csv-mcp-server'

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