Skip to main content
Glama
larsenweigle

LangExtract MCP Server

by larsenweigle

generate_visualization

Create interactive HTML visualizations to display extracted entities highlighted in their original text context with color coding and hover details.

Instructions

Generate interactive HTML visualization from extraction results.

Creates an interactive HTML file that shows extracted entities highlighted in their original text context. The visualization is self-contained and can handle thousands of entities with color coding and hover details.

Args: jsonl_file_path: Path to the JSONL file containing extraction results output_html_path: Optional path for the HTML output (default: auto-generated)

Returns: Dictionary with HTML file path and generation details

Raises: ToolError: If visualization generation fails

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
jsonl_file_pathYes
output_html_pathNo

Implementation Reference

  • The handler function that implements the generate_visualization tool. It loads the JSONL extraction results, uses langextract.visualize to create an interactive HTML visualization highlighting entities in context, handles output path (auto or specified), and returns the generated file path.
    def generate_visualization(
        jsonl_file_path: str,
        output_html_path: str | None = None
    ) -> dict[str, str]:
        """
        Generate interactive HTML visualization from extraction results.
        
        Creates an interactive HTML file that shows extracted entities highlighted
        in their original text context. The visualization is self-contained and
        can handle thousands of entities with color coding and hover details.
        
        Args:
            jsonl_file_path: Path to the JSONL file containing extraction results
            output_html_path: Optional path for the HTML output (default: auto-generated)
            
        Returns:
            Dictionary with HTML file path and generation details
            
        Raises:
            ToolError: If visualization generation fails
        """
        try:
            # Validate input file exists
            input_path = Path(jsonl_file_path)
            if not input_path.exists():
                raise ToolError(f"Input file not found: {jsonl_file_path}")
            
            # Generate visualization using langextract
            html_content = lx.visualize(str(input_path))
            
            # Determine output path
            if output_html_path:
                output_path = Path(output_html_path)
            else:
                output_path = input_path.parent / f"{input_path.stem}_visualization.html"
            
            # Ensure output directory exists
            output_path.parent.mkdir(parents=True, exist_ok=True)
            
            # Write HTML file
            with open(output_path, 'w', encoding='utf-8') as f:
                f.write(html_content)
            
            return {
                "message": "Visualization generated successfully",
                "html_file_path": str(output_path.absolute()),
                "file_size_bytes": len(html_content.encode('utf-8'))
            }
            
        except Exception as e:
            raise ToolError(f"Failed to generate visualization: {str(e)}")
  • The @mcp.tool decorator that registers the generate_visualization function as an MCP tool with FastMCP.
    @mcp.tool

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/larsenweigle/langextract-mcp'

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