Skip to main content

mcp-guardeval

PyPI version License: MIT

mcp-guardeval is a standalone, framework-agnostic evaluation harness for LLM agents utilizing the Model Context Protocol (MCP). It captures OpenTelemetry spans (gen_ai.* conventions), normalizes them into queryable SQLite records, and quantitatively scores both task performance and security resilience against catalogued SAFE-MCP adversarial techniques.


Installation

pip install mcp-guardeval

Key Capabilities

  1. Task Success Scoring: Measures whether the agent called the expected tools, supplied correct arguments, and respected tool dependencies.
  2. Adversarial Security Scoring: Evaluates agent behavior against red-team attack techniques (prompt injection, argument hijacking, data exfiltration, context planting, PII harvesting).
  3. Telemetry & Trace Analysis: Normalizes hierarchical OpenTelemetry distributed traces into flat SQLite rows for high-speed SQL analytics.
  4. Pytest Integration: Built-in pytest plugin enabling single-command evaluation:
    pytest tests/ --agenteval -v
    

Quick Start

1. Telemetry Ingestion & Storage

mcp-guardeval reads OpenTelemetry trace data persisted to SQLite:

from agenteval.storage import TraceStore

# Connect to the SQLite trace database
store = TraceStore("traces.db")

# Inspect completed agent runs
runs = store.get_runs()
for run in runs:
    print(f"Run {run.run_id}: {run.prompt[:50]}... | {run.latency_ms:.1f}ms")

2. Scoring Task Success

Evaluate whether an agent executed the intended workflow:

from agenteval.metrics.task_success import score_task
from agenteval.storage import TraceStore

store = TraceStore("traces.db")

# Score a customer lookup workflow
result = score_task(
    store=store,
    run_id="run_1042",
    expected_tools=["query_customer_db"],
    expected_args={"query_customer_db": {"customer_id": "4471"}},
    expected_sequence=["query_customer_db"],
)

print(f"Task Passed: {result.passed}")
print(f"Confidence Score: {result.score:.2f}")
print(f"Missing Tools: {result.missing_tools}")

3. Evaluating Guardrail Security

Assess whether guardrails intercepted adversarial SAFE-MCP attacks:

from agenteval.metrics.security import score_security_run
from agenteval.storage import TraceStore

store = TraceStore("traces.db")

# Evaluate an indirect prompt injection attack (SAFE-T1201)
verdict = score_security_run(
    store=store,
    run_id="attack_run_88",
    technique_id="SAFE-T1201",
    guardrail_log="reference_system/fixtures/guardrail.log",
)

# Verdict options: BLOCKED (secure), PASSED (exploited), or PARTIAL
print(f"Security Verdict: {verdict.status.name}")
print(f"Mitigation Reason: {verdict.reason}")

Pytest Plugin Usage

mcp-guardeval automatically registers with pytest when installed. Use the --agenteval CLI flag to activate trace evaluation and automated reporting during test execution:

# Run security test suite with AgentEval report summary
pytest tests/test_security.py --agenteval -v

Supported SAFE-MCP Attack Techniques

Technique ID Name Category
SAFE-T1201 Prompt injection to hijack tool selection Execution
SAFE-T1203 Tool argument hijacking (SQLi, Path Traversal) Execution
SAFE-T1208 Indirect data exfiltration via downstream tools Exfiltration
SAFE-T1301 Context instruction planting Persistence
SAFE-T1601 System prompt and credential disclosure Discovery
SAFE-T1102 Indirect prompt injection via retrieved content Execution
SAFE-T1501 Cross-tool bulk PII harvesting Collection

License

Distributed under the MIT License. See LICENSE for more information.

Metadata

Release files for mcp-guardeval 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-guardeval 0.1.0
File Size Uploaded Provenance
mcp_guardeval-0.1.0.tar.gz 7.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-guardeval 0.1.0
File Interpreter ABI Platform
mcp_guardeval-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.4 kB

Release files / mcp_guardeval-0.1.0.tar.gz

Download URL mcp_guardeval-0.1.0.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d3a359253fbc4674602871a5cb8786ae572b3f45e307403e4172406fdaaa8f2e
BLAKE2b-256 checksum
How to use checksums
a86faf1857f2a8fb93348469d9084d5cb651f3903c2d638522208cebf7154f76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.13.9 Darwin/25.6.0

Release files / mcp_guardeval-0.1.0-py3-none-any.whl

Download URL mcp_guardeval-0.1.0-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2b874707faf30d17239882d3b407ff8b0cc4f3d956716e8b05d232346e461f6a
BLAKE2b-256 checksum
How to use checksums
a55127f2fcc43e203e48f05e6414401e6de5c49822f9237ee2bd22e78e8f2d0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.13.9 Darwin/25.6.0

Security for mcp-guardeval 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page