多模型AI编排服务器

通过模型上下文协议(MCP)实现多AI模型智能编排的服务,提供四种执行策略(快速、平衡、质量和成本优化)以满足不同速度、成本和质量需求。

  • by manutej
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 manutej/crush-mcp-server

使用说明

粉碎MCP服务器

通过模型上下文协议进行多模型AI编排

将Crush CLI转换为Claude Code的智能MCP工具,通过自动策略选择实现跨多个AI模型的元编排。


这是什么?

一个MCP服务器,向Claude Code和其他MCP客户端公开Crush CLI的多模型编排功能。根据您的速度、成本和质量需求,从4种执行策略中进行选择。

Claude Code → Crush MCP Server → Crush CLI → Multiple AI Models
                   ↑
           (This Project)

特性

✨ 4执行策略

  • 快速:单型号,<10s,<0.005美元(grok-3-mini)
  • 平衡的:两种型号,<30s,~0.015美元→ 俳句)
  • 质量:多模型迭代,<60s,~0.06美元(grok→ 十四行诗→ 精炼)
  • 成本优化:预算有限,可定制的最大成本

🎯 MCP工具

  • crush_execute -使用智能模型路由执行提示
  • crush_evaluate -执行前估算成本/时间/质量

🧪 经过全面测试

  • 12/12单元测试通过
  • 全面的战略覆盖
  • 采用Vitest的TDD方法

快速开始

安装(2分钟)

cd /Users/manu/Documents/LUXOR/crush-mcp-server
npm install
npm run build
npm link

添加到克劳德代码

已配置! ✅ 已添加 ~/.claude/settings.json

下一步:重新启动Claude Code以加载服务器。

测试IT

Use crush_execute with fast strategy to explain REST APIs in 2 sentences.

📖 完整指南:参见 QUICKSTART.md


建筑

策略模式

interface Strategy {
  execute(prompt: string, maxCost?: number): Promise<ExecuteResult>;
}

class Orchestrator {
  private strategies: Map<string, Strategy>;

  async execute(request: ExecuteRequest): Promise<ExecuteResult> {
    const strategy = this.strategies.get(request.strategy || 'balanced');
    return await strategy.execute(request.prompt, request.max_cost);
  }
}

执行流程

┌──────────────────────────────────────────────────────────────┐
│ 1. User Prompt → Claude Code                                │
│    "Design a REST API using quality strategy"               │
└────────────────────┬─────────────────────────────────────────┘
                     │ MCP Protocol
┌────────────────────▼─────────────────────────────────────────┐
│ 2. Crush MCP Server (This Project)                          │
│    - Parse strategy from request                            │
│    - Route to appropriate Strategy implementation           │
└────────────────────┬─────────────────────────────────────────┘
                     │
┌────────────────────▼─────────────────────────────────────────┐
│ 3. Quality Strategy                                          │
│    Step 1: grok-3-mini (outline)        → Cost: $0.002      │
│    Step 2: claude-sonnet-4-5 (detail)   → Cost: $0.045      │
│    Step 3: iterative refinement         → Cost: $0.016      │
│                                                              │
│    Quality Score: 0.87 (target: 0.75)                       │
│    Total Cost: $0.063                                        │
│    Execution Time: 42s                                       │
└────────────────────┬─────────────────────────────────────────┘
                     │ Formatted Response
┌────────────────────▼─────────────────────────────────────────┐
│ 4. Return to User via Claude Code                           │
│    {                                                         │
│      result: "...",                                          │
│      metadata: {                                             │
│        models_used: ["grok-3-mini", "claude-sonnet-4-5"],   │
│        total_cost: 0.063,                                    │
│        quality_score: 0.87,                                  │
│        strategy: "quality"                                   │
│      }                                                       │
│    }                                                         │
└──────────────────────────────────────────────────────────────┘

项目结构

