-
Notifications
You must be signed in to change notification settings - Fork 26
feat(mcp-readability): compliance orchestrator, LLM judge, and metrics scorer #472
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
Open
akangsha7
wants to merge
1
commit into
GoogleCloudPlatform:main
Choose a base branch
from
akangsha7:feat/mcp-readability-compliance-eval
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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
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,3 @@ | ||
| from evaluator.mcp_readability.orchestrator import McpReadabilityOrchestrator | ||
|
|
||
| __all__ = ["McpReadabilityOrchestrator"] |
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,71 @@ | ||
| """Loading and matching of per-endpoint style-rule exceptions (waivers). | ||
|
|
||
| An exceptions file lets an operator waive a specific style requirement for a | ||
| specific endpoint when it legitimately cannot comply. Waived rules are passed to | ||
| the scorer so they are excluded from the P0/P1/P2 counts and surfaced separately | ||
| in the feedback. | ||
|
|
||
| File schema (see ``datasets/mcp_readability/exceptions.yaml``):: | ||
|
|
||
| exceptions: | ||
| - product_name: "Cloud SQL" # any of product_name / endpoint_type | ||
| rule_id: "tool-names" | ||
| reason: "..." | ||
| - endpoint_type: AUTOPUSH # "*" or omitted field = match-all | ||
| rule_id: "use-enums" | ||
| reason: "..." | ||
| """ | ||
|
|
||
| import logging | ||
| from util.config import load_yaml_config | ||
|
|
||
|
|
||
| def load_exceptions(path: str) -> list[dict]: | ||
| """Load the exceptions list from a YAML file. Missing/empty -> [].""" | ||
| if not path: | ||
| return [] | ||
| parsed = load_yaml_config(path) | ||
| if not parsed: | ||
| return [] | ||
| exceptions = parsed.get("exceptions") or [] | ||
| if not isinstance(exceptions, list): | ||
| logging.warning( | ||
| "mcp_readability: 'exceptions' in %s is not a list; ignoring.", path | ||
| ) | ||
| return [] | ||
| return exceptions | ||
|
|
||
|
|
||
| def _matches(field_value, exception_value) -> bool: | ||
| """A matcher field matches when it is absent, '*', or equal (case-insensitive).""" | ||
| if exception_value is None or exception_value == "*": | ||
| return True | ||
| if field_value is None: | ||
| return False | ||
| return str(field_value).strip().lower() == str(exception_value).strip().lower() | ||
|
|
||
|
|
||
| def applicable_exceptions(endpoint: dict, all_exceptions: list[dict]) -> list[dict]: | ||
| """Return exceptions whose matchers all apply to ``endpoint``. | ||
|
|
||
| Matchers considered: ``product_name`` and ``endpoint_type`` (the endpoint's | ||
| identity in #469's ``endpoints.yaml``). Each exception keeps its ``rule_id`` | ||
| and ``reason`` for the scorer prompt. | ||
| """ | ||
| matched = [] | ||
| for exc in all_exceptions: | ||
| if not isinstance(exc, dict): | ||
| continue | ||
| if not exc.get("rule_id"): | ||
| continue | ||
| if ( | ||
| _matches(endpoint.get("product_name"), exc.get("product_name")) | ||
| and _matches(endpoint.get("endpoint_type"), exc.get("endpoint_type")) | ||
| ): | ||
| matched.append( | ||
| { | ||
| "rule_id": exc.get("rule_id"), | ||
| "reason": exc.get("reason", ""), | ||
| } | ||
| ) | ||
| return matched |
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.