Skip to main content
Glama
stat-guy

Chain of Draft (CoD) MCP Server

by stat-guy

get_token_reduction

Calculate token usage statistics comparing Chain of Draft versus Chain of Thought reasoning approaches to optimize AI model efficiency.

Instructions

Get token reduction statistics for CoD vs CoT

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Main handler function for the 'get_token_reduction' tool, registered via @app.tool() decorator. Fetches stats from analytics and formats the response string.
    @app.tool()
    async def get_token_reduction() -> str:
        """Get token reduction statistics for CoD vs CoT."""
        stats = await analytics.get_token_reduction_stats()
        
        result = "Token Reduction Analysis:\n\n"
        
        if not stats:
            return "No reduction data available yet."
        
        for stat in stats:
            result += f"Domain: {stat['domain']}\n"
            result += f"CoD avg tokens: {stat['cod_avg_tokens']:.1f}\n"
            result += f"CoT avg tokens: {stat['cot_avg_tokens']:.1f}\n"
            result += f"Reduction: {stat['reduction_percentage']:.1f}%\n\n"
        
        return result
  • Database query helper that computes token reduction statistics by averaging tokens used for CoD and CoT approaches per domain.
    async def get_token_reduction_stats(self):
        """Calculate token reduction statistics for CoD vs CoT."""
        session = self.Session()
        try:
            domains = session.query(InferenceRecord.domain).distinct().all()
            results = []
            
            for domain_row in domains:
                domain = domain_row[0]
                
                # Get average tokens for CoD and CoT approaches in this domain
                cod_avg = session.query(func.avg(InferenceRecord.tokens_used)).filter(
                    InferenceRecord.domain == domain,
                    InferenceRecord.approach == "CoD"
                ).scalar() or 0
                
                cot_avg = session.query(func.avg(InferenceRecord.tokens_used)).filter(
                    InferenceRecord.domain == domain,
                    InferenceRecord.approach == "CoT"
                ).scalar() or 0
                
                if cot_avg > 0:
                    reduction_percentage = (1 - (cod_avg / cot_avg)) * 100
                else:
                    reduction_percentage = 0
                    
                results.append({
                    "domain": domain,
                    "cod_avg_tokens": cod_avg,
                    "cot_avg_tokens": cot_avg,
                    "reduction_percentage": reduction_percentage
                })
                
            return results
        finally:
            session.close()
  • Explicit JSON schema definition for the 'get_token_reduction' tool with no input parameters.
    const TOKEN_TOOL = {
      name: "get_token_reduction",
      description: "Get token reduction statistics for CoD vs CoT",
      inputSchema: {
        type: "object",
        properties: {}
      }
    };
  • JavaScript handler for 'get_token_reduction' tool in the MCP server request handler, formats stats from analyticsDb.
    if (name === "get_token_reduction") {
      const stats = analyticsDb.getTokenReductionStats();
      
      let result = "Token Reduction Analysis:\n\n";
      
      if (!stats || stats.length === 0) {
        result = "No reduction data available yet.";
      } else {
        for (const stat of stats) {
          result += `Domain: ${stat.domain}\n`;
          result += `CoD avg tokens: ${stat.cod_avg_tokens.toFixed(1)}\n`;
          result += `CoT avg tokens: ${stat.cot_avg_tokens.toFixed(1)}\n`;
          result += `Reduction: ${stat.reduction_percentage.toFixed(1)}%\n\n`;
        }
      }
      
      return {
        content: [{
          type: "text",
          text: result
        }]
      };
    }
  • In-memory analytics helper method that calculates token reduction stats by grouping records by domain and averaging CoD/CoT tokens.
    getTokenReductionStats: function() {
      // Group by domain
      const domains = {};
      for (const record of this.records) {
        if (!domains[record.domain]) {
          domains[record.domain] = {
            cod_tokens: [],
            cot_tokens: []
          };
        }
        
        if (record.approach === 'CoD') {
          domains[record.domain].cod_tokens.push(record.tokens_used);
        } else if (record.approach === 'CoT') {
          domains[record.domain].cot_tokens.push(record.tokens_used);
        }
      }
      
      // Calculate reduction stats
      return Object.entries(domains).map(([domain, data]) => {
        const cod_avg = data.cod_tokens.length 
          ? data.cod_tokens.reduce((a, b) => a + b, 0) / data.cod_tokens.length 
          : 0;
        const cot_avg = data.cot_tokens.length 
          ? data.cot_tokens.reduce((a, b) => a + b, 0) / data.cot_tokens.length 
          : 0;
        
        let reduction = 0;
        if (cot_avg > 0 && cod_avg > 0) {
          reduction = 100 * (1 - (cod_avg / cot_avg));
        }
        
        return {
          domain,
          cod_avg_tokens: cod_avg,
          cot_avg_tokens: cot_avg,
          reduction_percentage: reduction
        };
      });
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It only states what the tool does (get statistics) without revealing any behavioral traits such as whether it's read-only, requires authentication, has rate limits, or what the output format might be. This is a significant gap for a tool with zero annotation coverage.

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 a single, efficient sentence that directly states the tool's purpose without any wasted words. It is appropriately sized and front-loaded, making it easy for an agent to parse quickly.

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

Completeness2/5

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

Given the lack of annotations and output schema, the description is incomplete. It doesn't explain what the statistics include (e.g., metrics, timeframes, or data sources), how the results are structured, or any behavioral context. For a tool that likely returns data, this leaves significant gaps in understanding its full functionality.

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 tool has 0 parameters, and the schema description coverage is 100%, so there are no parameters to document. The description doesn't need to add parameter semantics, and it appropriately avoids mentioning any. A baseline of 4 is applied since no parameters exist, and the description doesn't introduce unnecessary complexity.

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 as retrieving 'token reduction statistics for CoD vs CoT' (Chain-of-Draft vs Chain-of-Thought), which is a specific verb+resource combination. However, it doesn't differentiate this tool from sibling tools like 'get_performance_stats' or 'analyze_problem_complexity', which might provide related metrics, so it falls short of a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention any context, prerequisites, or exclusions, nor does it reference sibling tools that might offer overlapping or complementary functionality, leaving the agent with no usage direction.

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

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