Repository avatar
AI Tools
v0.2.12
active

magpie-council

io.github.JohnWangggg/magpie-council

Anonymous multi-model adversarial debate MCP server and CLI for your local Magpie gateway.

Documentation

Magpie Council

Magpie Council

Multi-model anonymous debate engine, MCP server, CLI, and native sidebar page for Magpie.

简体中文 · Quick Start · How It Works · MCP Tools · Magpie Plugin · Security · Publishing

Version 0.2.12 Go Zero CGO Magpie >=0.1.1340 MIT License


Convene 3 to 12 models already configured in your local Magpie gateway to independently analyze hard bugs, architecture trade-offs, security audits, or product roadmaps — then cross-examine each other anonymously, score peers with Borda ranking, and synthesize an actionable verdict.

Every request goes strictly through your local Magpie gateway (http://127.0.0.1:3425 or discovered MAGPIE_ADDR), so your existing accounts, quota pacing, routing groups, failover, and usage ledger work out of the box with zero extra API keys.

Highlights

  • Anti-sycophancy 3-phase debate engine — Parallel blind opening prevents anchoring bias; anonymous cross-examination (Participant A/B/C…) enforces concrete critiques, calibrated confidence (1–10), and Borda peer ranking before Judge synthesis.
  • Unleash each model's full capacity — Session ingestion scales to the strongest participating model's context_window (up to 160k runes in deep mode); only smaller-window seats get per-call 70%/30% head+tail smart slicing instead of dragging down the entire council.
  • Deep Magpie-native integration — Zero-config gateway discovery (MAGPIE_BASE_URL → MAGPIE_ADDR → ~/.config/magpie/gateway.json), quota-pacing smart selection (/v1/magpie/quotas?kept=1), custom Chinese/English provider display-name matching (e.g. 自建中转), all_models (up to 12 seats), per-seat X-Magpie-Session route/failover tracing, and automatic compatibility retries (400/422 params & 502 reasoning-budget exhaustion).
  • Live SSE spectator & 2x PNG share cards — Debates launched from any terminal or MCP agent appear automatically in the built-in dark/light dashboard and native Magpie sidebar page (Council / 议会), complete with sub-second SSE progress, live interim Borda leaderboard, provider right-click quick launch, and zero-dependency Canvas 2D 2x Retina PNG export.
  • Crash-safe single binary — Pure Go (zero CGO), OS-level per-session flock, atomic fsync + rename persistence (session.json, transcript.md, standalone report.html), orphan-runner detection, and seamless --session continuation.

How It Works

flowchart LR
  U["Terminal / Agent (MCP) / Magpie Sidebar"] --> S["Magpie Discovery & Quota Selector"]
  S --> R1["Phase 1: Blind Opening\n(Parallel, Isolated Seats)"]
  R1 --> R2["Phase 2: Cross-Examination\n(Anonymous Critique + Borda Ranking)"]
  R2 -->|Supermajority or Max Rounds| J["Phase 3: Judge Synthesis\n(Consensus · Disagreements · Actions)"]
  J --> A["Atomic Store + SSE Live UI\n(session.json · transcript.md · report.html · 2x PNG)"]
  1. Zero-config gateway & quota awareness: Reads GET /v1/models, GET /v1/magpie/quotas?kept=1, and GET /v1/magpie/limit, aligning seat selection with Magpie's smart pacing (resetsAt, runsOutAt, outlasts, pricing) and routing groups (group/*).
  2. Problem-solving-first adversarial debate: Round 1 collects independent opening positions with zero peer visibility. Round 2..N anonymizes seats (Participant A, B, C…) so models critique claims rather than brand names, absorb strong peer evidence, and converge promptly once a solid solution emerges.
  3. Verdict & continuation: A Judge model synthesizes concise Consensus, unresolved Disagreements (Pro / Con), and concrete Recommendations (with an enriched deterministic fallback if every judge candidate fails). Continue any session anytime with session_id + follow_up reusing the exact same seats.

Quick Start

1. Build & Install the Binary

# Apple Silicon macOS (remove first to ensure a fresh AMFI inode)
rm -f /opt/homebrew/bin/magpie-council && \
  go build -o /opt/homebrew/bin/magpie-council ./cmd/magpie-council

# Intel macOS / Linux
go build -o /usr/local/bin/magpie-council ./cmd/magpie-council

2. Connect to Magpie MCP Router + Skill (Recommended for Agents)

Register magpie-council once in Magpie's Library so every agent behind Magpie (OMP, Claude Code, Codex, Devin, Cursor, Antigravity…) can convene debates natively:

magpie library mcp add council \
  /opt/homebrew/bin/magpie-council mcp \
  env=MAGPIE_BASE_URL=http://127.0.0.1:3425 \
  call-timeout=300 idle=never

Add the companion workflow skill (skills/magpie-council/SKILL.md) or import MCP + Skill together:

magpie library plugin import /path/to/magpie-council

Then just ask your agent naturally in any terminal:

"Use all models under Magpie provider my-relay in deep mode to review this project for concurrency bugs, optimization opportunities, and roadmap priorities."

Most meetings start mid-session, not from the page: the agent already holds the context, so it writes the brief and calls council_debate in one step. The playbook for that (what context to hand over, which preset, when to go async, what to do with the verdict) is in docs/agent-usage.md.

3. Add the Native Magpie Sidebar Page (Council / 议会)

magpie plugin add /path/to/magpie-council/magpie-plugin
  • Opens a Council / 议会 tab under Plugins in Magpie Desktop and magpie web.
  • Adds Convene Council / 召开多模型议会 to every provider's right-click menu in Magpie's Providers list — click it to open Quick Run pre-filled with that provider.

4. Run Directly from the Terminal (CLI)

# Inspect live providers, custom display names, models, and quota health
magpie-council providers
magpie-council providers -p "my-relay"

# Fast cross-provider debate (subscription-first pacing)
magpie-council run -p auto -m fast --cost subscription_first "Evaluate SQLite vs file-backed session storage"

# Deep code review using ALL healthy models under one provider + exact line ranges
magpie-council run -p "my-relay" --all-models -m deep --preset code_review \
  --context-file "/abs/path/server.go:1-240,/abs/path/engine.go" \
  "Audit concurrency races, edge-case bugs, and high-ROI optimizations"

# Continue or recover an existing debate with new constraints
magpie-council run --session <session_id> --follow-up "New constraint: zero CGO; dig deeper into Disagreement #1"

# Inspect saved sessions, specific rounds, or standalone HTML report path
magpie-council session --list
magpie-council session <session_id> --transcript --round 2
magpie-council session <session_id> --report

# Manage persistent defaults (~/.config/magpie-council/config.json)
magpie-council config show
magpie-council config set mode=deep language=zh

# Launch the standalone spectator dashboard (default 127.0.0.1:3497)
magpie-council ui --addr 127.0.0.1:3497

MCP Tools & Presets

Tools Exposed by magpie-council mcp

ToolPurposeKey Parameters
council_providersList enabled Magpie providers, custom display names, routing groups, models, context windows, and quota healthprovider (ID, display name, or substring)
council_debateConvene a new debate or continue an existing session_id (supports 12s progress heartbeats and async: true background execution)topic, provider, all_models, seats, models, mode, preset, cost_preference, context, context_files (supports :start-end), max_context_runes, session_id, follow_up, async
council_sessionPoll running progress (including live lock & orphan recovery hints) or fetch the final verdict, report.html path, and optional verbatim transcriptsession_id, include_transcript, round

Modes & Presets

Mode / PresetBehavior
fast (default)Up to 3 rounds, concise structured responses, X-Magpie-Fallback: 1, 60s per-call budget
deepUp to 5 rounds, unrestricted high-density reasoning (max_tokens up to 16,384, context up to 160k runes), 150s per-call budget
architecture (default)Architect · RedTeam · Pragmatist (+ Evolution / Security / Systems / DX / Testing seats when seats > 3)
code_reviewBugHunter · Maintainability · Performance
securityAttacker · Defender · Compliance
productUserAdvocate · Skeptic · Delivery

Native Magpie Page Plugin

The native page plugin in magpie-plugin/ follows Magpie's kind: "page" specification:

  • Launcher (magpie-plugin/page/index.html + boot.js): Runs in Magpie's strict CSP sandbox (connect-src 'none', zero inline scripts), negotiates theme/language/options/provider actions over _magpie/bridge.js, and navigates to window.magpie.service (proxied remote magpie web) or http://127.0.0.1:3493/ (with SSH tunnel guidance on older remote setups).
  • Host part (magpie-plugin/index.mjs): OpenCode v1 { id, server } export loaded by Magpie's Bun host. Adopts a running magpie-council ui or spawns and supervises one with stderr draining and bounded backoff restarts.
  • Plugin options (Plugins › Installed › Magpie Council › Options or magpie plugin options):
{
  "port": 3493,
  "binary": "",
  "gatewayUrl": ""
}

Environment Variables

VariableDefaultDescription
MAGPIE_BASE_URLAuto-discoveredExplicit Magpie gateway URL (overrides MAGPIE_ADDR and gateway.json)
MAGPIE_ADDRSet by Magpie hostGateway host:port (auto-inherited inside Magpie's plugin host and sandboxes)
MAGPIE_API_KEY(empty)Optional Magpie gateway API key (for LAN/remote or key-restricted setups)
MAGPIE_COUNCIL_DATA_DIR~/.local/share/magpie-council/sessionsDirectory where session.json, transcript.md, and report.html are stored
MAGPIE_COUNCIL_CONFIG~/.config/magpie-council/config.jsonPersistent user defaults shared by CLI, MCP, and Web UI
MAGPIE_COUNCIL_LANGautoOutput language override (zh or en); takes precedence over config.json
MAGPIE_COUNCIL_ALLOWED_ROOTS(unrestricted)Optional colon-separated allowlist restricting which root directories context_files may read
MAGPIE_COUNCIL_BINAuto-resolvedExplicit path to the magpie-council binary used by magpie-plugin/index.mjs

Data and Security

  • Zero external telemetry or credential storage: magpie-council registers no provider, stores no upstream API keys, and sends zero telemetry. All model inference goes exclusively through your configured Magpie gateway.
  • Zero bridge reads: magpie-plugin/package.json declares "permissions": [] — the sandboxed page reads no private Magpie bridge data.
  • Hardened loopback UI service (127.0.0.1, default 3493 in the plugin / 3497 standalone):
    • Validates loopback Host headers (127.0.0.1, localhost, ::1, *.localhost) to block DNS rebinding.
    • Guards every JSON API, SSE stream, and HTML report route with a 256-bit X-Council-Token (created atomically with 0600 permissions) embedded only in GET / with Cache-Control: no-store and no permissive CORS.
    • Blocks unauthenticated cross-origin and Sec-Fetch-Site: cross-site requests while supporting same-origin magpie web reverse proxying.
    • Sets Referrer-Policy: no-referrer and X-Content-Type-Options: nosniff on responses.
  • Safe server-side file ingestion: context_files opens paths with Unix O_NONBLOCK + regular-file fstat (never blocks on FIFOs/devices), rejects binary NUL files before truncation, trims cleanly on UTF-8 rune boundaries, and resolves symlinks via os.SameFile when MAGPIE_COUNCIL_ALLOWED_ROOTS is set.

Scope & Known Limits

  • Why stdio MCP instead of Magpie's tool hook: Magpie's plugin tool hook enforces a hard 55-second timeout and has no MCP notifications/progress channel. Running the 3 tools through stdio MCP (magpie-council mcp) supports multi-minute deep debates, 12s progress heartbeats, and async: true background sessions without duplicating tools in Magpie Library.
  • Default ports: The page plugin's service defaults to 3493 (3497 is @magpie-community/page-amp-usage, page-window-warmup uses 3492, page-usage-tree 3494, page-harnessweight 3496). The standalone magpie-council ui CLI defaults to 3497; pass --addr or change "port" in Plugin Options if needed.
  • Quota usage: Every debate sends live chat completion requests through your Magpie gateway and consumes the selected provider/account quota.

Project Structure

magpie-council/
├── assets/icon.svg                  # Brand SVG icon (128x128 viewBox)
├── cmd/magpie-council/              # Single-binary CLI / MCP / UI entrypoint
├── internal/
│   ├── config/                      # Shared defaults & MAGPIE_COUNCIL_LANG override
│   ├── debate/                      # 3-phase debate engine, prompts, context_files
│   ├── magpie/                      # Magpie gateway client, route/quota/limit, compat retry
│   ├── mcpserver/                   # Official Go MCP SDK stdio server
│   ├── selector/                    # Quota-pacing model selector & display-name matcher
│   ├── store/                       # Atomic persistence, flock, stat cache, report.html
│   └── webui/                       # Hardened HTTP/SSE server & embedded dashboard.html
├── magpie-plugin/                   # Native Magpie page plugin (index.mjs, page/, registry-entry.json)
├── docs/agent-usage.md              # Mid-session playbook: brief, presets, async, verdict handoff
├── npm/                             # Zero-dependency npx Go binary launcher (SHA-256 verified)
├── skills/magpie-council/SKILL.md   # Canonical agent workflow skill
├── server.json                      # Official MCP Registry manifest
└── PUBLISHING.md                    # Release & Magpie Market publishing guide

Development & Verification

go vet ./...
go test -race -count=3 ./...
go build -o ./bin/magpie-council ./cmd/magpie-council
node --check magpie-plugin/index.mjs magpie-plugin/page/boot.js npm/bin/magpie-council.js

See PUBLISHING.md for GoReleaser, npm launcher, Official MCP Registry (server.json), magpie library plugin import, npx skills add, and magpie-community/plugins submission steps.

License

MIT © 2026 magpie-council contributors. See LICENSE.

NPM
magpie-council
Install Command
npm install magpie-council