add McpProtection plugin#2977
Merged
Merged
Conversation
… modularity and reusability
…patterns and add corresponding unit tests
…PCValidator, and enhance method null check in Rule
…nd enhance configuration options
… request handling
…pc-protection # Conflicts: # core/src/main/java/com/predic8/membrane/core/interceptor/json/rpc/JsonRPCParams.java
…or` and add helper method `getJsonVisibleChildElementSpecs`.
…thods, and update references
…proper error handling and add corresponding test.
…idation, and batch size limiting
… parameter validation, and batch size limits
…d update associated logic, tests, and documentation
…ma handling logic
…s and documentation adjustments
…values in examples and responses
…`error` with updated tests and supporting classes
…lace with `schemaValidation` supporting `params`, `response`, and `error` validation. Update tests and tutorials accordingly.
…ince JSON validation is sufficient
predic8
reviewed
Jun 28, 2026
predic8
reviewed
Jun 28, 2026
…dling for non-`tools/list` responses in `MCPProtectionInterceptor`.
…od with static `getPayloadType`, remove unused methods, and improve code consistency.
…nly/write actions, adjust schemas, refine examples, and update test cases
…en error and success schemas are configured, and add corresponding test case.
… manipulation, improve `findLastSegmentStart` logic, and add unit test.
…lErrorRenderer and improve error handling
# Conflicts: # distribution/tutorials/README.md
Contributor
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
core/src/test/java/com/predic8/membrane/core/interceptor/mcp/MCPProtectionInterceptorTest.java (1)
398-423: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the response body stays unchanged here.
This only checks the return value. A regression that rewrites non-
tools/listJSON but still returnsCONTINUEwould still pass, so the negative path is not really covered.Suggested fix
exc.setResponse(Response.ok() .contentType(APPLICATION_JSON) .body(body) .build()); assertEquals(CONTINUE, interceptor.handleResponse(exc)); + assertEquals(body, exc.getResponse().getBodyAsStringDecoded()); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@core/src/test/java/com/predic8/membrane/core/interceptor/mcp/MCPProtectionInterceptorTest.java` around lines 398 - 423, The negative-path test in MCPProtectionInterceptorTest only verifies that handleResponse returns CONTINUE, but it does not confirm that a non-tools/list JSON response remains untouched. Update leavesNonToolsListResponsesUnchanged to capture the original response body from Response.ok() and assert after interceptor.handleResponse(exc) that the response body is still identical, using the existing handleResponse/exc setup to ensure no rewriting happens for ping responses.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@core/src/main/java/com/predic8/membrane/core/interceptor/json/rpc/JsonRPCProtectionInterceptor.java`:
- Around line 185-190: Invalidate the cached JsonRPCValidator whenever
configuration objects are replaced so validation state stays in sync with the
active config. Update JsonRPCProtectionInterceptor’s setSchemaValidation,
setBatch, and setMethods setters to clear the memoized validator (the field used
by init()/getValidator()) after swapping in new JsonRPCSchemaValidation, batch,
or methods objects, so handleResponse() and request/response validation all use
the same current settings.
---
Nitpick comments:
In
`@core/src/test/java/com/predic8/membrane/core/interceptor/mcp/MCPProtectionInterceptorTest.java`:
- Around line 398-423: The negative-path test in MCPProtectionInterceptorTest
only verifies that handleResponse returns CONTINUE, but it does not confirm that
a non-tools/list JSON response remains untouched. Update
leavesNonToolsListResponsesUnchanged to capture the original response body from
Response.ok() and assert after interceptor.handleResponse(exc) that the response
body is still identical, using the existing handleResponse/exc setup to ensure
no rewriting happens for ping responses.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7a6f94c6-71fd-4bb7-b120-b1233f1fa3f0
📒 Files selected for processing (11)
annot/src/main/java/com/predic8/membrane/annot/yaml/error/LineYamlErrorRenderer.javaannot/src/test/java/com/predic8/membrane/annot/yaml/error/LineYamlErrorRendererTest.javacore/src/main/java/com/predic8/membrane/core/interceptor/json/rpc/JsonRPCProtectionInterceptor.javacore/src/main/java/com/predic8/membrane/core/interceptor/json/rpc/JsonRPCSchemaValidation.javacore/src/main/java/com/predic8/membrane/core/interceptor/json/rpc/JsonRPCValidator.javacore/src/main/java/com/predic8/membrane/core/interceptor/mcp/MCPProtectionInterceptor.javacore/src/main/java/com/predic8/membrane/core/interceptor/mcp/MCPProtectionValidator.javacore/src/test/java/com/predic8/membrane/core/interceptor/json/rpc/JsonRPCProtectionInterceptorTest.javacore/src/test/java/com/predic8/membrane/core/interceptor/mcp/MCPProtectionInterceptorTest.javadistribution/src/test/java/com/predic8/membrane/tutorials/security/JsonRpcProtectionTutorialTest.javadistribution/tutorials/README.md
💤 Files with no reviewable changes (1)
- core/src/main/java/com/predic8/membrane/core/interceptor/json/rpc/JsonRPCSchemaValidation.java
✅ Files skipped from review due to trivial changes (1)
- distribution/tutorials/README.md
🚧 Files skipped from review as they are similar to previous changes (4)
- distribution/src/test/java/com/predic8/membrane/tutorials/security/JsonRpcProtectionTutorialTest.java
- annot/src/main/java/com/predic8/membrane/annot/yaml/error/LineYamlErrorRenderer.java
- core/src/test/java/com/predic8/membrane/core/interceptor/json/rpc/JsonRPCProtectionInterceptorTest.java
- core/src/main/java/com/predic8/membrane/core/interceptor/json/rpc/JsonRPCValidator.java
…onversion logic, and introduce comprehensive tests for attribute parsing.
… if marker is missing, and add test cases
…h Base64 URL encoding, handle colliding method names, and add test coverage.
…idator` usage, remove redundant method, and optimize property name matching with static regex pattern.
…Test` and implement `getMapValueType` in `ScalarValueConverter`.
…mentation to include protected endpoint setup instructions.
…date MCP protection functionality with comprehensive test coverage
…n responses, and ensure correct rule matching
predic8
requested changes
Jun 30, 2026
# Conflicts: # annot/src/main/java/com/predic8/membrane/annot/yaml/ParsingContext.java # annot/src/main/java/com/predic8/membrane/annot/yaml/parsing/binding/ScalarValueConverter.java # core/src/main/java/com/predic8/membrane/core/interceptor/json/rpc/JsonRPCProtectionInterceptor.java # core/src/main/java/com/predic8/membrane/core/interceptor/json/rpc/JsonRPCSchemaValidation.java # core/src/main/java/com/predic8/membrane/core/interceptor/json/rpc/JsonRPCValidator.java # core/src/main/java/com/predic8/membrane/core/util/config/allowdeny/Rule.java # core/src/test/java/com/predic8/membrane/core/interceptor/json/rpc/JsonRPCProtectionInterceptorTest.java
… tests, and apply minor code cleanup.
…ode readability with inline comments.
predic8
approved these changes
Jul 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by CodeRabbit
tools/listfiltering of unauthorized entries.additionalPropertiesschema behavior and safer type coercion.