crush-mcp-server/
├── src/
│   ├── index.ts              # MCP server (stdio transport)
│   ├── orchestrator.ts       # Strategy orchestration
│   ├── crush-client.ts       # Crush CLI wrapper
│   ├── evaluator.ts          # Quality evaluation (0-1 scale)
│   ├── types.ts              # TypeScript definitions
│   └── strategies/
│       ├── base.ts           # Strategy interface
│       ├── fast.ts           # Single model (grok-3-mini)
│       ├── balanced.ts       # Two models (grok → haiku)
│       ├── quality.ts        # Multi-model + iteration
│       └── cost-optimized.ts # Budget-constrained
├── tests/
│   └── strategies.test.ts    # 12 comprehensive tests
├── dist/                     # Compiled JavaScript
├── QUICKSTART.md             # Get started in 5 minutes
├── TESTING.md                # Comprehensive testing guide
├── PROGRESS.md               # Development tracker
└── package.json

文档


发展

运行测试

npm test                 # Run all tests
npm run test:watch       # Watch mode
npm run test:ui          # Visual UI
npm run test:coverage    # Coverage report

当前: ✅ 12/12测试通过

构建

npm run build     # Compile TypeScript
npm run dev       # Watch mode (auto-rebuild)
npm start         # Run compiled server

工作流程

  1. 先写测试 (TDD方法)
  2. 实施策略
  3. 运行测试 (npm test)
  4. 构建 (npm run build)
  5. 克劳德代码测试

战略详情

快速策略

// Single model, minimal tokens
const result = await client.run({
  model: 'grok-3-mini',
  prompt: userPrompt,
  maxTokens: 2000
});
// Target: <10s, <$0.005, quality: 0.6

平衡战略

// Step 1: Fast outline
const outline = await client.run({model: 'grok-3-mini', prompt});

// Step 2: Quality refinement with context
const refined = await client.run({
  model: 'claude-haiku-4-5',
  prompt: `Refine: ${outline.output}`
});
// Target: <30s, ~$0.015, quality: >0.5

质量战略

// Step 1: Outline (grok)
// Step 2: Detailed analysis (sonnet)
// Step 3: Iterative refinement until quality >= 0.75
while (qualityScore < 0.75 && iterations < maxIterations) {
  const improvement = await refine(currentOutput);
  qualityScore = evaluator.evaluate(improvement);
}
// Target: <60s, ~$0.06, quality: >0.7

成本优化策略

// Calculate max tokens from budget
const maxTokens = Math.min(
  Math.floor((budget / costPerMToken) * 1_000_000 / 2),
  1000
);

const result = await client.run({
  model: 'grok-3-mini',
  prompt,
  maxTokens
});
// Target: Custom budget, quality: 0.5

配置

粉碎二进制路径

违约: /opt/homebrew/bin/crush

要自定义,请编辑 src/orchestrator.ts:

constructor(crushBinaryPath: string = '/your/custom/path/to/crush') {

API密钥(用于实际执行)

在中配置 ~/.local/share/crush/crush.json:

{
  "providers": {
    "grok": {
      "api_key": "your-grok-api-key"
    },
    "anthropic": {
      "api_key": "your-anthropic-api-key"
    }
  }
}

路线图

✅ 完成(v0.1.0)

  • 4执行策略
  • MCP服务器实现
  • 全面的测试套件
  • 质量评价体系
  • TypeScript构建系统

🔄 进行中

  • Claude代码集成测试
  • 真实世界使用验证

📋 计划的

  • 会话管理 (CET-266)-有状态的多回合对话
  • 显式多模型 (CET-265)-用户定义模型工作流程
  • 性能优化 (CET-271)-缓存和响应时间
  • 增强文档 (CET-269)-API参考和实例

看 线性项目 了解详情。


贡献

开发工作流程

  1. 创建分支: git checkout -b feature/your-feature
  2. 编写测试:添加到 tests/strategies.test.ts
  3. 实施:将代码添加到 src/
  4. 测试: npm test (必须通过)
  5. 构建: npm run build
  6. 更新文档:更新PROGRESS.md
  7. 提交: git commit -m "feat: description"

代码风格

  • TypeScript严格模式
  • ES2022目标
  • Node16模块
  • JSDoc综合评论
  • TDD方法(先测试)

许可证

麻省理工学院


链接

  • 线性项目: https://linear.app/ceti-luxor/project/crush-mcp-server-fabcd9722fbc
  • Crush命令行界面: https://github.com/charmbracelet/crush
  • MCP规范: https://modelcontextprotocol.io

状态: ✅ 生产准备测试|🧪 集成测试正在进行中

下一步:重新启动Claude Code并尝试!看 QUICKSTART.md