| Crates.io | tetrad |
| lib.rs | tetrad |
| version | 0.1.11 |
| created_at | 2026-01-21 21:36:38.616057+00 |
| updated_at | 2026-01-25 16:51:20.632723+00 |
| description | Quadruple Consensus MCP Server for Claude Code - Validates code using Codex, Gemini and Qwen |
| homepage | https://github.com/SamoraDC/tetrad |
| repository | https://github.com/SamoraDC/tetrad |
| max_upload_size | |
| id | 2060161 |
| size | 479,298 |
Quadruple Consensus MCP Server for Claude Code
Tetrad is a high-performance MCP (Model Context Protocol) server written in Rust that orchestrates three AI-powered CLI code evaluation tools (Codex, Gemini CLI, Qwen) to validate all code produced by Claude Code.
The system implements a quadruple consensus protocol where no code or plan is accepted without approval from four intelligences: the three external evaluators + Claude Code itself.
init, serve, status, doctor, config, etc.)# Via npm (recommended - works seamlessly with Claude Code)
npm install -g @samoradc/tetrad
# Or via cargo (requires additional setup)
cargo install tetrad
sudo cp ~/.cargo/bin/tetrad /usr/local/bin/
npx @samoradc/tetrad init
This will:
tetrad.toml configuration file.tetrad/ directory for the database.tetrad/ to your .gitignoreTetrad requires at least one of the following AI CLI tools:
# Codex CLI (OpenAI)
npm install -g @openai/codex
export OPENAI_API_KEY="your-openai-key"
# Gemini CLI (Google)
npm install -g @google/gemini-cli
export GOOGLE_API_KEY="your-google-key"
# Qwen CLI (Alibaba)
pip install dashscope
export DASHSCOPE_API_KEY="your-dashscope-key"
# Check Tetrad version
tetrad version
# Check CLI availability
tetrad status
# Diagnose any issues
tetrad doctor
# Option 1: Auto-discovery (recommended - after MCP Registry publication)
claude mcp add tetrad
# Option 2: Manual installation (available in all projects)
claude mcp add --scope user tetrad -- npx @samoradc/tetrad serve
# Option 3: Current project only
claude mcp add tetrad -- npx @samoradc/tetrad serve
# Verify it's configured
claude mcp list
Alternative (if installed via cargo):
claude mcp add --scope user tetrad -- tetrad serve
Create or edit .mcp.json in your project root:
{
"mcpServers": {
"tetrad": {
"type": "stdio",
"command": "npx",
"args": ["@samoradc/tetrad", "serve"],
"env": {
"OPENAI_API_KEY": "${OPENAI_API_KEY}",
"GOOGLE_API_KEY": "${GOOGLE_API_KEY}",
"DASHSCOPE_API_KEY": "${DASHSCOPE_API_KEY}"
}
}
}
}
Or for global user configuration in ~/.claude.json (mcpServers section):
{
"mcpServers": {
"tetrad": {
"type": "stdio",
"command": "npx",
"args": ["@samoradc/tetrad", "serve"]
}
}
}
When you ask Claude Code to write code, Tetrad automatically validates it:
You: "Create a function in Rust that calculates the average of a vector"
Claude Code:
1. Writes the code
2. Calls tetrad_review_code automatically
3. Tetrad sends to Codex, Gemini and Qwen for evaluation
4. Returns consolidated consensus from all 3 evaluators
Tetrad Response:
┌─────────────────────────────────────────────┐
│ DECISION: PASS ✓ │
│ Score: 92/100 │
│ Consensus: Yes (3/3 approved) │
│ │
│ Votes: │
│ • Codex: Pass (95) │
│ • Gemini: Pass (90) │
│ • Qwen: Pass (92) │
│ │
│ Suggestions: │
│ - Consider handling empty vector case │
└─────────────────────────────────────────────┘
Claude Code: Saves the approved code
Tetrad Response:
┌─────────────────────────────────────────────┐
│ DECISION: BLOCK ✗ │
│ Score: 26/100 │
│ Consensus: Yes (3/3 rejected) │
│ │
│ Votes: │
│ • Codex: Fail (30) - division by zero │
│ • Gemini: Fail (25) - no error handling │
│ • Qwen: Fail (25) - unsafe operation │
│ │
│ Issues: │
│ - Division by zero not handled │
│ - Missing input validation │
│ - No Result/Option return type │
└─────────────────────────────────────────────┘
Claude Code: Fixes the code and resubmits
tetrad - Quadruple Consensus CLI for Claude Code
COMMANDS:
init Initialize configuration in current directory
serve Start the MCP server (used by Claude Code)
status Show CLI status (codex, gemini, qwen)
config Configure options interactively
doctor Diagnose configuration issues
version Show version
evaluate Evaluate code manually (without MCP)
history Show evaluation history from ReasoningBank
export Export patterns from ReasoningBank
import Import patterns into ReasoningBank
OPTIONS:
-c, --config <FILE> Configuration file (default: tetrad.toml)
-v, --verbose Verbose mode
-q, --quiet Quiet mode
-h, --help Show help
When running as MCP server, Tetrad exposes 6 tools:
| Tool | Description |
|---|---|
tetrad_review_plan |
Review implementation plans before coding |
tetrad_review_code |
Review code before saving |
tetrad_review_tests |
Review tests before finalizing |
tetrad_confirm |
Confirm agreement with received feedback |
tetrad_final_check |
Final verification before commit |
tetrad_status |
Check health of evaluators |
1. Claude Code generates plan → tetrad_review_plan → Feedback
2. Claude Code implements → tetrad_review_code → Feedback
3. Claude Code adjusts → tetrad_confirm → Confirmation
4. Claude Code finalizes → tetrad_final_check → Certificate
Claude Code → MCP Protocol (stdio) → Tetrad Server (Rust)
│
┌─────────────────────┼─────────────────────┐
▼ ▼ ▼
Codex CLI Gemini CLI Qwen CLI
(syntax) (architecture) (logic)
│ │ │
└─────────────────────┼─────────────────────┘
▼
Consensus Engine
│
┌─────────────┴─────────────┐
▼ ▼
LRU Cache ReasoningBank
(results) (SQLite)
RETRIEVE→JUDGE→DISTILL→CONSOLIDATE
| Executor | CLI | Specialization |
|---|---|---|
| Codex | codex exec --json |
Syntax and code conventions |
| Gemini | gemini -o json |
Architecture and design |
| Qwen | qwen |
Logic bugs and correctness |
| Rule | Requirement | Use Case |
|---|---|---|
| Golden | Unanimity (3/3) | Critical code, security |
| Strong | 3/3 or 2/3 with high confidence | Default |
| Weak | Simple majority (2/3) | Rapid prototyping |
The ReasoningBank is a continuous learning system that stores and consolidates code patterns:
RETRIEVE → JUDGE → DISTILL → CONSOLIDATE
│ │ │ │
│ │ │ └─ Merge similar patterns
│ │ └─ Extract new patterns
│ └─ Evaluate code with context
└─ Search for relevant patterns
# View evaluation history
tetrad history --limit 50
# Export patterns to share
tetrad export -o team-patterns.json
# Import patterns from another ReasoningBank
tetrad import team-patterns.json
The tetrad.toml file is created automatically with tetrad init:
[general]
log_level = "info"
timeout_secs = 60
[executors.codex]
enabled = true
command = "codex"
args = ["exec", "--json"]
timeout_secs = 30
[executors.gemini]
enabled = true
command = "gemini"
args = ["-o", "json"]
timeout_secs = 30
[executors.qwen]
enabled = true
command = "qwen"
args = []
timeout_secs = 30
[consensus]
default_rule = "strong"
min_score = 70
max_loops = 3
[reasoning]
enabled = true
db_path = ".tetrad/tetrad.db"
max_patterns_per_query = 10
consolidation_interval = 100
[cache]
enabled = true
capacity = 1000
ttl_secs = 300
Use tetrad config for interactive configuration:
🔧 Tetrad Interactive Configuration
What would you like to configure?
❯ General Settings
Executors (Codex, Gemini, Qwen)
Consensus
ReasoningBank
Save and Exit
Exit without Saving
The system includes an LRU cache to avoid unnecessary re-evaluations:
Hooks allow customizing behavior at specific points:
| Hook | When | Use |
|---|---|---|
pre_evaluate |
Before evaluation | Modify request, skip evaluation |
post_evaluate |
After evaluation | Logging, metrics, notifications |
on_consensus |
When consensus reached | Automatic actions on approval |
on_block |
When code blocked | Alerts, automatic rollback |
tetrad/
├── Cargo.toml # Crate manifest
├── CLAUDE.md # Documentation for Claude Code
├── README.md # This file
├── Tetrad.md # Complete specification
├── src/
│ ├── main.rs # Entry point (CLI)
│ ├── lib.rs # Exportable library
│ ├── cli/
│ │ ├── mod.rs # CLI definition with clap
│ │ ├── commands.rs # Command implementations
│ │ └── interactive.rs # Interactive configuration (dialoguer)
│ ├── executors/
│ │ ├── mod.rs
│ │ ├── base.rs # CliExecutor trait
│ │ ├── codex.rs # Codex executor
│ │ ├── gemini.rs # Gemini executor
│ │ └── qwen.rs # Qwen executor
│ ├── types/
│ │ ├── mod.rs
│ │ ├── config.rs # TOML configuration
│ │ ├── errors.rs # TetradError/TetradResult
│ │ ├── requests.rs # EvaluationRequest
│ │ └── responses.rs # EvaluationResult, ModelVote
│ ├── consensus/
│ │ ├── mod.rs # Exports
│ │ ├── engine.rs # ConsensusEngine
│ │ ├── aggregator.rs # Vote aggregation
│ │ └── rules.rs # Voting rules
│ ├── reasoning/
│ │ ├── mod.rs # Exports
│ │ ├── bank.rs # ReasoningBank
│ │ ├── patterns.rs # Pattern types
│ │ ├── sqlite.rs # SQLite storage
│ │ └── export.rs # Import/Export
│ ├── mcp/
│ │ ├── mod.rs # Exports
│ │ ├── server.rs # MCP server
│ │ ├── protocol.rs # JSON-RPC types
│ │ ├── tools.rs # Tool handlers
│ │ └── transport.rs # Stdio transport
│ ├── cache/
│ │ ├── mod.rs # Exports
│ │ └── lru.rs # LRU cache
│ └── hooks/
│ ├── mod.rs # Hook trait and HookSystem
│ └── builtin.rs # Default hooks
└── tests/
├── cli_integration.rs
├── consensus_integration.rs
├── mcp_integration.rs
└── reasoning_integration.rs
# Build
cargo build
cargo build --release
# Tests
cargo test # All tests
cargo test --lib # Unit tests only
cargo test --tests # Integration tests only
# Lint
cargo clippy --all-targets --all-features -- -D warnings
# Format
cargo fmt
cargo fmt --check
# Documentation
cargo doc --open
# Run CLI
cargo run -- status
cargo run -- doctor
cargo run -- version
cargo run -- config
# Check if CLIs are in PATH
which codex
which gemini
which qwen
# Check configuration
tetrad doctor
Make sure your config uses exec --json:
[executors.codex]
args = ["exec", "--json"]
Make sure your config uses -o json:
[executors.gemini]
args = ["-o", "json"]
Inside Claude Code, run:
/mcp
To use Tetrad, you need at least one of the AI CLIs installed:
Check availability with:
tetrad status
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)MIT
SamoraDC
Links: