Discover MCPs & agents
Loading MCPs and agents…
Loading MCPs and agents…
Dispatch AI coding agents (Claude Code, Copilot, OpenCode) as MCP tools - with resumable sessions, a cost ledger, admission and work-jail guards, and zikr + auditor skills against drift
Fetched from the repository for this visit.
Dispatch AI coding agents as MCP tools. Hand work to Claude Code, the GitHub Copilot CLI or OpenCode from any MCP client (Claude Desktop, Claude Code, your own orchestrator) and get it back as background jobs you can poll, continue, and account for.
You (MCP client)
|-- forge_dispatch("claude_code", "add retries to the HTTP client", cwd, multi_turn=True)
| -> job_id "forge-1a2b3c4d", runs in the background
|-- forge_status("forge-1a2b3c4d") -> "completed", the final answer, cost, tokens
|-- forge_resume("forge-1a2b3c4d", "now add a test for the timeout path")
|-- forge_cost_report(group_by="model") -> what each model actually cost
v3 is a rewrite around what long-running use taught: jobs that can be resumed after a correction, profiles so the right subscription pays, a cost ledger that survives restarts, a resource guard that won't start a job on a machine that's out of memory, a work jail that limits where agents can write, and a thread index so an agent can look up what you actually said instead of trusting its own summary. See CHANGELOG.md.
Requirements: Python 3.10+, and at least one agent CLI.
pip install git+https://github.com/Cloud-Eye-Prime/mcp-agent-forge.git
# or, from a checkout: pip install -e ".[dev]"
The pip package ships the server (forge_mcp) only. The thread index (tools/), the skills (skills/) and the docs (docs/) live in the repository: clone it, or copy those files into your project.
Agent CLIs (install the ones you want):
npm install -g @anthropic-ai/claude-code # Claude Code -- log in once with: claude
npm install -g @github/copilot # GitHub Copilot CLI (optional)
npm install -g opencode-ai # OpenCode (optional; dispatch needs `opencode serve --port 4096`)
The one required setting is FORGE_WORK_ROOTS: the directories agents may work in. Until it is set, every dispatch is refused.
{
"mcpServers": {
"agent-forge": {
"command": "mcp-agent-forge",
"env": {
"FORGE_WORK_ROOTS": "/home/you/projects"
}
}
}
}
Separate several roots with : (Linux, macOS) or ; (Windows). From a checkout without installing, use "command": "python", "args": ["/path/to/mcp-agent-forge/server.py"]. More in examples/.
Then ask your client to call forge_agents to see what is installed and how the forge is configured.
| Tool | What it does |
|---|---|
forge_agents | Which agent CLIs are installed; profiles, work roots, model aliases, ledger location. Call first. |
forge_dispatch | Start an agent in the background; returns a job_id at once. |
forge_status | A job's state: live log tail while running, the final answer when done. |
forge_list | Every job since the server started. |
forge_run | Dispatch and wait for the result (blocking; for short jobs). |
forge_resume | Continue a multi_turn Claude Code job with its context intact (and its restrictions). |
forge_sessions | The threads that can be resumed, newest first, with their profile. |
forge_profiles | The configured Claude Code profiles; verify=True checks each login. |
forge_cost_report | Spend, tokens, refusals and timeouts from the ledger, grouped. |
forge_plan | Preview a Bounded Plan (the constrained prompt). Starts nothing. |
forge_dispatch_plan | Dispatch with a Bounded Plan. |
forge_hand_report | Read a delegated agent's work from its git branch, not its own summary. |
forge_dispatch arguments: agent (claude_code, copilot, opencode), task, cwd, and optionally mode (execute, plan, review, validate), profile, model, effort, multi_turn, timeout (30-1800 s; up to 3600 with multi_turn), label, append_system_prompt, max_budget_usd, allowed_tools, admission_override. Every tool returns JSON.
A dispatch is one-shot by default: it leaves no session behind. Pass multi_turn=True when you expect to send a correction or a next phase:
forge_dispatch("claude_code", "Implement the parser in src/parse.py; write PLAN.md first", cwd, multi_turn=True, label="parser")
forge_resume("forge-1a2b3c4d", "PLAN.md step 3 is wrong: keep the old API. Continue.")
forge_sessions(label="parser") # -> "parser", "parser #2", ...
Send the correction or next phase, not the context again: the agent still has it and can read files and git history itself. Have each phase write an artefact and the next one read it. A resumed turn reuses the original job's profile and model (model overridable per turn). The session is found in the ledger, so resume works after the server restarts.
With more than one Claude subscription (personal and work, say), each needs its own config home: its own login, sessions and rate-limit window. Name them:
FORGE_PROFILE_WORK=/home/you/.claude-work # a profile called "work"
FORGE_EMAIL_WORK=you@company.example # optional: the login it must hold
FORGE_DEFAULT_PROFILE=work # optional: used when a dispatch names none
default always exists and means the CLI's own home (~/.claude). Log a new profile in once with CLAUDE_CONFIG_DIR=/home/you/.claude-work claude auth login.
Before each Claude Code job the forge runs claude auth status in that profile's home and refuses the job when the profile is not logged in, is authenticated by an API key (per-token billing, not the subscription), or holds a different account from the pinned email. An unknown profile name is refused, never quietly replaced by the default. There is no API-key mode: unset ANTHROPIC_API_KEY in the server's environment. One deliberate soft edge: if claude auth status cannot be run or does not answer JSON, the job is allowed and its status says "not verified" (a guard that blocked every job whenever the check was slow would be switched off). Profiles apply to Claude Code only.
model takes a full model id or an alias: opus, sonnet, haiku, fable. Override or add aliases without a code change: FORGE_ALIAS_OPUS=<model id>, FORGE_ALIAS_FAST=<model id>. With no model the CLI's default applies, unless FORGE_DEFAULT_MODEL is set.
effort (Claude Code) is passed to claude --effort: low, medium, high, xhigh, max. An unknown level is refused before the job starts.
Every job, whatever the agent, writes one row to an append-only JSONL ledger once it reaches a terminal status (completed, failed, timeout, cancelled): profile, the model the CLI reports it ran, effort, mode, cost, input/output/cache tokens, turns, duration, stop reason. A timed-out stream still records the tokens its messages used (usage_source: "assistant_partial"). The row is written by the server when the job ends: a job still running when the server is killed leaves no row (and cannot be resumed through the ledger).
forge_cost_report(group_by="model") # or profile, effort, mode, stop_reason, label, agent, status
forge_cost_report(group_by="effort", model="opus")
Each group has runs, cost, average cost, tokens, refusals and refusal rate, errors, timeouts. Tokens are reported beside dollars because two models at the same price differ only in how many tokens they use.
The ledger and per-job logs live in ~/.mcp-agent-forge/ (FORGE_STATE_DIR, or FORGE_LEDGER_PATH for the ledger alone).
A new job is refused, with nothing started, while:
| Reading | Refuses when | Variable (default) |
|---|---|---|
| Free RAM | under the limit | FORGE_MIN_RAM_FREE_MB (3000) |
| Free commit (Windows) | under the limit | FORGE_MIN_COMMIT_FREE_MB (2000) |
| CPU, ~5 min average | over the limit | FORGE_MAX_CPU_PCT (85) |
| Battery, when discharging | under the limit | FORGE_BATTERY_MIN_PCT (30) |
Readings come from Win32 calls on Windows and /proc and /sys on Linux; elsewhere they are reported as unmeasured. A probe that fails never blocks work: the job starts and the result says what was unmeasured. Pass admission_override=True to start anyway; the result says it was overridden.
FORGE_WORK_ROOTS lists the directories agents may be aimed at. A cwd outside them, or a symlink that resolves outside them, is refused, and so is any dispatch while the variable is unset. The jail limits blast radius. It does not judge intent: a task that needs a path outside the roots is a task a person should look at. The jail decides where an agent starts; it is not a sandbox. An agent with full tools can still reach an absolute path elsewhere, so pair the jail with allowed_tools (or an OS-level sandbox or container) when that matters.
Agents background things: test runners, watch processes, subagents. On Windows each Claude Code and Copilot job runs inside a Job Object. When the job ends, anything still alive in its process tree is logged (pid and MB) to the job log and terminated, so orphans don't pile up. On other platforms the agent process itself is killed when its job ends or is cancelled, but processes it started in the background are not tracked. The CLI's own wait for background work (CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS) is set from the job's timeout, so finished background work is collected before the forge ends the job.
When you delegate to an agent that pushes to a branch, its summary is a claim. forge_hand_report(branch, repo) (or python -m forge_mcp.hand_report <branch> --repo <owner>/<repo>) reads the branch through the GitHub CLI and returns evidence: does it exist, commits ahead, diffstat, and whether a test summary such as "42 passed" appears in the commit messages. If it cannot look (no gh, not authenticated, repository not found) it says so as an error. That is never reported as "no work". It proves work exists, not that the work is right; that still needs a reviewer.
forge_plan("Add error handling to the API routes", max_files=3,
allowed_paths=["src/routes/*.py"], no_touch=["src/auth.py", ".env"],
verification=["python -m pytest tests/routes"])
forge_dispatch_plan("claude_code", <same arguments>, cwd=...)
The agent receives the task rewritten with the limits and checks. A plan is a contract stated to the agent, not a sandbox. Where the limits must hold, combine it with allowed_tools, the work jail, and a review of the diff.
Long sessions get compacted, and a summary keeps conclusions but drops sources. tools/thread_index.py indexes your Claude Code transcripts (~/.claude/projects by default) into SQLite full-text search, so an agent can look up what was actually said.
python tools/thread_index.py ingest # resumable; only new bytes are read
python tools/thread_index.py query "words you would have used"
python tools/thread_index.py show 1234 # the whole turn: your words, the reply, tools, commits
python tools/thread_index.py rulings --since 2026-01-01 # turns that set direction
python tools/thread_index.py state --repo ~/projects/app # a one-page STATE.md
Settings: --projects / THREAD_INDEX_PROJECTS (transcript roots), --db / THREAD_INDEX_DB (default ~/.thread-index/index.sqlite), THREAD_INDEX_REPOS (repos for state). Secret-shaped strings (common API-key and token formats, NAME=value credentials, passwords in scheme://user:pass@ URLs, --password values, PEM private keys) are scrubbed before anything is stored. The scrub is pattern-based, not a guarantee; scan-secrets counts rows the current scrub would still change, and rescrub fixes them after a backup. Stdlib only. The index never leaves your machine.
Fresh after every turn: install the optional Stop hook (tools/thread_index_hook.py), which indexes each turn as it ends and always exits 0 so it can never block a turn. Add to ~/.claude/settings.json (see examples/claude-settings-stop-hook.json):
{"hooks": {"Stop": [{"hooks": [{"type": "command",
"command": "python /path/to/mcp-agent-forge/tools/thread_index_hook.py", "timeout": 20}]}]}}
The practice: skills/zikr/SKILL.md is a skill for the agent. Query the index at four moments: before saying "I can't find it"; when your memory and the agent's differ; before a decision that may repeat or contradict a past ruling; and right after a compaction. Cite the turn and date, then re-verify the present before acting. Copy the folder into ~/.claude/skills/ (or your project's .claude/skills/) to install it.
On a long project, requests fall out of view: never done, done narrower than asked, or quietly pushed back. skills/auditor/SKILL.md sets up a queue auditor: a read-only forge agent that keeps a ledger of your own words, audits at stage boundaries against the queue and the actual commits, and writes findings ranked HIGH, MED and LOW. Each audit is a fresh session whose memory lives in files, because a long resumed thread grows costly and drifts. It never edits code and never dispatches. Any deprioritized request needs your quoted approval.
docs/ANTI_DRIFT_LOOP.md runs zikr and the auditor together under Claude Code's /loop. On each tick the orchestrator returns to your words at the four moments and checks its jobs; at each stage boundary it runs a fresh audit and acts on HIGH findings first. The guide includes a worked /loop prompt, wake cadence advice, and a stop rule.
| Variable | Purpose |
|---|---|
FORGE_WORK_ROOTS | Required. Directories agents may work in. |
FORGE_PROFILE_<NAME> / FORGE_EMAIL_<NAME> | A Claude Code profile's config home / pinned login. |
FORGE_DEFAULT_PROFILE | Profile used when none is named (default default). |
FORGE_DEFAULT_MODEL, FORGE_ALIAS_<NAME> | Default Claude model; model aliases. |
FORGE_STATE_DIR, FORGE_LEDGER_PATH | Where the ledger and job logs live. |
FORGE_MIN_RAM_FREE_MB, FORGE_MIN_COMMIT_FREE_MB, FORGE_MAX_CPU_PCT, FORGE_BATTERY_MIN_PCT | Resource guard thresholds. |
FORGE_CLAUDE_BIN, FORGE_COPILOT_BIN, FORGE_OPENCODE_BIN | Pin an agent CLI's path. |
OPENCODE_SERVER_URL, OPENCODE_DEFAULT_MODEL | OpenCode server (default http://127.0.0.1:4096) and model. |
THREAD_INDEX_PROJECTS, THREAD_INDEX_DB, THREAD_INDEX_REPOS | Thread index locations. |
allowed_tools, Claude Code runs with --dangerously-skip-permissions and Copilot with --allow-all-tools, inside cwd. The work jail limits where; use allowed_tools (e.g. ["Read", "Grep"]) for read-only work and review diffs before merging. mode="plan" and mode="review" only instruct the agent not to change files; they do not restrict its tools. A resumed turn keeps the thread's allowed_tools, budget, system prompt and mode.opencode serve process, in that server's own directory; the forge checks cwd and names it in the prompt but cannot confine the agent to it, and a forge timeout does not stop work the server has already started. Start opencode serve inside a work root.pip install -e ".[dev]"
python -m pytest
The suite uses a fake claude CLI (tests/fake_claude.py) to exercise the worker end to end, so no agent or account is needed. tests/test_scrub.py fails if personal paths, hosts, key-shaped strings or UUIDs enter the repo.
MIT. See LICENSE.
Built by Cloud-Eye Prime.
GitHub checked 16h ago - refresh overdue. Recently viewed repositories target hourly refresh.