Skip to main content

Portable MCP server for agent handoff state and review tracking.

Project description

Agent Handoff MCP

Portable MCP server for agent handoff state, review findings, exports, close checks, and lane-scoped worker/orchestrator coordination.

Scope

This package owns handoff state and related workflow primitives:

  • task state, decisions, blockers, and next actions
  • review findings and review runs
  • generated CURRENT_TASK.json snapshots
  • lane registration, lane activity, worker reports, and lane messages
  • artifact indexing and derived metrics snapshots

It does not include unrelated repo-intel or UI helpers.

Runtime State

By default, runtime state lives under the workspace you point the CLI at:

  • SQLite DB: .task-state/handoff.db
  • exports: .task-state/exports/
  • generated markdown: CURRENT_TASK.json

Override these with CLI flags or AGENT_HANDOFF_* environment variables.

Installation

From PyPI (recommended)

pip install mcp-agent-handoff
# or, as an isolated tool:
uv tool install mcp-agent-handoff
# or, ad-hoc without installing:
uvx mcp-agent-handoff --workspace-root /path/to/workspace serve-stdio

From the monorepo source tree (development)

From this package root inside agentic-protocol-monorepo:

cd packages/mcp-agent-handoff
python -m pip install -e ".[dev]"

Development

All package-local development commands are intended to run from the package root:

make lint-handoff
make fix-lint-handoff
make format-handoff
make mypy-handoff
make test-handoff
make check-handoff

Prefer the package-local Make targets when running checks from editors or agent sessions. Workspace-level interpreter discovery can point at a minimal environment that lacks this package's dev extras such as pytest, while make test-handoff and make check-handoff keep execution anchored to the package root and honor PYTHON=/path/to/python3 overrides when you need to pin a specific interpreter.

The Makefile automatically adds a sibling ../codex-subagent-bridge/src to PYTHONPATH when that checkout exists. In a fully extracted repo, that fallback is unnecessary once dependencies are installed normally.

Direct commands also work:

PYTHONPATH=src python -m ruff check src tests
PYTHONPATH=src python -m mypy src
PYTHONPATH=src python -m pytest tests -q

Python API

The package can be used directly as a library — this is the primary fallback when MCP tool calls are unavailable.

Always import from the package root (agent_handoff_mcp), never from submodules like .config, .decisions, or .core. Submodules are internal and may change.

from pathlib import Path
from agent_handoff_mcp import (
    RuntimeConfig,
    configure_runtime,
    get_handoff_state,
    search_handoff,
  validate_decision_id,
    record_event,
    review_findings,
    list_review_findings,
    set_handoff_state,
    update_task_status,
    get_verified_tests,
    render_handoff,
    record_file_touch,
    get_touched_files,
)

# Configure runtime before any read/write call
configure_runtime(RuntimeConfig.for_repo(Path("/path/to/workspace")))

# Read state
state = get_handoff_state(sections="identity")

# Search decisions
results = search_handoff(queries=["slice_complete"], record_types=["decision"], limit=5)

# Preflight a slice-complete decision id before writing
preflight = validate_decision_id(
  decision="codex_slice_complete_plan0004_contract-pinning-and-docs",
  decision_kind="slice_complete",
)

# List open findings
findings = list_review_findings(status="open")

Without installation (monorepo source tree):

PYTHONPATH=packages/mcp-agent-handoff/src python3 -c "
from pathlib import Path
from agent_handoff_mcp import RuntimeConfig, configure_runtime, get_handoff_state
configure_runtime(RuntimeConfig.for_repo(Path('.')))
state = get_handoff_state(sections='identity')
print(state['data']['active']['task_ref'])
"

CLI Usage

Run the MCP server over stdio:

mcp-agent-handoff --workspace-root /path/to/workspace serve-stdio

Run the MCP server over HTTP:

mcp-agent-handoff --workspace-root /path/to/workspace serve-http

FastMCP's current HTTP defaults are:

  • host: 127.0.0.1
  • port: 8000
  • path: /mcp

Useful CLI checks:

mcp-agent-handoff --workspace-root /path/to/workspace doctor
mcp-agent-handoff --workspace-root /path/to/workspace state
mcp-agent-handoff --workspace-root /path/to/workspace validate-decision-id --decision codex_slice_complete_plan0004_contract-pinning-and-docs --decision-kind slice_complete
mcp-agent-handoff --workspace-root /path/to/workspace review-findings --operation list
mcp-agent-handoff --workspace-root /path/to/workspace handoff-close-check

Slice-complete Decision IDs

Do not hard-code the slice-complete regex in client prompts or scripts. Treat get_handoff_state(sections="identity").data.limits.write.slice_complete_decision_id as the authoritative registry, and use validate_decision_id(decision=..., decision_kind="slice_complete") for side-effect-free preflight when composing ids outside close_slice(author_tag=..., work_ref=..., slug=...).

Valid: cdx_slice_complete_plan0004_contract_pinning_and_docs

Invalid: cdx_slice_complete_plan0004_contract-pinning-and-docs

Review Intake

Preferred path when agent-orchestrator-mcp is available:

  1. get_latest_slice_review_packet
  2. get_review_findings_summary or review_findings --operation list as needed

Handoff-only fallback:

  1. load_session
  2. search_handoff(queries=["slice_complete"], record_types=["decision"], limit=1)
  3. get_verified_tests(task_ref=..., commit_sha=...)
  4. review_findings(review={"operation":"list","status":"open"})

Use the MCP read surfaces above before inspecting .task-state/handoff.db directly. Drop to raw SQLite or filesystem inspection only when the required MCP tool is unavailable or when you are debugging MCP transport or serialization failures.

