Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
csv_contentYes
delimiterNo,
has_headerNo
sheet_nameNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • 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()
  • 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(
  • 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
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden. It discloses auto-formatting behavior (header styling, auto-filter, frozen row, auto-sized columns) and return type (Base64 XLSX). Missing edge cases like large CSV performance or encoding, but still solid.

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?

Concise: two introductory sentences then a bullet-like Args list. No wasted words, though defaults could be omitted since schema already has them. Still very efficient.

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

Completeness4/5

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

Given 4 parameters and an output schema, the description covers main conversion and formatting behavior. It specifies the return format (Base64 XLSX). Lacks error scenarios or size limits, but overall adequate for an agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must add meaning. It provides one-line explanations for all 4 parameters, including defaults and interpretation (e.g., 'Raw CSV text', 'CSV delimiter'). Does not elaborate on allowed delimiter characters or null handling, but adds significant value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

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

The description clearly states the verb 'Convert' and the resource 'CSV content' to 'styled Excel workbook', and lists auto-formatting features. It effectively distinguishes from sibling tools like excel_to_csv (reverse) and generate_excel (for custom data).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool versus alternatives. Usage is implied by the description, but no when-not-to-use or alternative names are provided.

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/dokmatiq/docgen-sdks'

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