Skip to main content
Glama
stat-guy

Chain of Draft (CoD) MCP Server

by stat-guy

analyze_problem_complexity

Analyze problem complexity to determine difficulty level and required resources for effective solution planning.

Instructions

Analyze the complexity of a problem

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
problemYesThe problem to analyze
domainNoProblem domain

Implementation Reference

  • Primary handler function for the 'analyze_problem_complexity' tool in the Python FastMCP server. Decorated with @app.tool() for automatic registration and schema inference. Delegates to complexity_estimator for analysis.
    @app.tool()
    async def analyze_problem_complexity(
        problem: str,
        domain: str = "general"
    ) -> str:
        """Analyze the complexity of a problem.
        
        Args:
            problem: The problem to analyze
            domain: Problem domain
        """
        analysis = complexity_estimator.analyze_problem(problem, domain)
        
        result = f"Complexity Analysis for {domain} problem:\n\n"
        result += f"Word count: {analysis['word_count']}\n"
        result += f"Sentence count: {analysis['sentence_count']}\n"
        result += f"Words per sentence: {analysis['words_per_sentence']:.1f}\n"
        result += f"Complexity indicators found: {analysis['indicator_count']}\n"
        
        if analysis['found_indicators']:
            result += f"Indicators: {', '.join(analysis['found_indicators'])}\n"
        
        result += f"Question count: {analysis['question_count']}\n"
        result += f"\nEstimated complexity score: {analysis['estimated_complexity']}\n"
        result += f"Recommended word limit per step: {analysis['estimated_complexity']}\n"
        
        return result
  • Core helper method performing detailed problem complexity analysis, computing metrics like word count, indicators, sentences, and estimated complexity score. Called by the handler.
    def analyze_problem(self, problem, domain="general"):
        """
        Provide a detailed analysis of problem complexity factors.
        Useful for debugging and understanding complexity estimates.
        """
        base_limit = self.domain_base_limits.get(domain.lower(), 5)
        
        # Word count analysis
        word_count = len(problem.split())
        length_factor = min(word_count / 50, 2)
        
        # Indicator analysis
        indicators = self.complexity_indicators.get(domain.lower(), [])
        found_indicators = [ind for ind in indicators if ind.lower() in problem.lower()]
        indicator_count = len(found_indicators)
        indicator_factor = min(1 + (indicator_count * 0.2), 1.8)
        
        # Question mark analysis
        question_count = problem.count("?")
        question_factor = 1 + (question_count * 0.2)
        
        # Sentence complexity
        sentences = [s for s in problem.split(".") if s.strip()]
        words_per_sentence = word_count / max(len(sentences), 1)
        sentence_complexity_factor = min(words_per_sentence / 15, 1.5)
        
        return {
            "domain": domain,
            "base_limit": base_limit,
            "word_count": word_count,
            "length_factor": length_factor,
            "indicator_count": indicator_count,
            "found_indicators": found_indicators,
            "indicator_factor": indicator_factor,
            "question_count": question_count,
            "question_factor": question_factor,
            "sentence_count": len(sentences),
            "words_per_sentence": words_per_sentence,
            "sentence_complexity_factor": sentence_complexity_factor,
            "estimated_complexity": max(3, min(round(base_limit * max(length_factor, indicator_factor, question_factor, sentence_complexity_factor)), 10))
        }
  • Tool schema definition in JavaScript MCP server, specifying input parameters and descriptions for tool discovery.
    const COMPLEXITY_TOOL = {
      name: "analyze_problem_complexity",
      description: "Analyze the complexity of a problem",
      inputSchema: {
        type: "object",
        properties: {
          problem: {
            type: "string",
            description: "The problem to analyze"
          },
          domain: {
            type: "string",
            description: "Problem domain"
          }
        },
        required: ["problem"]
      }
    };
  • Handler implementation in JavaScript MCP server for dispatching and executing the tool using inline complexityEstimator.
    // Complexity analysis
    if (name === "analyze_problem_complexity") {
      const analysis = complexityEstimator.analyzeProblem(args.problem, args.domain || "general");
      
      let result = `Complexity Analysis for ${args.domain || "general"} problem:\n\n`;
      result += `Word count: ${analysis.word_count}\n`;
      result += `Sentence count: ${analysis.sentence_count}\n`;
      result += `Words per sentence: ${analysis.words_per_sentence.toFixed(1)}\n`;
      result += `Complexity indicators found: ${analysis.indicator_count}\n`;
      
      if (analysis.found_indicators && analysis.found_indicators.length > 0) {
        result += `Indicators: ${analysis.found_indicators.join(", ")}\n`;
      }
      
      result += `Question count: ${analysis.question_count}\n`;
      result += `\nEstimated complexity score: ${analysis.estimated_complexity}\n`;
      result += `Recommended word limit per step: ${analysis.estimated_complexity}\n`;
      
      return {
        content: [{
          type: "text",
          text: result
        }]
      };
  • Inline helper object in JS with analyzeProblem method mirroring the Python ComplexityEstimator, providing core analysis logic.
    const complexityEstimator = {
      domainBaseLimits: {
        math: 6,
        logic: 5,
        common_sense: 4,
        physics: 7,
        chemistry: 6,
        biology: 5,
        code: 8,
        puzzle: 5,
        general: 5
      },
      complexityIndicators: {
        math: ['integral', 'derivative', 'equation', 'theorem', 'calculus', 'polynomial', 'algorithm'],
        logic: ['if-then', 'premise', 'fallacy', 'syllogism', 'deduction', 'induction'],
        physics: ['velocity', 'acceleration', 'quantum', 'momentum', 'thermodynamics'],
        code: ['function', 'algorithm', 'recursive', 'complexity', 'optimization', 'edge case']
      },
      analyzeProblem: function(problem, domain) {
        const wordCount = problem.split(/\s+/).filter(Boolean).length;
        const sentences = problem.split(/[.!?]+/).filter(Boolean);
        const sentenceCount = sentences.length;
        const wordsPerSentence = sentenceCount > 0 ? wordCount / sentenceCount : 0;
        
        // Count indicators
        const indicators = this.complexityIndicators[domain] || this.complexityIndicators.general || [];
        const lowerProblem = problem.toLowerCase();
        const foundIndicators = indicators.filter(i => lowerProblem.includes(i.toLowerCase()));
        
        // Count questions
        const questionCount = (problem.match(/\?/g) || []).length;
        
        // Estimate complexity
        let complexity = this.domainBaseLimits[domain] || this.domainBaseLimits.general;
        
        // Adjust for length
        if (wordCount > 100) complexity += 2;
        else if (wordCount > 50) complexity += 1;
        
        // Adjust for sentences
        if (wordsPerSentence > 20) complexity += 1;
        
        // Adjust for indicators
        complexity += Math.min(3, foundIndicators.length);
        
        // Adjust for questions
        complexity += Math.min(2, questionCount);
        
        return {
          word_count: wordCount,
          sentence_count: sentenceCount,
          words_per_sentence: wordsPerSentence,
          indicator_count: foundIndicators.length,
          found_indicators: foundIndicators,
          question_count: questionCount,
          estimated_complexity: complexity
        };
      }

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/stat-guy/chain-of-draft'

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