Repository navigation
fix(mcp): run the metric write checks on mcp creates and patches - #36955
Conversation
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
| securityContext, | ||
| new OperationContext(entityType, jsonPatch), | ||
| new ResourceContext<>(entityType, null, fqn, ResourceContextInterface.Operation.PATCH)); | ||
| MetricAuthorization.authorizePatch(authorizer, securityContext, entityType, fqn, jsonPatch); |
There was a problem hiding this comment.
Design. PatchEntityTool and CreateEntityTool are type-blind, but they now call a metric class from the REST resources package by name (here and at CreateEntityTool.java:86). That has two costs:
- A future resource-level write check has to be remembered here too, or its type added to
DEDICATED_PATCH_LIFECYCLES/DEDICATED_CREATE_FLOWS. - The checks run on a separate copy of the entity, with the patch applied a second time. That copy is where the
add /owners/-400 came from.
Suggestion. There's already one place where checks like these run on every update: EntityRepository.admit(original, updated, actor, edit). Since ADR 2026-10-21-domain-moves-are-authorized-in-the-write-pipeline, it authorizes domain moves there with authorizer.authorizeActor, before the approval gate. PATCH (REST and this tool), PUT, bulk PUT and CSV import all go through it, using the original and updated entity that the write itself built.
A possible shape:
- A
protected void authorizeWrite(T original, T updated, ChangeActor actor)hook onEntityRepository, doing nothing by default.admitcalls it right after the domain check, and skips system actors the way the domain check does. MetricRepositoryandMetricGroupRepositoryoverride it with whatMetricAuthorizationchecks today (the moved subtree and its destinations, membership changes, requested assets), throughauthorizeActor.- Create has no
admittoday, socreateInternalcalls the same hook withoriginal == null.
With that in place, several things can go:
- the calls in
MetricResource,MetricGroupResource,CreateEntityToolandPatchEntityTool; - the copy-and-reapply step;
- MCP's import of
service.resources.metrics.
The read-only field check (assets, children, childrenCount) could move to the metric repository's patch path, so REST and MCP share it there too.
Two things are worth confirming first:
- The
originalthat reachesadmiton the PUT and import paths carriesparent,metricGroupandmetrics. PATCH already loads them through the patch fields. updatedis already prepared at that point (parent resolved, group subtree expanded).
It deletes more code than it adds, so it might fit in this PR. A follow-up works too.
There was a problem hiding this comment.
Agree, this is the better shape and it fixes the drift our ADR calls out. I'd keep this PR as is since it closes the gap now, and do the hook in a follow-up: it has to sit in authorizeDomainWrite (admit, previewPatch, the CSV batch and the bulk loop all call it) plus createInternal, and it overlaps with the metric CSV checks in #36792, so I'd rather sort that in one go. Both of your checks hold: PUT/import originals carry parent and metricGroup (and metrics for groups), and updated is prepared before admit.
Follow-up: #37030
Code Review ✅ Approved🔴 High risk · Adding EditAll checks to metric hierarchy and group writes changes authorization; users lacking access to affected metrics or destinations could have legitimate writes denied. Moves the metric write checks (EditAll on touched metrics and destinations, asset view access, read-only field checks) into a shared VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
|
Resolves the conflict with #36955, which moved the metric and metric group write checks into MetricAuthorization for REST and MCP: - MetricAuthorization now rejects document-root metric patches, refuses a copy, move or test that reads a relation field into another field, requires view on every member for a group patch that addresses members, and masks JSON-P errors on group patches. - The REST resources still authorize the patch before simulating it, and the group member pin with its 412 stays in MetricGroupResource. - MCP patch_entity no longer refuses metric hierarchy and membership changes; it runs the same checks through MetricAuthorization.
#37110) MetricGroupResource.patch now loads the stored group with repository.get before authorizing the patch (#36955). The test added in #36764 only stubbed getWithMembers, so get returned null and applyPatch failed with "Expected a JSON object or array", failing openmetadata-service unit tests on main.



Describe your changes:
Fixes #36956
create_entityandpatch_entityskipped the checks the metric and metric group REST endpoints run on top of the policy check: EditAll on the metrics a move or group change touches and on the parent or group they land in, view access to the assets a new metric links, and the read-only metric fields.MetricAuthorization, which the REST create, PUT, PATCH and metric bulk endpoints and both MCP tools call. Metric CSV import still skips them, tracked in https://github.com/open-metadata/openmetadata-collate/issues/8228. Decision record:ADR:2026-11-03-metric-writes-run-the-same-checks-through-rest-and-mcp.replacepatch on a metric now counts as a hierarchy change. It skipped the parent and group check on REST too. The checks also run on a copy loaded with the same fields the real patch uses, which fixes RESTPATCH /v1/metricGroups/{id}withadd /owners/-returning 400.Behaviour change: an MCP write to a metric or group that REST refuses now gets the same 403. An MCP patch that sets a metric's
assets,childrenorchildrenCountis a 400 instead of being ignored.Type of change:
Tests:
Unit tests
MetricResourceTest#wholeDocumentReplaceCountsAsAHierarchyChange. The existingMetricResourceTest/MetricGroupResourceTestcases now call the moved checks.Backend integration tests
McpMetricAuthorizationIT: as a user who may edit everything except metrics taggedPII.Sensitive,patch_entityrefuses moving a metric under, or adding to a group, a metric the user cannot edit, andcreate_entityrefuses creating a metric or a group that would. Each case first does the allowed version, and all 4 fail before this change. A fifth case checks that appending an owner to a group, or to a metric while moving it, still works while the checks run.MetricResourceIT#hierarchyWritesRequireEditPermissionOnParentAndGroupDestinations: a whole-document replace that sets a restricted parent is now 403. It returned 200 before this change.MetricGroupResourceIT#patch_appendsAnOwnerThroughTheMembershipCheck:add /owners/-on a group succeeds. It returned 400 before this change.Local Java test run: PASSED
8af9d60ce1a2(baseorigin/main)Checklist:
REVIEW.mdand fixed every 🔴 finding, or answered it on the line below.Reviewed
8af9d60ce1a. Not changed: a whole-document replace carryingassets,childrenorchildrenCountis not refused, as on main, but none of them is written (assetslinks only on PUT,childrenis restored).ADR:2026-11-03-metric-writes-run-the-same-checks-through-rest-and-mcp.