Skip to content

Fix LlamaFirewall scans inside the MCP event loop - #54

Open
3nesdeniz wants to merge 1 commit into
trailofbits:mainfrom
3nesdeniz:fix/llamafirewall-async-scan
Open

Fix LlamaFirewall scans inside the MCP event loop#54
3nesdeniz wants to merge 1 commit into
trailofbits:mainfrom
3nesdeniz:fix/llamafirewall-async-scan

Conversation

@3nesdeniz

Copy link
Copy Markdown

Summary

  • make guardrail provider checks asynchronous end to end
  • use LlamaFirewall's native scan_async() API for server configurations and tool responses
  • update the built-in providers, mocks, and call sites for the async contract
  • add regression coverage for both ALLOW and BLOCK decisions

Fixes #39.

Root cause

mcp-context-protector executes guardrail checks inside its active asyncio event loop. LlamaFirewall.scan() starts another event loop with asyncio.run(), so both the configuration-review and tool-response paths could fail with:

RuntimeError: asyncio.run() cannot be called from a running event loop

LlamaFirewall provides scan_async() for this environment. The provider contract and both call chains now await that API directly.

Verification

  • Reproduced the failure on the current main branch with the official MCP Python weather server.
  • Verified configuration scanning and a real get_alerts tool call after the fix.
  • Full test suite: 302 passed
  • Coverage: 69% (CI threshold: 55%)
  • Focused regression suite on Python 3.11, 3.12, and 3.13: 13 passed on each version
  • make lint: Ruff formatting/checks and 100% interrogate coverage passed
  • uv build: source distribution and wheel built successfully
  • git diff --check: passed

Signed-off-by: Enes Deniz <142517728+3nesdeniz@users.noreply.github.com>
@CLAassistant

CLAassistant commented Jul 25, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LlamaFirewallProvider unable to run due to nested asyncio event loops

2 participants