Skip to main content
Glama
RalphLi213
by RalphLi213

summarize_large_chat

Summarize extensive chat conversations by breaking them into manageable chunks, creating individual summaries, and generating a comprehensive master summary for easier review.

Instructions

Handle extremely large chat histories by chunking them into manageable pieces. Each chunk gets its own summary, then creates a master summary.

Args: chat_history: The large chat conversation text to summarize title: Optional title for the summary chunk_size: Size of each chunk in characters (default: 50,000) overlap: Overlap between chunks in characters (default: 5,000)

Returns: Information about the chunked summaries created

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chat_historyYes
titleNo
chunk_sizeNo
overlapNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • main.py:327-470 (handler)
    The handler function for the 'summarize_large_chat' MCP tool. It chunks large chat histories into overlapping segments, saves each chunk to a separate Markdown file, and creates a master summary file listing all chunks. Includes input validation, error handling, and detailed file generation with metadata.
    def summarize_large_chat(
        chat_history: str,
        title: str = None,
        chunk_size: int = 50000,
        overlap: int = 5000
    ) -> str:
        """
        Handle extremely large chat histories by chunking them into manageable pieces.
        Each chunk gets its own summary, then creates a master summary.
        
        Args:
            chat_history: The large chat conversation text to summarize
            title: Optional title for the summary
            chunk_size: Size of each chunk in characters (default: 50,000)
            overlap: Overlap between chunks in characters (default: 5,000)
        
        Returns:
            Information about the chunked summaries created
        """
        try:
            if not ensure_notes_directory():
                return "Error: Could not create or access notes directory"
            
            history_size = len(chat_history)
            if history_size <= chunk_size:
                return f"Chat history ({history_size:,} chars) is small enough for regular summarization. Use summarize_chat instead."
            
            # Calculate chunks
            chunks = []
            start = 0
            chunk_num = 1
            
            while start < len(chat_history):
                end = min(start + chunk_size, len(chat_history))
                chunk_text = chat_history[start:end]
                chunks.append({
                    'number': chunk_num,
                    'text': chunk_text,
                    'start': start,
                    'end': end,
                    'size': len(chunk_text)
                })
                start = end - overlap  # Overlap to maintain context
                chunk_num += 1
            
            # Create individual chunk summaries
            timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
            clean_title = title.replace(' ', '_')[:30] if title else "Large_Chat"
            
            chunk_summaries = []
            chunk_files = []
            
            for chunk in chunks:
                chunk_filename = f"chat_chunk_{timestamp}_{clean_title}_part{chunk['number']:02d}.md"
                chunk_filepath = NOTES_DIR / chunk_filename
                
                chunk_content = f"""# Chat Chunk {chunk['number']}: {title or 'Large Chat'}
    
    **Date:** {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
    **Chunk:** {chunk['number']} of {len(chunks)}
    **Characters:** {chunk['start']:,} - {chunk['end']:,} ({chunk['size']:,} chars)
    **Total Size:** {history_size:,} characters
    
    ## Chunk Summary
    
    This is part {chunk['number']} of a large conversation that was split into {len(chunks)} chunks for processing.
    
    ### Key Points from This Chunk
    - Chunk size: {chunk['size']:,} characters
    - Position in conversation: {(chunk['start']/history_size)*100:.1f}% - {(chunk['end']/history_size)*100:.1f}%
    
    ## Chunk Content
    
    ```
    {chunk['text']}
    ```
    
    ---
    *Generated by Chat History Summarizer MCP Server - Large Chat Handler*
    """
                
                with open(chunk_filepath, 'w', encoding='utf-8') as f:
                    f.write(chunk_content)
                
                chunk_files.append(chunk_filename)
                chunk_summaries.append(f"Chunk {chunk['number']}: {chunk['size']:,} chars ({chunk['start']:,}-{chunk['end']:,})")
            
            # Create master summary file
            master_filename = f"chat_master_{timestamp}_{clean_title}.md"
            master_filepath = NOTES_DIR / master_filename
            
            master_content = f"""# Master Summary: {title or 'Large Chat'}
    
    **Date:** {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
    **Total Size:** {history_size:,} characters ({history_size/(1024*1024):.2f} MB)
    **Chunks Created:** {len(chunks)}
    **Chunk Size:** {chunk_size:,} characters
    **Overlap:** {overlap:,} characters
    
    ## Overview
    
    This large conversation was automatically split into {len(chunks)} chunks for better handling and processing.
    
    ## Chunk Breakdown
    
    {chr(10).join(f"- **{summary}**" for summary in chunk_summaries)}
    
    ## Chunk Files Created
    
    {chr(10).join(f"- `{filename}`" for filename in chunk_files)}
    
    ## Usage Instructions
    
    1. **Read individual chunks** for detailed content
    2. **Search across chunks** to find specific topics
    3. **Use chunk summaries** for quick reference
    4. **Combine insights** from multiple chunks as needed
    
    ## Master Summary
    
    > **Note:** For extremely large conversations, consider reading individual chunks for complete context.
    > This master file provides an overview of the conversation structure.
    
    ---
    *Generated by Chat History Summarizer MCP Server - Large Chat Handler*
    """
            
            with open(master_filepath, 'w', encoding='utf-8') as f:
                f.write(master_content)
            
            return f"""Large chat processed successfully!
    
    **Master Summary:** {master_filepath}
    **Total Size:** {history_size:,} characters ({history_size/(1024*1024):.2f} MB)
    **Chunks Created:** {len(chunks)}
    
    **Files Created:**
    - Master: {master_filename}
    {chr(10).join(f"- Chunk {i+1}: {filename}" for i, filename in enumerate(chunk_files))}
    
    All chunks preserve the complete original conversation with overlapping context for continuity."""
            
        except Exception as e:
            return f"Error processing large chat: {str(e)}"
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It describes the chunking and summarization process, but lacks details on behavioral traits such as performance characteristics (e.g., processing time, rate limits), error handling (e.g., what happens with invalid input), or side effects (e.g., whether summaries are stored persistently). The mention of 'Returns: Information about the chunked summaries created' is vague and doesn't specify format or content.

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?

