Skip to main content
Glama

Chain of Draft (CoD) MCP Server

by stat-guy

草案链(CoD)MCP 服务器

概述

该 MCP 服务器实现了研究论文《Chain of Draft: Thinking Faster by Writing Less》中描述的 Chain of Draft (CoD) 推理方法。CoD 是一种新颖的范式,它允许 LLM 在解决任务时生成简洁但信息丰富的中间推理输出,从而显著减少 token 的使用,同时保持准确性。

主要优点

  • 效率:显著减少代币使用量(仅为标准 CoT 的 7.6%)
  • 速度:由于生成时间较短,响应速度更快
  • 节省成本:降低 LLM 调用的 API 成本
  • 保持精度:与 CoT 相比,精度相似甚至更高
  • 灵活性:适用于各种推理任务和领域

特征

  1. 草案实施的核心链
    • 简洁的推理步骤(通常 5 个字或更少)
    • 格式强制执行
    • 答案提取
  2. 性能分析
    • 代币使用情况追踪
    • 解决方案准确性监控
    • 执行时间测量
    • 特定领域的性能指标
  3. 自适应字数限制
    • 自动复杂度评估
    • 动态调整字数限制
    • 特定领域校准
  4. 综合示例数据库
    • CoT 到 CoD 的转换
    • 特定领域的示例(数学、代码、生物、物理、化学、谜题)
    • 基于问题相似度的示例检索
  5. 格式执行
    • 后期处理以确保遵守字数限制
    • 台阶结构保存
    • 依从性分析
  6. 混合推理方法
    • 自动选择 CoD 和 CoT
    • 特定领域优化
    • 基于历史绩效的选择
  7. OpenAI API 兼容性
    • 标准 OpenAI 客户端的直接替代品
    • 支持完成和聊天界面
    • 轻松集成到现有工作流程中

设置和安装

先决条件

  • Python 3.10+(用于 Python 实现)
  • Node.js 18+(用于 JavaScript 实现)
  • 人类学 API 密钥

Python 安装

  1. 克隆存储库
  2. 安装依赖项:
    pip install -r requirements.txt
  3. .env文件中配置 API 密钥:
    ANTHROPIC_API_KEY=your_api_key_here
  4. 运行服务器:
    python server.py

JavaScript 安装

  1. 克隆存储库
  2. 安装依赖项:
    npm install
  3. .env文件中配置 API 密钥:
    ANTHROPIC_API_KEY=your_api_key_here
  4. 运行服务器:
    node index.js

Claude 桌面集成

与 Claude Desktop 集成:

  1. claude.ai/download安装 Claude Desktop
  2. 创建或编辑 Claude Desktop 配置文件:
    ~/Library/Application Support/Claude/claude_desktop_config.json
  3. 添加服务器配置(Python版本):
    { "mcpServers": { "chain-of-draft": { "command": "python3", "args": ["/absolute/path/to/cod/server.py"], "env": { "ANTHROPIC_API_KEY": "your_api_key_here" } } } }
    或者对于 JavaScript 版本:
    { "mcpServers": { "chain-of-draft": { "command": "node", "args": ["/absolute/path/to/cod/index.js"], "env": { "ANTHROPIC_API_KEY": "your_api_key_here" } } } }
  4. 重启Claude桌面

您还可以使用 Claude CLI 添加服务器:

# 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"

可用工具

Chain of Draft 服务器提供以下工具:

工具描述
chain_of_draft_solve使用 Chain of Draft 推理解决问题
math_solve使用 CoD 解决数学问题
code_solve使用 CoD 解决编码问题
logic_solve使用 CoD 解决逻辑问题
get_performance_stats获取 CoD 与 CoT 的性能统计数据
get_token_reduction获取 token 减少统计数据
analyze_problem_complexity分析问题复杂性

开发人员使用情况

Python客户端

如果您想在 Python 代码中直接使用 Chain of Draft 客户端:

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 客户端

对于 JavaScript/Node.js 应用程序:

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();

实现细节

该服务器有 Python 和 JavaScript 两种实现,均由几个集成组件组成:

Python 实现

  1. AnalyticsService :跟踪不同问题领域和推理方法的性能指标
  2. ComplexityEstimator :分析问题以确定适当的字数限制
  3. ExampleDatabase :管理和检索示例,将 CoT 示例转换为 CoD 格式
  4. FormatEnforcer :确保推理步骤符合字数限制
  5. ReasoningSelector :根据问题特征在 CoD 和 CoT 之间进行智能选择

JavaScript 实现

  1. analyticsDb :用于跟踪性能指标的内存数据库
  2. complexityEstimator :分析问题以确定复杂性和适当的字数限制
  3. formatEnforcer :确保推理步骤符合字数限制
  4. reasoningSelector :根据问题特征和历史表现自动在 CoD 和 CoT 之间进行选择

两种实现都遵循相同的核心原则并提供相同的 MCP 工具,使得它们在大多数用例中可以互换。

执照

该项目是开源的,并根据 MIT 许可证提供。

You must be authenticated.

A
security – no known vulnerabilities
F
license - not found
A
quality - confirmed to work

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

实施 Chain of Draft 推理方法,在解决任务时生成简约的中间推理输出,在保持准确性的同时显著减少 token 的使用。

  1. 概述
    1. 主要优点
      1. 特征
        1. 设置和安装
          1. 先决条件
          2. Python 安装
          3. JavaScript 安装
        2. Claude 桌面集成
          1. 可用工具
            1. 开发人员使用情况
              1. Python客户端
              2. JavaScript 客户端
            2. 实现细节
              1. Python 实现
              2. JavaScript 实现
            3. 执照

              Related MCP Servers

              • A
                security
                A
                license
                A
                quality
                Enhances Claude's reasoning capabilities by integrating DeepSeek R1's advanced reasoning engine for intricate multi-step reasoning tasks with precision and efficiency.
                Last updated -
                1
                35
                Python
                MIT License
                • Apple
              • -
                security
                A
                license
                -
                quality
                Enhances Claude's reasoning capabilities by integrating DeepSeek R1's advanced reasoning engine, allowing Claude to tackle complex multi-step reasoning tasks with greater precision.
                Last updated -
                Python
                MIT License
                • Apple
              • -
                security
                -
                license
                -
                quality
                Provides a tool for dynamic and reflective problem-solving by breaking complex problems into manageable steps with support for revision, branching, and hypothesis generation.
                Last updated -
                13,824
                JavaScript
              • -
                security
                A
                license
                -
                quality
                A minimal MCP Server that provides Claude AI models with the 'think' tool capability, enabling better performance on complex reasoning tasks by allowing the model to pause during response generation for additional thinking steps.
                Last updated -
                525
                1
                TypeScript
                MIT License
                • Apple

              View all related MCP servers

              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