chain of draft.com
chain of draft.com logo

Chain of Draft

Implements Chain of Draft reasoning to generate concise intermediate steps for efficient, token-optimized problem-solvin...

Created byApr 23, 2025

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
  1. **Performance Analytics** - Token usage tracking - Solution accuracy monitoring - Execution time measurement - Domain-specific performance metrics
  1. **Adaptive Word Limits** - Automatic complexity estimation - Dynamic adjustment of word limits - Domain-specific calibration
  1. **Comprehensive Example Database** - CoT to CoD transformation - Domain-specific examples (math, code, biology, physics, chemistry, puzzle) - Example retrieval based on problem similarity
  1. **Format Enforcement** - Post-processing to ensure adherence to word limits - Step structure preservation - Adherence analytics
  1. **Hybrid Reasoning Approaches** - Automatic selection between CoD and CoT - Domain-specific optimization - Historical performance-based selection
  1. **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
  1. Install dependencies: ```bash pip install -r requirements.txt ```
  1. Configure API keys in `.env` file: ``` ANTHROPIC_API_KEY=your_api_key_here ```
  1. Run the server: ```bash python server.py ```

JavaScript Installation

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

Claude Desktop Integration

To integrate with Claude Desktop:
  1. Install Claude Desktop from [claude.ai/download](https://claude.ai/download)
  1. Create or edit the Claude Desktop config file: ``` ~/Library/Application Support/Claude/claude_desktop_config.json ```
  1. Add the server configuration (Python version): ```json { "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: ```json { "mcpServers": { "chain-of-draft": { "command": "node", "args": ["/absolute/path/to/cod/index.js"], "env": { "ANTHROPIC_API_KEY": "your_api_key_here" } } } } ```
  1. Restart Claude Desktop
You can also use the Claude CLI to add the server:

Available Tools

The Chain of Draft server provides the following tools:
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]

Developer Usage

Python Client

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

JavaScript Client

For JavaScript/Node.js applications:

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
  1. **ComplexityEstimator**: Analyzes problems to determine appropriate word limits
  1. **ExampleDatabase**: Manages and retrieves examples, transforming CoT examples to CoD format
  1. **FormatEnforcer**: Ensures reasoning steps adhere to word limits
  1. **ReasoningSelector**: Intelligently chooses between CoD and CoT based on problem characteristics

JavaScript Implementation

  1. **analyticsDb**: In-memory database for tracking performance metrics
  1. **complexityEstimator**: Analyzes problems to determine complexity and appropriate word limits
  1. **formatEnforcer**: Ensures reasoning steps adhere to word limits
  1. **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.