load_csv_from_content
Load CSV data directly from string content to process and manipulate tabular information within the CSV Editor MCP server.
Instructions
Load CSV data from string content.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | ||
| delimiter | No | , | |
| session_id | No | ||
| has_header | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- Core handler function that implements the tool logic: parses CSV content from string using pandas.read_csv with StringIO, loads DataFrame into a session, and returns detailed OperationResult.
async def load_csv_from_content( content: str, delimiter: str = ",", session_id: Optional[str] = None, has_header: bool = True, ctx: Context = None ) -> Dict[str, Any]: """Load CSV data from a string content. Args: content: CSV content as string delimiter: Column delimiter session_id: Optional existing session ID has_header: Whether first row is header ctx: FastMCP context Returns: Operation result with session ID and data info """ try: if ctx: await ctx.info("Loading CSV from content string") # Parse CSV from string from io import StringIO df = pd.read_csv( StringIO(content), delimiter=delimiter, header=0 if has_header else None ) # Get or create session session_manager = get_session_manager() session = session_manager.get_or_create_session(session_id) session.load_data(df, None) if ctx: await ctx.info(f"Loaded {len(df)} rows and {len(df.columns)} columns") return OperationResult( success=True, message=f"Successfully loaded CSV from content", session_id=session.session_id, rows_affected=len(df), columns_affected=df.columns.tolist(), data={ "shape": df.shape, "preview": df.head(5).to_dict('records') } ).model_dump() except Exception as e: if ctx: await ctx.error(f"Failed to parse CSV content: {str(e)}") return OperationResult( success=False, message="Failed to parse CSV content", error=str(e) ).model_dump() - src/csv_editor/server.py:133-142 (registration)MCP tool registration using @mcp.tool decorator. Thin wrapper that imports and delegates to the core implementation in io_operations.py.
@mcp.tool async def load_csv_from_content( content: str, delimiter: str = ",", session_id: Optional[str] = None, has_header: bool = True, ctx: Context = None ) -> Dict[str, Any]: """Load CSV data from string content.""" return await _load_csv_from_content(content, delimiter, session_id, has_header, ctx) - src/csv_editor/server.py:98-106 (registration)Import of the core load_csv_from_content function (aliased as _load_csv_from_content) used by the registered tool wrapper.
from .tools.io_operations import ( load_csv as _load_csv, load_csv_from_url as _load_csv_from_url, load_csv_from_content as _load_csv_from_content, export_csv as _export_csv, get_session_info as _get_session_info, list_sessions as _list_sessions, close_session as _close_session )