Skip to main content
Glama
proactive-agent-mcp

proactive-agent-mcp

by MishaelOliva

proactive-agent-mcp

A Model Context Protocol server in Python that exposes a proactive triage queue, document compliance validation, grounded knowledge retrieval, and server-enforced guardrails for autonomous agents. Speaks JSON-RPC 2.0 over stdio.

CI License: MIT Python: 3.10+ MCP: 2025-06-18

What it does

  • Proactive triage with leases. poll_event_queue claims unprocessed events and takes a time-boxed lease on each. If the agent dies mid-triage the lease lapses and the event returns to the queue. complete_event and release_event settle or hand back work explicitly.

  • Document compliance evaluation. evaluate_document_compliance checks extracted document fields against a declared schema, reporting missing fields, regex violations, a confidence score, and a risk level.

  • Grounded retrieval. query_rag_knowledge ranks an in-repository corpus with sparse TF-IDF vectors and cosine similarity, returning measured latency and an explicit grounding verdict.

  • Human-in-the-loop gates. request_human_approval parks a sensitive action behind an HMAC-SHA256 signed ticket. verify_approval_token checks a supervisor's confirmation code.

  • Cost enforcement. track_cost_budget books token spend, and the server refuses further tool calls for any session that has exhausted its budget.

Related MCP server: agent-work-mcp

Architecture

+--------------------------------------------------+
|        Client (Claude Desktop / Cursor / IDE)     |
+----------------------+---------------------------+
                       |
                       |  JSON-RPC 2.0 over stdio
                       v
+--------------------------------------------------+
|              proactive-agent-mcp                  |
|                                                  |
|  server.py     dispatch, negotiation, budgets    |
|  protocol.py   JSON-RPC + MCP primitives         |
|  validation.py pydantic argument enforcement     |
|                                                  |
|  tools/     triage, compliance, knowledge,       |
|             guardrails (HITL + cost)             |
|  resources/ system://health, compliance://standards
|  prompts/   autonomous_triage_loop,              |
|             compliance_audit_brief                |
+--------------------------------------------------+

The event queue and knowledge corpus are in-memory reference implementations. They reset on restart and are not shared between replicas.

Quick start

git clone https://github.com/MishaelOliva/proactive-agent-mcp.git
cd proactive-agent-mcp
pip install -e ".[dev]"
python -m proactive_agent_mcp.server

To watch a full triage session, including the human-approval round trip and budget enforcement:

python examples/run_client_demo.py

Configuration

Claude Desktop

{
  "mcpServers": {
    "proactive-agent": {
      "command": "python",
      "args": ["-m", "proactive_agent_mcp.server"],
      "env": {
        "PYTHONUNBUFFERED": "1",
        "MCP_SIGNING_SECRET": "generate-with-openssl-rand-hex-32"
      }
    }
  }
}

Cursor (.cursor/mcp.json)

{
  "mcpServers": {
    "proactive-agent": {
      "command": "python",
      "args": ["-m", "proactive_agent_mcp.server"],
      "env": {
        "MCP_SIGNING_SECRET": "generate-with-openssl-rand-hex-32"
      }
    }
  }
}

Environment variables

Variable

Purpose

Default

MCP_SIGNING_SECRET

Key for HMAC-SHA256 approval codes. Set this. An unset value produces a random per-process secret and logs a warning, so tokens do not survive a restart.

random, per process

MCP_SESSION_BUDGET_USD

Default per-session spend ceiling.

5.0

MCP_LOG_LEVEL

Log level for the stderr stream.

INFO

PYTHONUNBUFFERED

Flush stdout so responses are not buffered.

1 recommended

Tools

Tool

Purpose

poll_event_queue

Claim events under a lease.

complete_event

Settle a claimed event.

release_event

Return a claimed event to the queue.

push_event

Record an observation onto the queue.

evaluate_document_compliance

Validate extracted document fields.

query_rag_knowledge

