-
Notifications
You must be signed in to change notification settings - Fork 169
add McpProtection plugin #2977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
add McpProtection plugin #2977
Changes from all commits
Commits
Show all changes
71 commits
Select commit
Hold shift + click to select a range
899be42
init
christiangoerdes 9a15d18
Implement JSON-RPC request validation with rules and batch support
christiangoerdes 69d37c7
Add unit tests for JsonRPCProtectionInterceptor
christiangoerdes 9b7da29
Refactor JSON-RPC validation logic into JsonRPCValidator for improved…
christiangoerdes 9222fc2
Add JSON-RPC parameter schema validation with unit tests
christiangoerdes 89e6590
Support JSON-RPC parameter schema validation with regex-based method …
christiangoerdes 8a57b48
Merge branch 'master' into json-rpc-protection
christiangoerdes 5a225af
Make `fromNode` method public in JSONRPCRequest, add logging to JsonR…
christiangoerdes 329ee81
Merge remote-tracking branch 'origin/json-rpc-protection' into json-r…
christiangoerdes 5bd32da
Add Javadoc comments for JSON-RPC protection classes with detailed de…
christiangoerdes 4fd835a
Support XML-style parameter mappings for JSON-RPC schema validation a…
christiangoerdes de22caa
Refactor JSON-RPC validation: rename `rules` to `methods` and improve…
predic8 c4b7d4d
Merge remote-tracking branch 'origin/json-rpc-protection' into json-r…
predic8 6825c32
Fix test failures: set batch rules before interceptor init
christiangoerdes 7d431c3
Filter child elements excluded from JSON schema in `JsonSchemaGenerat…
christiangoerdes c25259c
Refactor Allow/Deny rule hierarchy: move to util.allowdeny, rename me…
christiangoerdes fd8d1f7
Reject non-JSON content types in `JsonRPCProtectionInterceptor` with …
christiangoerdes 7ce7007
Merge branch 'master' into json-rpc-protection
christiangoerdes c1bab2b
Move Allow/Deny rules to `util.config.allowdeny` package and update a…
christiangoerdes f52a9a6
Add JSON-RPC protection tutorial with method filtering, parameter val…
christiangoerdes cd0bd99
Add tests for JSON-RPC protection tutorial covering method filtering,…
christiangoerdes fe0833b
Switch JSON-RPC `params` method matching from regex to exact names an…
christiangoerdes f7d963f
Add result schema validation to JSON-RPC protection and refactor sche…
christiangoerdes f223210
Add JSON-RPC result schema validation for `rpc.echo` with test update…
christiangoerdes 92bb547
disable response handling when result mappings are empty
christiangoerdes 0b4ed0c
Update JSON-RPC protection tutorial and tests to use consistent `id` …
christiangoerdes 2519939
Add schema validation support for JSON-RPC `params`, `response`, and …
christiangoerdes 79f985a
Remove deprecated JSON-RPC `params` and `result` schema handling, rep…
christiangoerdes f957fdf
Remove redundant body empty check in `JsonRPCProtectionInterceptor` s…
christiangoerdes 24db336
Add copyright headers to JSON-RPC interceptor classes
christiangoerdes 666c123
Merge branch 'master' into json-rpc-protection
christiangoerdes 7ba583f
Add inline schema support for JSON-RPC `error` validation, enhance do…
christiangoerdes 63ec1ea
Merge remote-tracking branch 'origin/json-rpc-protection' into json-r…
christiangoerdes f7d5cbd
Use inline schema in tutorial
christiangoerdes 7a1e798
Add response schema validation for JSON-RPC methods, update tests wit…
christiangoerdes edc038e
Rename JSON-RPC schema-related classes for clarity, refactor usage in…
christiangoerdes 941bb11
Refactor JSONPath segment processing logic, enhance error rendering w…
christiangoerdes 742b367
Improve documentation for JSONPath property encoding and `@MCOtherAtt…
christiangoerdes 0d3a074
Fix formatting in JSON-RPC-Protection tutorial configuration
christiangoerdes 8c8169e
Merge branch 'master' into json-rpc-protection
christiangoerdes c917dd1
Restructure JSON-RPC tutorial: adjust file hierarchy, refine document…
christiangoerdes 98d7223
Update JSON-RPC tutorials: restructure file hierarchy, rename configu…
christiangoerdes 37713aa
Add new tests for JSON-RPC allow/deny methods, batch validation, and …
christiangoerdes 6017a0e
Refactor JSON-RPC Allow/Deny and Batch Validation tutorial: simplify …
christiangoerdes d6373ab
Update JSON-RPC Allow/Deny and Batch Validation tutorial: add demo ba…
christiangoerdes 60f3c4d
Add MCPProtectionInterceptor and related classes: implement JSON-RPC …
christiangoerdes c61bbd2
Add comprehensive tests for MCPProtectionInterceptor: validate JSON-R…
christiangoerdes bc77e5f
Add error suppression for rejected JSON-RPC notifications and enhance…
christiangoerdes 89f71ee
Merge branch 'master' into mcp-protection
christiangoerdes c1c0405
Filter denied tools from `tools/list` responses and add unaltered han…
christiangoerdes 926bed4
Refactor JSON-RPC validation logic: replace inline `payloadType` meth…
christiangoerdes 22fcf31
Update JSON-RPC Protection tutorial: rename methods to reflect read-o…
christiangoerdes b0a054b
Enhance JSON-RPC validation: allow ignoring notification responses wh…
christiangoerdes c2f14f4
Refactor LineYamlErrorRenderer: introduce public methods for JSONPath…
christiangoerdes 7167f14
Add comprehensive tests for JSONPath segment parsing logic in LineYam…
christiangoerdes 20fa54d
Merge branch 'master' into json-rpc-protection
christiangoerdes 271fa07
Merge branch 'json-rpc-protection' into mcp-protection
christiangoerdes 2a9e558
Add type-safe support for `MCOtherAttributes`, enhance scalar value c…
christiangoerdes e9ce647
Add request marker for JSON-RPC eligibility, skip response validation…
christiangoerdes 940be96
Improve JSON-RPC schema location creation: replace sanitize logic wit…
christiangoerdes 4faa710
Reject unmatched JSON-RPC error response IDs and add corresponding te…
christiangoerdes 09af67d
Refactor JSON-RPC validation: replace `getValidator` with direct `val…
christiangoerdes 108ad86
Add comprehensive tests for map value type inference in `MethodSetter…
christiangoerdes e42eecc
Add tutorial for `mcpProtection`, restrict MCP tools, and update docu…
christiangoerdes fa6a1b2
Add `McpProtectionTutorialTest` and `AbstractMcpTutorialTest` to vali…
christiangoerdes 5f4b3d9
Merge branch 'master' into mcp-protection
christiangoerdes 0214642
Add tests to validate MCP tool restriction logic, hide denied tools i…
christiangoerdes 5dfb8bf
Merge branch 'master' into mcp-protection
christiangoerdes f4e3d0c
Merge branch 'master' into mcp-protection
christiangoerdes f0ee1cb
Extract `JsonPathUtil` from `LineYamlErrorRenderer`, relocate related…
christiangoerdes 8c43051
Add tests for `ScalarValueConverter`, document methods, and improve c…
christiangoerdes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
99 changes: 99 additions & 0 deletions
99
annot/src/main/java/com/predic8/membrane/annot/util/JsonPathUtil.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /* Copyright 2026 predic8 GmbH, www.predic8.com | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. */ | ||
|
|
||
| package com.predic8.membrane.annot.util; | ||
|
|
||
| import com.predic8.membrane.annot.yaml.ParsingContext; | ||
|
|
||
| public final class JsonPathUtil { | ||
|
|
||
|
|
||
| private JsonPathUtil() {} | ||
|
|
||
| /** | ||
| * Returns the parent path before the last JSONPath segment. | ||
| * | ||
| * @param jsonPath JSONPath created by {@link ParsingContext} | ||
| * @return parent path without the last segment | ||
| */ | ||
| public static String getParentPath(String jsonPath) { | ||
| return jsonPath.substring(0, findLastSegmentStart(jsonPath)); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the last part of a JSONPath created by {@link ParsingContext}. | ||
| * <p> | ||
| * Examples: | ||
| * {@code $.api.methods} -> {@code methods} | ||
| * {@code $.api.methods['rpc.echo']} -> {@code rpc.echo} | ||
| * {@code $.api.methods[0]} -> {@code 0} | ||
| * | ||
| * @param jsonPath JSONPath created by {@link ParsingContext} | ||
| * @return unescaped field name or array index of the last segment | ||
| */ | ||
| public static String getLastSegment(String jsonPath) { | ||
| String segment = jsonPath.substring(findLastSegmentStart(jsonPath)); | ||
|
|
||
| if (segment.startsWith(".")) { | ||
| return segment.substring(1); | ||
| } | ||
|
|
||
| if (isQuotedPropertySegment(segment)) { | ||
| return decodeQuotedPropertySegment(segment); | ||
| } | ||
|
|
||
| if (isArrayIndexSegment(segment)) { | ||
| return segment.substring(1, segment.length() - 1); | ||
| } | ||
|
|
||
| throw new IllegalArgumentException("Unsupported JSONPath segment: " + segment); | ||
| } | ||
|
|
||
| private static boolean isQuotedPropertySegment(String segment) { | ||
| return segment.startsWith("['") && segment.endsWith("']"); | ||
| } | ||
|
|
||
| private static boolean isArrayIndexSegment(String segment) { | ||
| return segment.startsWith("[") && segment.endsWith("]"); | ||
| } | ||
|
|
||
| /** | ||
| * Removes JSONPath bracket quoting and unescapes supported characters. | ||
| */ | ||
| private static String decodeQuotedPropertySegment(String segment) { | ||
| return segment.substring(2, segment.length() - 2) | ||
| .replace("\\'", "'") | ||
|
|
||
| .replace("\\\\", "\\"); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the start index of the last JSONPath segment. | ||
| */ | ||
| private static int findLastSegmentStart(String jsonPath) { | ||
| int depth = 0; | ||
| for (int i = jsonPath.length() - 1; i >= 0; i--) { | ||
| char c = jsonPath.charAt(i); | ||
| if (c == ']') { | ||
| depth++; | ||
| } else if (c == '[') { | ||
| depth--; | ||
| } | ||
| if (depth == 0 && (c == '.' || c == '[')) { | ||
| return i; | ||
| } | ||
| } | ||
| throw new IllegalArgumentException("Cannot determine parent path of: " + jsonPath); | ||
| } | ||
| } |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.