Skip to content

🐛 Fix: analyze_health_topic timeout on comprehensive analysis (MCP 10-second limit) #34

@ma3u

Description

@ma3u

🐛 Bug Report

Problem Description

The analyze_health_topic tool times out when using "comprehensive" depth setting through MCP clients. The timeout occurs due to MCP clients' 10-second default timeout, while comprehensive analysis takes >10 seconds to process 43,373 documents.

Current Behavior

  • Error: MCP error -32001: Request timed out
  • Occurs when: Using depth="comprehensive" parameter
  • Processing time: >10 seconds for comprehensive analysis
  • MCP client timeout: 10 seconds (hard limit in most clients)

Root Cause

  1. Large dataset: Processing 43,373 documents in vector database
  2. Complex operations: Multiple vector searches, result aggregation, AI synthesis
  3. MCP timeout: 10-second client timeout is shorter than processing time

🎯 Proposed Solution: Streaming Progressive Responses

Implementation Plan

Phase 1: Streaming Response Architecture (High Priority)

Implement SSE-based progressive response streaming to keep connections alive:

async def analyze_health_topic_streaming(topic: str, depth: str):
    # Send initial acknowledgment (< 1 second)
    yield {"type": "progress", "status": "started", "progress": 0}
    
    # Stream search results (2-4 seconds)
    search_results = await vector_search(topic)
    yield {"type": "progress", "progress": 25, "partial_results": search_results[:5]}
    
    # Stream categorization (4-6 seconds)
    categories = await categorize_results(search_results)
    yield {"type": "progress", "progress": 50, "categories": list(categories.keys())}
    
    # Stream AI synthesis (6-9 seconds)
    for category, analysis in process_categories_async(categories):
        yield {"type": "progress", "progress": 75, "partial_analysis": {category: analysis}}
    
    # Final result (< 10 seconds total)
    yield {"type": "complete", "progress": 100, "result": comprehensive_analysis}

Phase 2: Optimization (Medium Priority)

  1. Parallel Processing: Run searches concurrently
  2. Smart Caching: Cache common topics with 1-hour TTL
  3. Result Truncation: Limit to 30 documents for comprehensive

Phase 3: Background Processing (Low Priority)

Implement job queue for truly comprehensive analysis with polling.

Quick Fix (Immediate)

if depth == "comprehensive" and len(results) > 25:
    results = results[:25]  # Temporary fix to stay under 10 seconds

Success Metrics

  • Comprehensive analysis completes in <10 seconds
  • No timeout errors in MCP Inspector
  • Progressive updates visible to user
  • Claude.ai integration works smoothly

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions