csv_to_excel
Convert raw CSV text to a styled Excel workbook with auto-filters, frozen header, and auto-column sizing. Customize delimiter and sheet name.
Instructions
Convert CSV content into a styled Excel workbook.
Auto-formats with header styling, auto-filter, frozen header row, and auto-sized columns.
Args: csv_content: Raw CSV text content. delimiter: CSV delimiter (default: comma). has_header: Whether the first row is a header (default: true). sheet_name: Name for the sheet tab (default: "Data").
Returns: Base64-encoded XLSX file.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| csv_content | Yes | ||
| delimiter | No | , | |
| has_header | No | ||
| sheet_name | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- mcp/src/docgen_mcp/server.py:665-687 (handler)The csv_to_excel tool handler: accepts CSV content, delimiter, has_header flag, and optional sheet_name. It uses the DocGen client's excel.from_csv method to convert CSV to XLSX, then returns Base64-encoded XLSX.
@mcp.tool() def csv_to_excel( csv_content: str, delimiter: str = ",", has_header: bool = True, sheet_name: str | None = None, ) -> str: """Convert CSV content into a styled Excel workbook. Auto-formats with header styling, auto-filter, frozen header row, and auto-sized columns. Args: csv_content: Raw CSV text content. delimiter: CSV delimiter (default: comma). has_header: Whether the first row is a header (default: true). sheet_name: Name for the sheet tab (default: "Data"). Returns: Base64-encoded XLSX file. """ dg = _get_client() xlsx = dg.excel.from_csv(csv_content, delimiter=delimiter, has_header=has_header, sheet_name=sheet_name) return base64.b64encode(xlsx).decode() - mcp/src/docgen_mcp/server.py:665-666 (registration)The tool is registered via the @mcp.tool() decorator on the csv_to_excel function, which registers it with the FastMCP instance.
@mcp.tool() def csv_to_excel( - mcp/src/docgen_mcp/server.py:28-47 (helper)The _get_client() helper lazy-initializes the DocGen client used by csv_to_excel to call dg.excel.from_csv().
def _get_client(): """Lazy-initialise the DocGen client.""" global _client if _client is None: # Import here so the module can be imported without the SDK installed # (useful for schema introspection) from docgen import DocGen api_key = os.environ.get("DOCGEN_API_KEY", "") if not api_key: raise RuntimeError( "DOCGEN_API_KEY environment variable is required. " "Set it to your DocGen API key before starting the server." ) base_url = os.environ.get("DOCGEN_BASE_URL") kwargs: dict[str, Any] = {"api_key": api_key} if base_url: kwargs["base_url"] = base_url _client = DocGen(**kwargs) return _client