MCP cover image
See in Github
2025-03-04

草稿链(COD)MCP服务器:用于更有效的LLM推理的草案推理方法链的MCP服务器实现。

1

Github Watches

4

Github Forks

5

Github Stars

Chain of Draft (CoD) MCP Server

Overview

This MCP server implements the Chain of Draft (CoD) reasoning approach as described in the research paper "Chain of Draft: Thinking Faster by Writing Less". CoD is a novel paradigm that allows LLMs to generate minimalistic yet informative intermediate reasoning outputs while solving tasks, significantly reducing token usage while maintaining accuracy.

Key Benefits

  • Efficiency: Significantly reduced token usage (as little as 7.6% of standard CoT)
  • Speed: Faster responses due to shorter generation time
  • Cost Savings: Lower API costs for LLM calls
  • Maintained Accuracy: Similar or even improved accuracy compared to CoT
  • Flexibility: Applicable across various reasoning tasks and domains

Features

  1. Core Chain of Draft Implementation

    • Concise reasoning steps (typically 5 words or less)
    • Format enforcement
    • Answer extraction
  2. Performance Analytics

    • Token usage tracking
    • Solution accuracy monitoring
    • Execution time measurement
    • Domain-specific performance metrics
  3. Adaptive Word Limits

    • Automatic complexity estimation
    • Dynamic adjustment of word limits
    • Domain-specific calibration
  4. Comprehensive Example Database

    • CoT to CoD transformation
    • Domain-specific examples (math, code, biology, physics, chemistry, puzzle)
    • Example retrieval based on problem similarity
  5. Format Enforcement

    • Post-processing to ensure adherence to word limits
    • Step structure preservation
    • Adherence analytics
  6. Hybrid Reasoning Approaches

    • Automatic selection between CoD and CoT
    • Domain-specific optimization
    • Historical performance-based selection
  7. OpenAI API Compatibility

    • Drop-in replacement for standard OpenAI clients
    • Support for both completions and chat interfaces
    • Easy integration into existing workflows

Setup and Installation

Prerequisites

  • Python 3.10+ (for Python implementation)
  • Node.js 18+ (for JavaScript implementation)
  • Anthropic API key

Python Installation

  1. Clone the repository
  2. Install dependencies:
    pip install -r requirements.txt
    
  3. Configure API keys in .env file:
    ANTHROPIC_API_KEY=your_api_key_here
    
  4. Run the server:
    python server.py
    

JavaScript Installation

  1. Clone the repository
  2. Install dependencies:
    npm install
    
  3. Configure API keys in .env file:
    ANTHROPIC_API_KEY=your_api_key_here
    
  4. Run the server:
    node index.js
    

Claude Desktop Integration

To integrate with Claude Desktop:

  1. Install Claude Desktop from claude.ai/download

  2. Create or edit the Claude Desktop config file:

    ~/Library/Application Support/Claude/claude_desktop_config.json
    
  3. Add the server configuration (Python version):

    {
        "mcpServers": {
            "chain-of-draft": {
                "command": "python3",
                "args": ["/absolute/path/to/cod/server.py"],
                "env": {
                    "ANTHROPIC_API_KEY": "your_api_key_here"
                }
            }
        }
    }
    

    Or for the JavaScript version:

    {
        "mcpServers": {
            "chain-of-draft": {
                "command": "node",
                "args": ["/absolute/path/to/cod/index.js"],
                "env": {
                    "ANTHROPIC_API_KEY": "your_api_key_here"
                }
            }
        }
    }
    
  4. Restart Claude Desktop

You can also use the Claude CLI to add the server:

# For Python implementation
claude mcp add chain-of-draft -e ANTHROPIC_API_KEY="your_api_key_here" "python3 /absolute/path/to/cod/server.py"

# For JavaScript implementation
claude mcp add chain-of-draft -e ANTHROPIC_API_KEY="your_api_key_here" "node /absolute/path/to/cod/index.js"

Available Tools

The Chain of Draft server provides the following tools:

Tool Description
chain_of_draft_solve Solve a problem using Chain of Draft reasoning
math_solve Solve a math problem with CoD
code_solve Solve a coding problem with CoD
logic_solve Solve a logic problem with CoD
get_performance_stats Get performance stats for CoD vs CoT
get_token_reduction Get token reduction statistics
analyze_problem_complexity Analyze problem complexity

Developer Usage

Python Client

If you want to use the Chain of Draft client directly in your Python code:

from client import ChainOfDraftClient

# Create client 
cod_client = ChainOfDraftClient()

# Use directly
result = await cod_client.solve_with_reasoning(
    problem="Solve: 247 + 394 = ?",
    domain="math"
)

print(f"Answer: {result['final_answer']}")
print(f"Reasoning: {result['reasoning_steps']}")
print(f"Tokens used: {result['token_count']}")

JavaScript Client

For JavaScript/Node.js applications:

import { Anthropic } from "@anthropic-ai/sdk";
import dotenv from "dotenv";

// Load environment variables
dotenv.config();

// Create the Anthropic client
const anthropic = new Anthropic({
  apiKey: process.env.ANTHROPIC_API_KEY,
});

// Import the Chain of Draft client
import chainOfDraftClient from './lib/chain-of-draft-client.js';

// Use the client
async function solveMathProblem() {
  const result = await chainOfDraftClient.solveWithReasoning({
    problem: "Solve: 247 + 394 = ?",
    domain: "math",
    max_words_per_step: 5
  });
  
  console.log(`Answer: ${result.final_answer}`);
  console.log(`Reasoning: ${result.reasoning_steps}`);
  console.log(`Tokens used: ${result.token_count}`);
}

solveMathProblem();

Implementation Details

The server is available in both Python and JavaScript implementations, both consisting of several integrated components:

Python Implementation

  1. AnalyticsService: Tracks performance metrics across different problem domains and reasoning approaches
  2. ComplexityEstimator: Analyzes problems to determine appropriate word limits
  3. ExampleDatabase: Manages and retrieves examples, transforming CoT examples to CoD format
  4. FormatEnforcer: Ensures reasoning steps adhere to word limits
  5. ReasoningSelector: Intelligently chooses between CoD and CoT based on problem characteristics

JavaScript Implementation

  1. analyticsDb: In-memory database for tracking performance metrics
  2. complexityEstimator: Analyzes problems to determine complexity and appropriate word limits
  3. formatEnforcer: Ensures reasoning steps adhere to word limits
  4. reasoningSelector: Automatically chooses between CoD and CoT based on problem characteristics and historical performance

Both implementations follow the same core principles and provide identical MCP tools, making them interchangeable for most use cases.

License

This project is open-source and available under the MIT license.

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Bora Yalcin
  • Evaluator for marketplace product descriptions, checks for relevancy and keyword stuffing.

  • https://jgadvisorycpa.com
  • This GPT assists in finding a top-rated business CPA - local or virtual. We account for their qualifications, experience, testimonials and reviews. Business operators provide a short description of your business, services wanted, and city or state.

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • OffchainLabs
  • 进行以太坊的实施

  • huahuayu
  • 统一的API网关,用于将多个Etherscan样区块链Explorer API与对AI助手的模型上下文协议(MCP)支持。

    Reviews

    2 (1)
    Avatar
    user_OFWm5U98
    2025-04-15

    I've been using MCP Server for WordPress, developed by swissspidy, and it has significantly improved my website's performance. The installation was smooth, and I'm impressed with its speed and reliability. Highly recommend checking it out: https://mcp.so/server/mcp-wp/swissspidy.