mcp-delegate
mcp-delegate
Claude Code(オーケストレーター)に、別のモデル(Ollama経由のローカル、またはOpenRouter経由のリモート)で実行される独立した完全なエージェントループへタスクを委任するツールを提供するMCPサーバー。独自のツールアクセス(ファイル、bashなど)を持ち、最終結果のみを返す——機能的にはネイティブのサブエージェントと同等だが、モデルに依存しない。
完全なビルド計画は mcp-subagent-delegation-plan.md を参照。個別のコミット/チェックポイントとして段階的に分かれている。
Status
フェーズ1、2、3、4が完了。
delegate_task— 設定済みのOpenAI互換エンドポイント(Ollama、LM Studio、vLLM、OpenRouterなど)に対する単発のチャット補完。delegate_agentic_task— 委任されたモデルに、呼び出し元が指定した作業ディレクトリにスコープされた独自のツール使用ループ(read_file、write_file、run_bash)を提供する。ツールの呼び出しを停止するか、max_iterationsに達するか、timeout_secondsを超えるまで実行される。list_recent_delegations— 過去の委任(どちらのツールでも)が実際に何をしたかを、ログを掘り返したり再実行したりせずに確認する。get_delegation_transcript—capture_transcript=Trueで実行された場合の、1回の委任の完全なメッセージ/ツール呼び出しトランスクリプト(例:モデル比較/評価実行用)。
元の計画からの逸脱: フェーズ2では agent-loop をサブプロセスとしてラップする予定だった。agent-loopはLinux/macOS/WSLのみをサポートしており、このサーバーはWindows上でネイティブに動作する必要があるため、代わりにフェーズ5の代替案として説明されているインプロセスループを構築した——同じツールインターフェースで、サブプロセス/ANSIストリッピングの複雑さがなく、agent-loopのAGPL/商用不可ライセンスを完全に回避できる。delegate/agentic.py を参照。
安全性に関する注意: working_dir は呼び出し元が指定するものであり、固定されたサンドボックスではない——委任されたモデルは、指定されたディレクトリに対して無人でファイル/bashアクセスができる。ファイルツール(read_file/write_file)は working_dir 内に留まるようにスコープされている。run_bash はそのディレクトリを cwd として実行されるが、シェルコマンドは完全にはサンドボックス化されておらず、そこから逃げ出せる可能性がある(例:cd ..)。無人モデルが読み取り、書き込み、コマンド実行を行っても問題ないディレクトリを指定すること。
ガードレールに関する注意: 元の計画のフェーズ4では、agent-loop自身のガードレール(反復上限、繰り返し検出)が有効であることを確認するよう求めていた。agent-loopを使用していないため、これは直接には適用されない——我々のループには独自の max_iterations と timeout_seconds の上限(テストで検証済み)があるが、繰り返し検出はない。2つのツール呼び出しを交互に繰り返してスタックしたモデルは、早期に検出されるのではなく max_iterations に達するまで実行される。実際にそのような事態が発生するようなら追加する価値がある。
Related MCP server: deepseek-subagent-mcp
Setup
uv sync
cp .env.example .env # fill in DELEGATE_BASE_URL / DELEGATE_API_KEY / DELEGATE_MODEL
cp models.json.example models.json # optional: named backends, see belowMultiple backends
両方のツールはオプションの backend パラメータを受け取り、デフォルトの DELEGATE_* 環境変数の代わりに models.json から base_url/model/api_key を参照する——例えば、同じターン内で一方の呼び出しに backend="ollama-local"、もう一方に backend="openrouter-free" を指定し、それぞれを並行して実行できる。model も指定された場合は、そのバックエンド内のモデル文字列のみを上書きする。
キーを models.json に直接書く代わりに、環境変数を参照する:
{
"openrouter-free": {
"base_url": "https://openrouter.ai/api/v1",
"model": "nvidia/nemotron-nano-9b-v2:free",
"api_key_env": "OPENROUTER_API_KEY"
}
}models.json は .env と同じくgitignoreされている。
Concurrency
MCPツール呼び出しはすでに個別のワーカースレッドで実行されるため、追加の配管なしで並行委任が並列実行される。DELEGATE_MAX_CONCURRENCY(デフォルト4、.env.example を参照)は、両方のツール、任意のバックエンドにわたって同時に実行される委任の数を制限し、大規模なファンアウトがローカルモデルサーバーや有料APIのレート制限を圧迫するのを防ぐ。
サーバーを直接実行する(主にエラーなく起動するかを確認するのに有用——その後、MCPクライアントのためにstdioで待機する):
uv run server.pyLogging
delegate_task/delegate_agentic_task のすべての呼び出し——成功か失敗かに関わらず——はローカルのSQLiteファイル delegations.db(gitignoreされ、初回使用時に作成)に記録される: ツール、バックエンド、モデル、タスクテキスト、開始/終了時刻、反復回数、成功/失敗、切り詰められた結果/エラープレビュー、およびバックエンドが返した場合はトークン使用量。list_recent_delegations ツールで照会するか、sqlite3 delegations.db "select * from delegations order by id desc limit 20" で直接照会できる。ロギングはベストエフォートであり——ロギングの失敗で、それ以外は成功した委任が失敗することはない。
両方のツールは、バックエンドが使用量を報告した場合、戻り値の末尾に [tokens: N prompt / N completion / N total ($cost)] の行を追加する。これにより、呼び出し元のエージェントは別途 list_recent_delegations を呼び出さなくてもすぐに確認できる。
Cost tracking
pricing.json はモデル文字列 → {input_per_million, output_per_million} のUSDレートをマッピングする。呼び出しの解決されたモデルにエントリがある場合、コストは実際のトークン使用量から計算され、delegations.db(cost_usd カラム)に記録され、[tokens: ...] サフィックスに含まれる。エントリがないモデルは cost_usd = NULL が記録される——無料と見なすのではなく不明として——つまり、エントリの欠落が支出を黙って過小報告することはない。ローカルモデルは通常その理由でエントリを持たない。本当に無料のモデル(例:OpenRouterの :free モデル)は、省略される代わりに明示的な {"input_per_million": 0, "output_per_million": 0} エントリが与えられる。
.env/models.json とは異なり、pricing.json は秘密情報でも環境固有でもないため、gitignoreされるのではなく直接コミットされる。価格は変動する——同梱のファイルは、これが構築されたモデル比較ベイクオフで指定されたモデルについて、2026-08-21にOpenRouterの /api/v1/models から取得されたもの。必要に応じて再取得して編集し、モデルを追加/更新すること。
Transcript capture (model comparison / eval runs)
両方のツールは capture_transcript: bool = False を受け取る。設定すると、最終回答だけでなく、すべてのモデルメッセージ、ツール呼び出し、ツール結果を含む完全なメッセージ交換が記録され、戻り値に [delegation_id: N] サフィックスが付く。get_delegation_transcript(delegation_id) で取得できる。
これは、同じタスクを複数の異なるモデル/バックエンドで実行し、最終回答だけでなく各モデルがどのようにそこに到達したか(ツール選択、不正な形式のツール呼び出し、リトライ)を比較するために存在する——例えば、本番使用のために1つを選ぶ前に候補モデル間でベイクオフを行う場合など。通常の委任には不要な追加のロギングオーバーヘッドであるため、デフォルトではオフ。
Register with Claude Code
プロジェクトスコープの .mcp.json はすでにチェックインされている(uv run server.py)。このディレクトリでClaude Codeを再起動するか、claude mcp list を実行して delegate サーバーが認識されたことを確認し、次に簡単なプロンプトで delegate_task を呼び出すよう依頼してラウンドトリップを確認する。
Tools
delegate_task(prompt, model=None, system_prompt=None, backend=None, capture_transcript=False) -> str— 設定済みバックエンドに対する単発のチャット補完。delegate_agentic_task(task, working_dir, model=None, max_iterations=20, timeout_seconds=600, backend=None, capture_transcript=False) -> str—working_dirにスコープされたread_file/write_file/run_bashツールを使ったマルチステップ委任。capture_transcript=Trueの場合を除き、完全なトランスクリプトではなく最終回答のみを返す。list_recent_delegations(limit=20) -> list[dict]— 直近に記録された委任を新しい順で返す。get_delegation_transcript(delegation_id) -> list[dict]—capture_transcript=Trueで記録された1回の委任の完全なトランスクリプト。
delegate_task/delegate_agentic_task は、エラー(設定ミス、到達不能なエンドポイント、タイムアウト、反復上限)を例外として発生させるのではなく "Error: ..." 文字列として返す。これにより、呼び出し元のエージェントが何が問題だったかを確認できる。
Available Tools
4 toolsdelegate_agentic_taskA
Delegate a multi-step task to a model with its own tool-use loop (read_file, write_file, run_bash) scoped to working_dir. Runs until the model stops calling tools, hits max_iterations, or exceeds timeout_seconds. Returns only the final answer, not the full transcript.
The delegated model gets unattended file/bash access within working_dir for the duration of the call - point it at a directory you're comfortable it can read, write, and execute commands in.
Args:
task: The task instruction to give the delegated model.
working_dir: Directory the model's tools are scoped to.
model: Override just the model string for this call.
max_iterations: Stop after this many tool-call rounds.
timeout_seconds: Wall-clock budget for the whole task.
backend: Named backend from models.json (base_url/model/api_key) to
use instead of the default DELEGATE_* env vars. model, if also
given, overrides the model within that backend.
capture_transcript: Log every model message and tool call/result for
later retrieval via get_delegation_transcript, instead of just
the final answer. Off by default; useful when comparing models
(e.g. a bake-off) rather than for routine use.
Inputs: task (required), working_dir (required), model, backend, +3 more. Returns: result
delegate_taskA
Delegate a single-shot task to a configured OpenAI-compatible model (e.g. local Ollama or OpenRouter) and return its text response verbatim.
Args:
prompt: The task/question to send to the delegated model.
model: Override just the model string for this call.
system_prompt: Optional system prompt to steer the delegated model.
backend: Named backend from models.json (base_url/model/api_key) to
use instead of the default DELEGATE_* env vars. model, if also
given, overrides the model within that backend.
capture_transcript: Log the full message exchange for later retrieval
via get_delegation_transcript. Off by default; useful when
comparing models (e.g. a bake-off) rather than for routine use.
Inputs: prompt (required), model, backend, system_prompt, +1 more. Returns: result
get_delegation_transcriptA
Full message transcript (every model message and tool call/result) for one delegation, if it was run with capture_transcript=True. Get the id from list_recent_delegations. Returns an error string if no transcript was captured for that id.
Args:
delegation_id: The id field from a list_recent_delegations row.
Inputs: delegation_id (required). Returns: result
list_recent_delegationsA
List the most recent delegate_task / delegate_agentic_task calls (backend, model, task, duration, iterations, success, token usage, USD cost if the model has a pricing.json entry, truncated result), most recent first. Answers "what did the delegated model actually do" without re-running anything.
Args: limit: Max number of records to return (default 20).
Inputs: limit. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
Each tool has a distinct purpose: delegate_task for single-turn, delegate_agentic_task for multi-step with tool use, list_recent_delegations for querying history, and get_delegation_transcript for retrieving full logs. No overlap.
All tool names follow a consistent snake_case verb_noun pattern (delegate_task, delegate_agentic_task, list_recent_delegations, get_delegation_transcript), with clear action prefixes.
Four tools precisely cover the core delegation workflow: create a delegation (two variants), list delegations, and inspect a transcript. No unnecessary extras.
The tool set covers creating delegations, retrieving summaries, and fetching full transcripts. No update/delete is needed for delegation records, so the surface is complete for its purpose.
Maintenance
Related MCP Connectors
Agent-native task management: your AI agent is the interface. Delegate to anyone by email.
Shared task layer for AI agents: tasks, handoffs and decisions that persist across tools.
Delegate tasks between AI agents on different platforms and collect the results.
Discover available AI models and delegate analysis or code review from your existing agent.
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables Claude to delegate tasks to external coding agents (Codex or Antigravity) for independent reviews, separate quota usage, and async processing.6MIT
- AlicenseAqualityCmaintenanceEnables AI coding agents like Claude Code or Codex to delegate tasks to a DeepSeek Harness subagent with its own context window, providing tools for task delegation, result waiting, continuation, and supervision with sandboxed execution.6MIT
- FlicenseAqualityCmaintenanceEnables main agents to delegate memory retrieval, web research, and multi-step tasks to internal sub-agents, returning concise conclusions while keeping detailed tool calls and raw content out of the main context.3-
- AlicenseNot gradedqualityBmaintenanceEnables MCP-capable coding assistants to delegate repository investigation, bounded implementation work, and noisy command runs (tests, builds, linters) to sandboxed OpenCode agents. Each role can use an independently selected model, and only concise results are returned to the parent agent, which keeps responsibility for architecture and high-risk operations.MIT