mcp-brain
Enables multi-agent cognitive processing for complex tasks using a pipeline of Analyst, Creator, and Critic agents, running locally via MiniMax API.
README
MCP-Brain: Multi-agent Cognitive Processing Framework
A lightweight AI framework that runs locally on your machine using MiniMax API. Three specialized agents — Analyst, Creator, and Critic — collaborate through a structured cognitive pipeline to solve complex problems.
User Task
│
▼
┌──────────┐ Analyst breaks it down
│ Analyst ├─────────────────────────┐
└──────────┘ │
│ │
▼ │
┌──────────┐ Creator drafts ┌──────────┐
│ Creator │◄──────────────────┤ Analyst │
└──────────┘ │ Context │
│ └──────────┘
│ │
▼ │
┌──────────┐ Critic evaluates ┌──────────┐
│ Critic │◄────────────────────┤ Creator │
└──────────┘ │ Draft │
│ └──────────┘
│ │
▼ │
┌──────────┐ Creator improves ┌──────────┐
│ Creator │◄────────────────────┤ Critic │
└──────────┘ │ Feedback │
│ └──────────┘
│
▼
┌──────────┐ Critic final ┌──────────┐
│ Critic │◄──────eval─────────│ Improved │
└──────────┘ │ Solution │
│ └──────────┘
▼
Final Solution + Evaluation
Features
- Local-only — API key and data never leave your machine
- Multi-agent cognition — mimics human collaborative problem-solving
- Persistent memory — sessions saved to
~/.mcp/for review - Simple CLI —
mcp setup,mcp process,mcp sessions - Streaming support — stream responses token-by-token
- OpenAI-compatible HTTP server — use as a drop-in LLM provider for any OpenAI client
- Hermes integration — works as both an MCP tool server and a full LLM provider
Installation
# Install from PyPI
pip install mcp-brain
# Or install with pipx (recommended on Ubuntu)
pipx install mcp-brain
# Or install from source
git clone https://github.com/MC80s/mcp.git
cd mcp
pip install -e .
Quick Start
# 1. Configure your MiniMax API key
mcp setup
# 2. Process your first task
mcp process "Design a logo for a tech startup called Quantum Leap"
# 3. View previous sessions
mcp sessions
# 4. Check config status
mcp status
How It Works
| Step | Agent | Role |
|---|---|---|
| 1 | Analyst | Breaks down the problem into components |
| 2 | Creator | Generates an initial creative solution |
| 3 | Critic | Evaluates the draft, identifies flaws |
| 4 | Creator | Improves the solution based on critique |
| 5 | Critic | Final evaluation and rating |
Cost Estimation
MiniMax API is pay-per-use. Each task runs 5 agent calls.
| Complexity | Est. Cost |
|---|---|
| Simple task | ~$0.02–0.05 |
| Medium task | ~$0.05–0.15 |
| Complex task | ~$0.15–0.30 |
No subscription fees. You control your usage.
Project Structure
mcp-brain/
├── src/mcpbrain/
│ ├── minimax_client.py # MiniMax API client
│ ├── agents.py # Creator/Critic/Analyst agents
│ ├── memory.py # Working memory
│ ├── mcp_core.py # Orchestration engine
│ ├── http_server.py # OpenAI-compatible HTTP server
│ ├── server.py # MCP stdio server
│ ├── tools.py # Local tool registry
│ └── cli.py # CLI commands
├── scripts/
├── tests/
├── setup.py
├── pyproject.toml
├── install.sh
└── README.md
CLI Commands
mcp setup Interactively configure API key
mcp process "task" Run a task through the cognitive pipeline
mcp sessions List recent sessions
mcp session <id> View full session details
mcp status Check configuration
HTTP Server (OpenAI-compatible)
The HTTP server exposes POST /v1/chat/completions in OpenAI format, making mcp-brain usable as a drop-in LLM provider for any OpenAI-compatible client.
Two Routing Modes
Mode 1: Passthrough (tools present) — When the request includes tools or functions, the cognitive pipeline is bypassed. The full messages array is forwarded directly to MiniMax with the tool definitions. The LLM decides whether to call a tool or respond with text. This is the mode used by Hermes agent integration.
Mode 2: Cognitive Pipeline (no tools) — When no tools are present, the full adaptive pipeline runs. Tasks are classified as SIMPLE (1 step), MODERATE (2 steps), or COMPLEX (5 steps) and routed accordingly.
Starting the server
# Auto-start on boot (systemd user service)
systemctl --user enable mcp-brain-http
systemctl --user start mcp-brain-http
# Or run manually
mcp-brain-http --port 8080
systemd user service
# ~/.config/systemd/user/mcp-brain-http.service
[Unit]
Description=MCP Brain HTTP Server (OpenAI-compatible)
After=network.target
[Service]
ExecStart=/home/YOUR_USERNAME/.local/share/pipx/venvs/mcp-brain/bin/mcp-brain-http --host 127.0.0.1 --port 8080
Restart=always
RestartSec=10
[Install]
WantedBy=default.target
Verify
curl http://127.0.0.1:8080/health # {"status":"ok"}
curl http://127.0.0.1:8080/v1/models # {"object":"list","data":[{"id":"mcp-brain",...}]}
Test a completion
curl -X POST http://127.0.0.1:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"mcp-brain","messages":[{"role":"user","content":"What is 2+2?"}],"stream":false}'
Hermes Integration
mcp-brain integrates with Hermes in two ways:
Option A — MCP Tool Server (manual invocation)
Connect mcp-brain as a native MCP tool server. Hermes can delegate complex reasoning tasks to the multi-agent pipeline by calling the process_task tool.
# ~/.hermes/config.yaml
mcp_servers:
mcp-brain:
command: "/home/YOUR_USERNAME/.local/bin/mcp-brain-server"
Option B — Full LLM Provider (recommended, automatic)
Route all LLM conversations through the cognitive pipeline. Every message goes through the adaptive multi-agent architecture automatically.
# ~/.hermes/config.yaml
custom_providers:
- name: "mcp-brain"
base_url: "http://127.0.0.1:8080/v1"
api_key: "local" # any value — the server ignores it
provider: "openai" # OpenAI-compatible endpoint
Why Option B: With Option A, you manually invoke mcp-brain tools. With Option B, every conversation automatically benefits from the cognitive pipeline — no explicit invocation needed.
Configuration
Config file: ~/.mcp/config.json
{
"api_key": "...",
"model": "MiniMax-M2.7",
"max_tokens": 2000,
"temperature": 0.7
}
Run setup: mcp setup
Important: MiniMax API base URL is https://api.minimax.io/v1 (NOT .chat — that returns 401 on everything).
Working model names: MiniMax-M2.7, MiniMax-M2, MiniMax-M2.5.
Changelog
v0.9.2 (2026-04-26)
_read_code_files: fair per-file budget — pre-calculates equal allocation across all discovered files instead of sequential-first-wins. Prevents large files from starving subsequent files in the context window._classify_task:code_pattern_confidencenow factored into return confidence viamax(); strong pattern-only matches return MODERATE instead of UNKNOWN.find_code_patterns: Jaccard threshold raised fromscore > 0toscore >= 0.15(matches threshold already used in_classify_task).record_pattern: deduplication window expanded frompatterns[-50:]topatterns[-200:]to match retention limit._STOPWORDS: removed"file","files","code","mcp","brain"— too generic for a code-analysis fingerprinting system.
v0.7.4 — Tool Schema Fix + Memory Error Handling
- Tool schema normalization:
TOOL_REGISTRY.list()returned flat{name, description, parameters}dicts but MiniMax API expects{type:'function', function:{...}}. Added_normalize_to_api_format()to wrap schemas. This fixed "invalid tool type (2013)" errors and enabled tool execution. - Passthrough error handling:
_stream_passthroughhad no try/except while_stream_pipelinedid. Uncaught exceptions now yield SSE error chunk instead of crashing the FastAPI route. - memory.py error handling:
mkdir()in__init__,json.dump()TypeError insave(), andPermissionError/OSErrorinload()are now all caught.
Changelog
v0.9.2 (2026-04-26)
_read_code_files: fair per-file budget — pre-calculates equal allocation across all discovered files instead of sequential-first-wins. Prevents large files from starving subsequent files in the context window._classify_task:code_pattern_confidencenow factored into return confidence viamax(); strong pattern-only matches return MODERATE instead of UNKNOWN.find_code_patterns: Jaccard threshold raised fromscore > 0toscore >= 0.15(matches threshold already used in_classify_task).record_pattern: deduplication window expanded frompatterns[-50:]topatterns[-200:]to match retention limit._STOPWORDS: removed"file","files","code","mcp","brain"— too generic for a code-analysis fingerprinting system.
v0.9.1 — Closed Learning Loop: Code-Change Patterns
- PatternExtractor: auto-extracts reusable code-change patterns from every successful session into
~/.mcp/learned/code_patterns.json(last 200). Classifies as refactor/fix/feature/audit/optimize. Extracts file paths, code snippets, and pattern summaries. - Auto-extraction:
_auto_record_pattern()fires at every pipeline completion (SIMPLE/MODERATE/COMPLEX). Also fires inreport_outcome()for explicit feedback. - Route-time matching:
_classify_task()looks up similar code patterns by Jaccard fingerprint and injects[CODE PATTERN: prior fix on file.py — snippet: ...]into the Analyst prompt. - Pattern stored as
CodeChangePatternnamedtuple with deduplication by (pattern_summary, task_keywords).
v0.9.0 — Learned-Data Routing + Code Audit Fixes
- New
_classify_task()method: pre-classifies task using heuristics + learned history before Analyst runs. Combines similarity score, recency decay (30-day half-life), and outcome bonus into a weighted complexity prediction. High-confidence (>=0.85) SIMPLE seedscomplexity_detectedearly and injects "answer directly" hint into the prompt. - Now actively uses
~/.mcp/learned/: routing is informed by past session outcomes instead of just storing them agents.py: remove unusedlog,app_logimports; add try-except aroundjson.dumps(tool_result)to prevent crashes from non-serializable tool results; fix misleadingelse: breakcomment on async-for; remove deadprocess_streammethod (never called anywhere)tools.py:_read_fileusesitertools.islicefor O(1) memory instead of loading full file then slicing;_skill_viewaddsis_file()check and 500KB size cap;_web_searchcheckscurlreturncode before claiming success;_write_fileremoves redundant hardcoded/home/mc411path check
v0.8.9 — agents.py + tools.py Audit Fixes
agents.py: remove unusedlog,app_logimports; add try-except aroundjson.dumps(tool_result); fix misleadingelse: breakcomment; remove deadprocess_streammethodtools.py:_read_fileO(1) memory viaislice;_skill_viewsize cap +is_file()check;_web_searchreturncode check;_write_fileredundant path removal
v0.8.8 — http_server.py Audit Fixes
- Removed unused
MiniMaxAPIError,MiniMaxRateLimitErrorimports _build_token_chunk()now takes resolved model name instead of hardcoded"mcp-brain"- Added
get_api_key()startup-cached helper — eliminates per-request disk I/O on/healthand/ready - Fixed correlation ID reuse: endpoint now uses
getattr(request.state, 'correlation_id', None) or new_correlation_id()instead of always overwriting - Fixed
_extract_user_message()to handle OpenAI list content blocks ([{"type": "text", "text": "..."}]) - Fixed error chunk schema in
_stream_passthrough— now uses properchoices[0].errornested object - Fixed error chunk schema in
_stream_pipeline— same - Removed dead
done_resultvariable (assigned on everydoneevent but never consumed) /healthand/readyendpoints simplified to use cachedget_api_key()
v0.8.7 — Dead Code Purge + Bare-Filename Extraction
- Added
_BARE_CODE_FILE_PATTERNregex — matchesmcp_core.pystyle bare filenames in addition to slash-prefixed paths _read_code_files()now resolves bare filenames relative to package source directory when cwd doesn't matchexploration_noterenamed toanalyst_exploration_note— only Analyst agent receives the mandatory exploration directive; Creator and Critic no longer get redundant injection- Removed
_llm_tool_dispatch(~40 lines) — dead code with latentimport requestsin unreachable try block - Removed
_parse_local_tool(~55 lines) — phrasal tool patterns (run 'command', read "file"), never called - Removed
_parse_tool_invocation(~25 lines) — slash-command parser, never called - Removed
_run_step(~6 lines) — legacy blocking helper, dead session_identropy doubled:str(uuid.uuid4())[:8]→[:16](2¹²⁸ vs 2³²)
v0.8.6 — MCP-Brain Found 4 Real Bugs
- MCP-brain identified and fixed real bugs in its own codebase using the two-phase pipeline
- Fixed
_write_filein tools.py: inconsistent path check (str(p).startswith("/tmp/")vsis_relative_to()) - Fixed
report_outcomein mcp_core.py: saved staleresultdict instead ofupdated— feedback fields were lost on re-save - Fixed
_find_result_on_disk: returned first matching file instead of latest by mtime - Fixed
_save_session_log: usedself.session_idfor filename instead ofresult["session_id"]
v0.8.5 — Hallucination Fix + Tool Call ID Format
- Two-phase pipeline: mandatory exploration phase forces agent to call
read_filebefore generating analysis — eliminates hallucination for code reference tasks analyst_exploration_noteinjected when_extract_file_paths()finds file references- Tool call ID format changed from
call_0_0tocall_{round:02d}_{index:04d}(MiniMax compatible) - Tool call arguments now use
{"function": {"name": ..., "arguments": json.dumps(...)}}structure - Analyst persona: code review tasks always route as MODERATE+
- Analyst
max_tokensbumped to 12000, Creator to 4000 report_outcomerace condition fixed: atomic RMW withself.__class__._results_lock
v0.8.4 — Version Bump Fix
- Fixed version string mismatch: local files at 0.8.2, GitHub Actions build at 0.8.3 — bump silently failed in prior session
- Bumped to 0.8.4 and published to PyPI
v0.8.3 — Same pipx Venv Issue
- pipx venv not updated with editable install — same issue as v0.8.2
v0.8.2 — pipx Venv Path Mismatch
- pipx venv at
~/.local/share/pipx/venvs/mcp-brain/lib/python3.12/site-packages/mcpbrain/was not updated after code changes - Fixed: must run
pipx install ~/mcp-work --forceafter every edit to update the venv
v0.8.1 — Streamlit Dashboard
- Added tab 10: Debate Log — view AI debate transcripts from completed sessions
- Added tab 12: Philosophy Mode — reasoning trace visualization
v0.8.0 — Learning Loop
SessionIndex— fingerprints tasks by keywords, finds similar past sessions (Jaccard similarity >= 0.2)LearnedMemory— stores outcome patterns (success/partial/failed) with ratingsreport_outcome(session_id, outcome, rating, notes)— record feedback for a session~/.mcp/learned/patterns.json— outcome records~/.mcp/learned/session_index.json— session metadata with fingerprints~/.mcp/learned/heuristics.json— extracted heuristics from successful solutions- Similar sessions and patterns injected into Analyst context on every new task
mcp feedback <session_id> <outcome> [rating]CLI command for recording outcomesmcp learnedCLI command to view learned patterns
v0.7.x — See Architecture section above
v0.7.2 through v0.7.5 were minor fixes: version string cleanup, MiniMax reasoning tag leakage, unified _filter_think_tags() helper for streaming and non-streaming paths, file corruption修复.
v0.7.0 — Async Architecture
httpx.AsyncClientreplacesrequests— true async streaming, connection pooling (100 max connections)structlogfor structured logging with correlation IDsgenerate_stream()andgenerate_stream_from_messages()with retry/backoff/ready(readiness probe) and/metrics(Prometheus-compatible) endpointsget_shared_client()singleton — reused across HTTP requests- Think-tag filter (
_make_think_filter()) applied to pipeline mode - Graceful shutdown with
aclose()
v0.6.5 — Streaming Think Tag Fix
- Streaming responses now strip
<think>and<tool_call>reasoning blocks from token stream - State machine (
_process_token) handles the stripping during streaming re.sub()stripping added for non-streaming responses
v0.6.4 — Streaming Bug Fixes
- Fixed streaming: each chunk is yielded separately instead of buffered
- Non-streaming:
_strip_reasoning_tags()now runs on full response before returning
v0.6.3 — Passthrough Mode Think Tag Fix
- Think tags (
<think>...</think>) were leaking into passthrough responses — stripped withre.sub() - Both
<tool_call>think>and<thinking>tag variants handled
v0.6.2 — Passthrough max_tokens Fix
- Fixed
max_tokenshardcoded to 2000 in passthrough mode — now reads from request body (default 4096)
v0.6.1 — Passthrough Mode
- When
toolsare present in the request, the cognitive pipeline is bypassed and messages are forwarded directly to MiniMax API
v0.6.0 — Native Tool Calling
- Removed regex interceptors for tool invocations — tools passed directly to MiniMax API
Privacy
- All API calls go directly from your machine to MiniMax
- No intermediary servers
- Session logs stored locally in
~/.mcp/logs/ - Your API key stored in
~/.mcp/config.json(keep this file private)
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.