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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

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
Behavior4/5

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

With no annotations provided, the description carries the full burden and does well by disclosing key behavioral traits: it creates a self-contained HTML file, handles thousands of entities, includes color coding and hover details, and mentions error handling via ToolError. It doesn't cover aspects like performance, file size limits, or specific visual features, but provides substantial operational context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and front-loaded with the core purpose in the first sentence. Each subsequent sentence adds value: capabilities, parameter details, return values, and error handling. There's no wasted text, and the bullet-like formatting for Args/Returns/Raises enhances readability without verbosity.

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

Completeness5/5

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

Given the tool's moderate complexity (2 parameters, no annotations, but with output schema), the description is complete. It covers purpose, behavior, parameters, returns, and errors. The output schema existence means return values don't need detailed explanation in the description, and the description provides all necessary context for effective use.

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

Parameters5/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 compensate fully. It clearly explains both parameters: jsonl_file_path as 'Path to the JSONL file containing extraction results' and output_html_path as 'Optional path for the HTML output (default: auto-generated)'. This adds essential meaning beyond the bare schema, covering purpose, format, and default behavior.

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 specific action ('Generate interactive HTML visualization') and resource ('from extraction results'), distinguishing it from sibling tools like extract_from_text/url (which extract) and save_extraction_results (which saves). It specifies the visualization type, content, and capabilities like handling thousands of entities with color coding and hover details.

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?

The description implies usage context by mentioning 'extraction results' and referencing JSONL files, suggesting it should be used after extraction tools. However, it doesn't explicitly state when to use this vs. alternatives or provide any exclusions. The connection to extraction is clear but not explicitly framed as guidance.

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

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