Rank the corpus by TF-IDF cosine similarity.

request_human_approval

Park a sensitive action for human authorization.

verify_approval_token

Verify a supervisor's confirmation code.

track_cost_budget

Book token spend against a session.

set_active_session

Choose which session the budget guard charges.

Security model

The human-in-the-loop gate is a worked pattern, not a production authorization system. What it does guarantee:

  • Approval codes are full 256-bit HMAC-SHA256 values, base32-encoded for legibility. They are not truncated.

  • The signed payload binds the ticket id, action name, a SHA-256 digest of the action parameters, and the absolute expiry. A code cannot be re-pointed at a different action, swapped for different parameters, or replayed after expiry.

  • The code is recomputed at verification time rather than read from a stored expected value, so a tampered ticket record invalidates its own code.

  • Tickets are single-use, compared in constant time, and garbage-collected once settled.

  • The confirmation code is never returned by request_human_approval. It must arrive through a channel the agent cannot reach.

  • The signing secret has no hardcoded default. With MCP_SIGNING_SECRET unset, a random secret is generated at start-up, so a code cannot be derived from knowledge of this repository.

What it does not guarantee, and what a real deployment must add:

  • Binding approvals to an authenticated human principal. The gate proves a holder of the secret approved, not who.

  • Surviving a restart or spanning replicas. Tickets live in process memory.

  • An authenticated delivery channel for the confirmation code.

  • Protection against a sufficiently privileged caller with in-process access.

The budget guard enforces rather than advises: once a session exceeds its ceiling, the server refuses non-guardrail tool calls. Accounting tools stay reachable so the agent can report honestly rather than dead-ending.

Testing

python -m unittest discover -s tests -t .

116 tests covering protocol conformance (initialization gating, notification suppression, version negotiation, batching, pagination, error codes), tool behaviour, the HITL security properties, budget enforcement, and an end-to-end stdio session against a real subprocess.

Several tests are explicit regression guards for defects fixed in v1.1.0: a confidence score that capped a perfect document at 0.571, a hardcoded retrieval latency, a forgeable approval secret, a mid-session budget change that was silently ignored, and an event queue that stranded work when an agent crashed.

CI runs the suite on Python 3.10-3.12 with and without MCP_SIGNING_SECRET set, lints with ruff, verifies the wheel installs in a clean environment, and smoke tests the container entrypoint.

Limitations

  • Single process. State is in memory, so the event queue, tickets, and budget ledger reset on restart and are not shared across replicas.

  • stdio only. Streamable HTTP transport is not implemented.

  • Lexical retrieval. TF-IDF cosine matches vocabulary, not meaning. Paraphrased queries retrieve poorly. Dense embeddings would be the natural upgrade; the interface would not change.

  • Deterministic compliance. Field and regex validation only. It says nothing about whether extracted values are truthful.

  • Illustrative pricing. MODEL_PRICING in tools/guardrails.py is a static table that needs periodic refreshing. Treat it as configuration.

License

MIT.


Built by Mishael Oliva • LinkedIn

Available Tools

10 tools
complete_eventA
Idempotent

Settle a claimed event with an outcome and an optional note. Use this once triage of an event has finished.

Inputs: event_id (required), note, outcome. Returns: object

evaluate_document_complianceA
Read-onlyIdempotent

Check an extracted document against a declared schema. Reports missing required fields, pattern violations, a confidence score, and a triage verdict. This is deterministic field validation over regex rules, not document understanding.

Inputs: document_payload (required), schema_type, strict_mode. Returns: object

poll_event_queueA
Read-only

Claim unprocessed events from the proactive triage queue and take a time-boxed lease on each. Events whose lease lapses return to the queue automatically, so a crashed agent does not strand work.

Inputs: max_items, queue_name, lease_seconds, filter_severity. Returns: object

push_eventA

Record an observation the agent made onto the triage queue so it becomes visible to other workers. Rejected when the queue is full.