Source-tree execution without installation:

PYTHONPATH=src python -m agent_handoff_mcp --workspace-root /path/to/workspace serve-stdio

Token-Efficient Usage

The v2 envelope is already compact, but callers still save the most tokens by shaping read responses deliberately:

  • Use get_handoff_state(sections="identity") for routine task checks instead of a full state fetch.
  • Use detail="summary" on read surfaces such as get_handoff_state, load_session, review_findings, search_handoff, and artifacts when truncated text is acceptable.
  • Use top_n_*, limit=, and fields= to cap read size instead of trimming large payloads client-side. load_session accepts top_n_touched_files (default 20, max 200) to bound the additive touched_files list.
  • Read from the canonical data block — result["data"]["active"] etc. The legacy top-level mirror was removed in 0.3.0 and never returns.

Package-local guidance and examples live in docs/guides/token-efficient-usage.md.

Wire format note (≥0.3.0)

Starting in agent-handoff-mcp 0.3.0, MCP tool responses are native JSON objects on the wire, not JSON strings inside structured_content.result. Every handler is annotated -> dict and returns a real dict via _envelope(); FastMCP serialises it once. If you previously did json.loads(handoff_tool(...)) to parse a JSON string return value, drop the json.loads — the call returns a dict directly. If you previously read result.content[0].text from the MCP wire payload and parsed it, read result.structured_content directly instead.

The envelope field set is unchanged (ok, schema_version, tool, scope, data, mutation, artifacts, warnings, task_ref) and schema_version stays at 2. Only the wire-encoding moved from JSON-string-inside-JSON to a native nested object. See CHANGELOG.md for the full migration notice.

Client Adapter Shape

Installed console-script adapter:

{
  "name": "altcontext-mcp",
  "command": "mcp-agent-handoff",
  "args": ["--workspace-root", "/path/to/workspace", "serve-stdio"]
}

Source checkout adapter:

{
  "name": "altcontext-mcp",
  "command": "python3",
  "args": [
    "-m",
    "agent_handoff_mcp",
    "--workspace-root",
    "/path/to/workspace",
    "serve-stdio"
  ],
  "cwd": "/path/to/mcp-agent-handoff",
  "env": {
    "PYTHONPATH": "/path/to/mcp-agent-handoff/src"
  }
}

Tool Surface

mcp-agent-handoff now exposes a single unified MCP surface.

Legacy --tool-profile all|core|extended inputs are still accepted for compatibility, but they all expose the same tool set:

mcp-agent-handoff --workspace-root /path/to/workspace --tool-profile core serve-stdio

Unified surface

CLI name MCP tool
state get_handoff_state
set set_handoff_state
validate-decision-id validate_decision_id
event record_event
next-actions next_actions
review-findings review_findings
review-runs review_runs
handoff-close-check handoff_close_check
render-handoff render_handoff (kind=current_task/dashboard)
(no CLI) load_session
(no CLI) close_slice
audit-decisions audit_decision_ids
export export_handoff_state
import import_handoff_state
archive archive_task_state
task-status update_task_status
artifacts artifacts
handoff-search search_handoff
get-verified-tests get_verified_tests
get-archived-task get_archived_task
record-file-touch record_file_touch
get-touched-files get_touched_files

record_event uses a typed event payload with event_kind="decision" | "test_result" | "blocker" so each variant keeps its own required fields. next_actions uses operation="list" | "add" | "update" | "complete" | "skip". review_findings uses operation="record" | "batch_record" | "update" | "list". review_runs uses operation="record" | "list" | "coverage".

Branch/worktree drift is surfaced through warnings on write responses. If you set AGENT_HANDOFF_ENFORCE_BRANCH=1, branch mismatches against the active task's target_branch fail before mutation on enforceable branches. Direct Python callers see BranchMismatchError; MCP clients receive the standard v2 error envelope with data.expected_branch and data.actual_branch.

CLI-only extras (not part of MCP registry): artifact-list, artifact-terms.

Surface classes:

  • action: mutates canonical state; do not blind-retry
  • query: read-only inspection of canonical state; usually safe to retry
  • generator: derived output such as close checks, markdown renders, and metrics summaries

Troubleshooting

The fastest first check is still:

mcp-agent-handoff --workspace-root /path/to/workspace doctor

If startup succeeds but calls fail, check the workspace paths first: --workspace-root, --state-dir, --current-task-path, and --exports-dir must all point at the same workspace state.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_agent_handoff-0.9.1.tar.gz (306.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_agent_handoff-0.9.1-py3-none-any.whl (175.9 kB view details)

Uploaded Python 3

File details

Details for the file mcp_agent_handoff-0.9.1.tar.gz.

File metadata

  • Download URL: mcp_agent_handoff-0.9.1.tar.gz
  • Upload date:
  • Size: 306.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for mcp_agent_handoff-0.9.1.tar.gz
Algorithm Hash digest
SHA256 4d43fb928987cfce65e1426e49075d667c5424a1bee37b23b760f2bd43b52670
MD5 332d090674788ed1f23ab0a74d574323
BLAKE2b-256 365262534e344c7e0c9b3a7c72b0ec0451da4bce42ff88da3055ed62b80b048f

See more details on using hashes here.

File details

Details for the file mcp_agent_handoff-0.9.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_agent_handoff-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 46cca5d896155657e3143c66e451483b939f903316c9c585e24676c02995beb2
MD5 04448f7516ac7f942b23b7918405c6a3
BLAKE2b-256 dbdace52a860e554a94ae1a58b0b0083fb56a131feea4edd0222256d24b19c5d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page