Skip to content

feat(guardrails): add IsMalicious MCP content gate - #44371

Draft
hexablob wants to merge 9 commits into
BerriAI:mainfrom
hexablob:feat-ismalicious-mcp-guardrail
Draft

hexablob wants to merge 9 commits into
BerriAI:mainfrom
hexablob:feat-ismalicious-mcp-guardrail

Conversation

@hexablob

@hexablob hexablob commented Oct 3, 2026 •

Copy link
Copy Markdown

TLDR

Problem this solves:

  • MCP text tools lack an IsMalicious inspection provider

How it solves it:

  • Inspect original URL arguments and complete normalized tool text
  • Refuse warnings, errors, oversized requests and incomplete inspection
  • Preserve admitted inputs and reuse native HTTP clients

User Flow

Before: an operator cannot configure IsMalicious inspection for MCP tools

  1. They configure a text MCP server in their proxy
  2. Their client submits a tool URL and receives untrusted text
  3. They cannot select IsMalicious to inspect that exchange

After: the operator can configure IsMalicious for that exchange

  1. They configure their text MCP server and the documented policy
  2. Their client submits the same URL and receives tool text
  3. Admitted text returns unchanged and refusal returns the fixed error

Pre-Submission checklist

This remains draft, with no maintainer review requested

  • Meaningful tests added
  • Mapped test files pass locally
  • Required CI/CD checks pass on the current tip
  • Scope addresses one MCP content-inspection provider
  • Every automated review on the current tip has finished and its findings are triaged

Screenshots / Proof of Fix

Authenticated live proxy, real IsMalicious API and real-provider proof remain unavailable. Fixture tests establish integration behavior and are not presented as live proof. The earlier question about the MCP-only route's proof requirement remains unanswered

Before (08a24d3)

  1. No live capture was performed at this revision
  2. The native IsMalicious provider is absent

After (020672a)

  1. No authenticated live capture was performed at this revision
  2. The PR remains draft until its proof requirements are met

Type

New Feature

Caveats

Medium

  • Native extraction omits binary and some envelope metadata
  • Disable raw-content logging and review tracing configuration
  • Hosted API credentials and separate scan quota are required
  • Live proof and maintainer placement confirmation remain pending
  • Fresh automated reviews and current-tip CI remain pending

Low

  • Mapped suites: 174 passing cases, with synthetic inspection replies
  • Batch coverage preserves order, Unicode and original input identity
  • Refusal tests exclude input text and credentials from errors
  • Frozen validation models still accept JSON arrays
  • Native registration supports configured scalar and list modes
  • Full lint passes without changing budgets or dependency locks
  • Upstream provider additions and transport/cache regressions were preserved
  • Conditional mode configuration now raises the required TypeError
  • Native list discovery and audit mutation retain documented exceptions

Full lint compares rule counts with current upstream and does not claim zero whole-repository type errors. The current-tip CI and fresh automated reviews will supersede results on the earlier head

The open placement thread awaits maintainer confirmation. Greptile accepted the existing guardrail precedents as relevant

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

@CLAassistant

CLAassistant commented Oct 3, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ hexablob
❌ devin-ai-integration[bot]
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov

codecov Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.44444% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...rdrails/guardrail_hooks/ismalicious/ismalicious.py 99.34% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 31 untouched benchmarks


Comparing hexablob:feat-ismalicious-mcp-guardrail (020672a) with main (08a24d3)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (a9e45a2) during the generation of this report, so 08a24d3 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@hexablob

hexablob commented Oct 3, 2026

Copy link
Copy Markdown
Author

Reused the native HTTP pool with isolated transports and added native lifecycle/configuration tests. Local checks pass; authenticated live-provider proof remains pending

…-scan (BerriAI#44347)

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
(cherry picked from commit 4ece6c9)
@hexablob

hexablob commented Oct 5, 2026 •

Copy link
Copy Markdown
Author

Imported upstream’s braces exception (expires 2026-11-03). @greptileai please review; maintainers, does authenticated /mcp-rest proof suffice without billable LLM calls under “if applicable” and AGENTS:42?

@greptile-apps

greptile-apps Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Adds a new content inspection guardrail for MCP tool calls.

The reported behavior fixes appear sound, but the provider-specific code placement requirement should be addressed before merging

Findings

  1. P2 Provider logic in proxy ▶

Summary

The PR adds an IsMalicious guardrail for MCP URL arguments and text results, using LiteLLM’s cached HTTP client and a fixed refusal on inspection failure. Since the previous review, it recognizes case-variant HTTP(S) schemes without rewriting URLs and handles closed-client errors during inspection. Both previous threads are resolved, and the current code addresses their reported behavior

Reviews (2) · Last reviewed commit: "fix(guardrails): reject case-variant blo..."

@hexablob

hexablob commented Oct 5, 2026

Copy link
Copy Markdown
Author

Both P1 findings are fixed in 40cbd2f with reproduced regressions and 155 passing tests. @greptileai please re-review the updated head

Comment on lines +181 to +183
await client.get(
f"{_API_BASE}/gate/url",
params={"u": url},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Provider logic in proxy The proxy guardrail constructs IsMalicious API requests and handles provider responses. This violates the repository requirement to keep provider-specific code under llms/ and must be addressed before merging.

Rule Used: What: Avoid writing provider-specific code outside of the llms/ directory. Why: This practice ensures better maintainability and reduces complexity over time. Good: ```python # Handle provider-specific logic within llms/vertex_ai/transformation.py ... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API calls live in native Lakera, Pangea and EnkryptAI guardrail hooks. Maintainers, please confirm whether this placement should differ for IsMalicious

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those precedents are relevant, and they make this a reasonable architectural question rather than an obvious defect. I agree that guardrail hooks commonly own their provider API calls today, and the MCP-specific orchestration here is naturally tied to the proxy hook lifecycle; moving only the HTTP client code into llms/ could add indirection without improving the design.

My original comment was driven by the repository-wide instruction to avoid provider-specific code outside llms/, not by a claim that IsMalicious is uniquely misplaced. The existing Lakera, Pangea, and EnkryptAI implementations show that this convention is not consistently applied. I’ll treat this finding as requiring maintainer confirmation: if those guardrail implementations are the accepted pattern, IsMalicious can remain alongside them; otherwise the rule should be clarified and applied consistently to the existing hooks as well.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.

@hexablob

hexablob commented Oct 12, 2026 •

Copy link
Copy Markdown
Author

Merged upstream and froze validation models. 170 tests and full lint pass. @greptileai please review, live proof and maintainer placement confirmation remain pending

@hexablob

Copy link
Copy Markdown
Author

Merged upstream 08a24d3 and preserved new provider registrations. 174 tests and full lint pass. @greptileai please review this head

This branch has not been deployed

No deployments
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.

2 participants