Skip to main content
Glama
stat-guy

Chain of Draft (CoD) MCP Server

by stat-guy

get_token_reduction

Analyze token reduction statistics to compare Chain of Draft with Chain of Thought, optimizing reasoning outputs for task-solving while maintaining accuracy.

Instructions

Get token reduction statistics for CoD vs CoT

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler for the get_token_reduction tool in the MCP tool call dispatcher. Fetches stats from analyticsDb and formats the response.
    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 }] }; }
  • Schema definition for the get_token_reduction tool, specifying no input parameters.
    const TOKEN_TOOL = { name: "get_token_reduction", description: "Get token reduction statistics for CoD vs CoT", inputSchema: { type: "object", properties: {} } };
  • Python MCP tool handler decorated with @app.tool() that executes the get_token_reduction logic by calling analytics and formatting.
    @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
  • Helper function in analytics that queries the database to compute token reduction stats 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()
  • JavaScript analytics database helper function that computes in-memory token reduction statistics from records.
    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 }; }); }

Other Tools

Related 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