MCP Chain of Draft (CoD) Prompt Tool
Overview
- **Input Transformation**: Your regular prompt is automatically transformed into a CoD/CoT format
- **LLM Processing**: The transformed prompt is passed to your chosen LLM (Claude, GPT, Ollama, or local models)
- **Enhanced Reasoning**: The LLM processes the request using structured reasoning steps
- **Result Transformation**: The response is transformed back into a clear, concise format
BYOLLM Support
Supported LLM Integrations
- **Cloud Services** - Anthropic Claude - OpenAI GPT models - Mistral AI
- **Local Models** - Ollama (all models) - Local LLama variants - Any model supporting chat completion API
Configuring Your LLM
- **Cloud Services** ```bash # For Anthropic Claude export ANTHROPIC_API_KEY=your_key_here # For OpenAI export OPENAI_API_KEY=your_key_here # For Mistral AI export MISTRAL_API_KEY=your_key_here ```
- **Local Models with Ollama** ```bash # First install Ollama curl https://ollama.ai/install.sh | sh # Pull your preferred model ollama pull llama2 # or ollama pull mistral # or any other model # Configure the tool to use Ollama export MCP_LLM_PROVIDER=ollama export MCP_OLLAMA_MODEL=llama2 # or your chosen model ```
- **Custom Local Models** ```bash # Point to your local model API export MCP_LLM_PROVIDER=custom export MCP_CUSTOM_LLM_ENDPOINT=http://localhost:your_port ```
Credits
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
- **Core Chain of Draft Implementation** - Concise reasoning steps (typically 5 words or less) - Format enforcement - Answer extraction
- **Performance Analytics** - Token usage tracking - Solution accuracy monitoring - Execution time measurement - Domain-specific performance metrics
- **Adaptive Word Limits** - Automatic complexity estimation - Dynamic adjustment of word limits - Domain-specific calibration
- **Comprehensive Example Database** - CoT to CoD transformation - Domain-specific examples (math, code, biology, physics, chemistry, puzzle) - Example retrieval based on problem similarity
- **Format Enforcement** - Post-processing to ensure adherence to word limits - Step structure preservation - Adherence analytics
- **Hybrid Reasoning Approaches** - Automatic selection between CoD and CoT - Domain-specific optimization - Historical performance-based selection
- **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 22+ (for JavaScript implementation)
- Nx (for building Single Executable Applications)
Python Installation
- Clone the repository
- Install dependencies: ```bash pip install -r requirements.txt ```
- Configure API keys in `.env` file: ``` ANTHROPIC_API_KEY=your_api_key_here ```
- Run the server: ```bash python server.py ```
JavaScript/TypeScript Installation
- Clone the repository
- Install dependencies: ```bash npm install ```
- Configure API keys in `.env` file: ``` ANTHROPIC_API_KEY=your_api_key_here ```
- Build and run the server: ```bash # Build TypeScript files using Nx npm run nx build # Start the server npm start # For development with auto-reload: npm run dev ```
- `npm run nx build`: Compiles TypeScript to JavaScript using Nx build system
- `npm run build:sea`: Creates Single Executable Applications for all platforms
- `npm start`: Runs the compiled server from `dist`
- `npm test`: Runs the test query against the server
- `npm run dev`: Runs the TypeScript server directly using ts-node (useful for development)
- Efficient caching and incremental builds
- Cross-platform build support
- Integrated SEA generation
- Dependency graph visualization
- Consistent build process across environments
Single Executable Applications (SEA)
Building SEA Executables
SEA Build Configuration
- Cross-platform support (macOS, Linux, Windows)
- Automatic dependency bundling
- Optimized binary size
- No runtime dependencies required
Using SEA Executables
- Are completely standalone
- Don't require Node.js installation
- Can be distributed and run directly
- Maintain all functionality of the original application
Claude Desktop Integration
- Install Claude Desktop from [claude.ai/download](https://claude.ai/download)
- Create or edit the Claude Desktop config file: ``` ~/Library/Application Support/Claude/claude_desktop_config.json ```
- Add the tool configuration (Python version): ```json { "mcpServers": { "chain-of-draft-prompt-tool": { "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-prompt-tool": { "command": "node", "args": ["/absolute/path/to/cod/index.js"], "env": { "ANTHROPIC_API_KEY": "your_api_key_here" } } } } ```
- Restart Claude Desktop
Using with Dive GUI
Integrating with Dive
- Download and install Dive from their [releases page](https://github.com/OpenAgentPlatform/Dive/releases)
- Configure the Chain of Draft tool in Dive's MCP settings:
Key Benefits of Using Dive
- Universal LLM Support with multiple API key management
- Cross-platform availability (Windows, MacOS, Linux)
- Seamless MCP integration in both stdio and SSE modes
- Multi-language interface
- Custom instructions and system prompts
- Automatic updates
Testing with MCP Inspector
Running the Inspector
- Start the MCP server in the background
- Launch the MCP Inspector interface in your default browser
- Connect to the running server for testing
Using the Inspector Interface
- Real-time visualization of tool calls and responses
- Interactive testing of MCP functions
- Request/response history
- Debug information for each interaction
- Performance metrics and timing data
- Development and debugging
- Understanding tool behavior
- Testing different inputs and scenarios
- Verifying MCP compliance
- Performance optimization
Available 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
JavaScript/TypeScript Client
Implementation Details
Python Implementation
- **AnalyticsService**: Tracks performance metrics across different problem domains and reasoning approaches
- **ComplexityEstimator**: Analyzes problems to determine appropriate word limits
- **ExampleDatabase**: Manages and retrieves examples, transforming CoT examples to CoD format
- **FormatEnforcer**: Ensures reasoning steps adhere to word limits
- **ReasoningSelector**: Intelligently chooses between CoD and CoT based on problem characteristics
JavaScript Implementation
- **analyticsDb**: In-memory database for tracking performance metrics
- **complexityEstimator**: Analyzes problems to determine complexity and appropriate word limits
- **formatEnforcer**: Ensures reasoning steps adhere to word limits
- **reasoningSelector**: Automatically chooses between CoD and CoT based on problem characteristics and historical performance