Inputs: payload (required), severity (required), event_type (required), source. Returns: object

query_rag_knowledgeA
Read-onlyIdempotent

Rank the built-in knowledge corpus against a query using sparse TF-IDF vectors and cosine similarity. Lexical rather than semantic: it matches vocabulary, so paraphrased queries retrieve poorly. Returns measured retrieval latency and an explicit grounding verdict.

Inputs: query (required), top_k, min_score_threshold. Returns: object

release_eventA
Idempotent

Return a claimed event to the unprocessed pool without settling it, so another worker can pick it up immediately instead of waiting for the lease to lapse.

Inputs: event_id (required). Returns: object

request_human_approvalB
Read-only

Park a sensitive action behind a human decision and return an authorization ticket. The confirmation code is never returned here: it must be supplied by an authorized human over an authenticated out-of-band channel, otherwise the gate proves nothing.

Inputs: rationale (required), action_name (required), action_parameters (required), urgency, +1 more. Returns: object

set_active_sessionA
Idempotent

Select which session the server's budget guard charges. The server refuses non-guardrail tool calls for any session that has exhausted its budget.

Inputs: session_id (required). Returns: object

track_cost_budgetA

Book token spend against a session budget. Once a session exceeds its budget the server refuses further tool calls for it until the budget is raised; enforcement is server-side, not advisory.

Inputs: session_id (required), prompt_tokens (required), completion_tokens (required), model_name, +1 more. Returns: object

verify_approval_tokenA

Verify a supervisor's confirmation code against a ticket and consume the ticket on success. The code is bound to the action name, a digest of the action parameters, and the expiry, and each ticket is single-use.

Inputs: ticket_id (required), confirmation_code (required). Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.9/5.0

    Scored across 10 tools

    Disambiguation4/5

    The tools cluster into four clear domains: event-queue lifecycle (poll/complete/release/push), approval (request/verify), budget (track/set_active_session), and two standalone capabilities (compliance, RAG). complete_event vs release_event could be momentarily confused, but the descriptions clearly distinguish settling from returning to the pool. set_active_session and track_cost_budget are related but have distinct roles.

    Naming Consistency5/5

    Every tool follows a consistent verb_noun snake_case pattern (poll_event_queue, complete_event, verify_approval_token, track_cost_budget, etc.). No mixed conventions or vague verbs anywhere in the set.

    Tool Count5/5

    Ten tools is well within the sweet spot for a triage/guardrail agent, and each tool earns its place by covering a distinct operation rather than duplicating another. No bloat or thin coverage.

    Completeness4/5

    The event queue has full lifecycle coverage (push/poll/complete/release), approval has request+verify, and budget has tracking plus session selection. Minor gaps like inspecting queue depth or listing pending events exist, but agents can work around them via polling.

    Maintenance

    ActivitySlowing
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides durable queues, human-in-the-loop approval gates, and an audit trail for AI agent fleets, enabling blocking approval requests and reliable work handoffs.
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      Enables coding agents to run persistent, budgeted work sessions with dependency graphs, human decision queues, required validation, and clean handoffs for autonomous or human-in-the-loop execution.
      16
      MIT
    • A
      license
      Not graded
      quality
      Not graded
      maintenance
      Enables agents to track real-time token spend and cost velocity, automatically throttle or freeze execution when budgets are exceeded, and enforce sandbox and safety guardrails.
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables agents to route every action through a pre-execution gate that returns allow, escalate-to-human, or deny verdicts, backed by deterministic hard-rule blocks plus probabilistic gray-zone scoring, and to run a resumable orchestration loop covering routing, quality gates, stop-loss, acceptance, and escalation. Every decision, arbitration between conflicting agents, and human approval is written to an append-only hash-chained, Ed25519-signed ledger that can be postmortemed, calibrated, alert-scanned, and exported as offline verification bundles or OTel spans.
      1
      MIT