The description is appropriately sized and front-loaded, starting with the core purpose, followed by a clear breakdown of arguments and returns. Each sentence adds value, with no redundant information. However, the structure could be slightly improved by integrating the 'Args' and 'Returns' sections more seamlessly into the narrative flow.

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

Completeness3/5

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

Given the tool's complexity (chunking and summarizing large histories) and the presence of an output schema (which should cover return values), the description is moderately complete. It explains the process and parameters well, but lacks context on prerequisites (e.g., input format requirements), limitations (e.g., maximum size), or integration with sibling tools like 'delete_summary' or 'list_summaries'. The output schema existence reduces the need to detail returns, but behavioral gaps remain.

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?

The description adds significant meaning beyond the input schema, which has 0% schema description coverage. It explains each parameter's purpose: 'chat_history' as 'The large chat conversation text to summarize', 'title' as 'Optional title for the summary', 'chunk_size' as 'Size of each chunk in characters (default: 50,000)', and 'overlap' as 'Overlap between chunks in characters (default: 5,000)'. This compensates well for the low schema coverage, though it doesn't detail units or constraints beyond defaults.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Handle extremely large chat histories by chunking them into manageable pieces. Each chunk gets its own summary, then creates a master summary.' This specifies the verb (chunk and summarize), resource (large chat histories), and method (chunking with individual and master summaries). It distinguishes from 'summarize_chat' by emphasizing handling 'extremely large' histories through chunking, though it doesn't explicitly contrast with siblings.

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 when to use this tool by stating it's for 'extremely large chat histories' and involves chunking, suggesting it should be used for large inputs where 'summarize_chat' might not suffice. However, it doesn't provide explicit guidance on when to choose this over 'summarize_chat' or when not to use it, nor does it mention alternatives like 'list_summaries' or 'delete_summary'.

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/RalphLi213/ide-chat-summarizer-mcp'

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