Repository navigation
Fixes #34270: Make the MCP knowledge-graph tools usable by non-admins for column lineage at scale - #34790
Conversation
…dex projection shape
…gent SPARQL ADR
…rification evidence
…ey call the tools
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
…, not from an authorization exception
…' executeAuthorized
…e in the reindex wait
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
…t amends so the Flowable ALTER DATABASE stays last
… over the real /mcp endpoint
…ore the read only
… default and an administrator can lower it
🚦 Removed from the merge queue —
|
🚦 Removed from the merge queue —
|
…rebuilt since 2.1 does not prove there is no lineage
Code Review ✅ Approved 1 closed / 1 findings🔴 High risk · Granting MCP graph reads under the default ExecuteSparqlQuery policy could reveal unfiltered metadata about assets users cannot otherwise view. Makes the MCP knowledge-graph tools ( ✅ 1 closed✅ Quality: MCP agent-profile audit always logs serviceActor=null
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 |
|
🚦 Removed from the merge queue —
|



Describe your changes:
Fixes #34270
The MCP server has had knowledge-graph tools since #28042, but only administrators could call them, so in practice no MCP user, and no bot token, could ask the graph anything. One customer needed the full column lineage of a column (4,523 edges).
get_entity_lineageclipped it to 139, and the graph tools were closed to them.This PR makes those tools usable for that question:
ExecuteSparqlQueryinstead of admin-only;sparql_querydescription teaches paging and the column-lineage query, and multi-hop traversal is verified at about 5,000 column mappings.Where RDF is off the graph tools are not offered at all (see "Done when (c)" below).
It extends the existing RDF MCP tools in the shared OpenMetadata implementation, which Collate's MCP server (
CollateMcpServer extends McpServer) also uses, so the change reaches Collate and OSS users alike. It does not touchget_entity_lineage(separate MCP work) or asset-level SPARQL RBAC (#33224).What changes
sparql_queryExecuteSparqlQuery; non-admins get the agent profile, admins keep today's behavior unchangedentity_neighborhood,find_by_tagExecuteSparqlQueryontology_describewithoutresourceGET /v1/rdf/ontology)ontology_describewithresourceExecuteSparqlQueryshacl_validatefullGraph=trueloads up to 100k triples)Non-admin
sparql_query: SELECT only, JSON output, inference forced tonone, noFROM/GRAPH/SERVICE/CALL/java:, projection must beREADYbefore and after execution, an audit event per call that passes authorization, attributed to the MCP bot as service actor (refusals are logged by the MCP layer's authorization handling), and acompletenessfield on the result.find_by_tag,entity_neighborhoodandontology_describe(resource)apply the sameREADYcheck for non-admins; admins are unchanged. These three tools check readiness before the read only (ADR A3). Bot tokens have no special case, but by default every bot holds the grant:POST /v1/userswithisBot=trueattachesDefaultBotRole, which includesDataConsumerPolicy, which shipsDataConsumerPolicy-ExecuteSparqlQuery-Rule(#34253). A bot loses access only if that rule is removed or a policy denies the operation.The
sparql_querydescription now carries the column-lineage template (column-IRIom:fromColumn/om:toColumnform since #34970, paging, asset-type/service/owner/tier filters). Data-model facts only, no agent routing strategy. A vocabulary test pins everyom:term it uses against the ontology and the live projection.Done when (c), RDF off: with RDF off the graph tools (
sparql_query,entity_neighborhood,find_by_tag,shacl_validate) are not offered intools/list(existing gating, unchanged), and a direct call is refused by the SDK before the server's tool code runs.ontology_describestays offered, andontology_describe(resource)answers 400 "RDF knowledge graph is not enabled" (covered byMcpRdfNotEnabledIT).Behavior changes beyond the RDF tools:
DefaultToolContextnow classifiesQueryCapacityException(and the new retry-later exception) as 429 for every MCP tool, the administrator path ofsparql_queryincluded. It was 500 before.sparql_querybehavior; their call goes through the old code path unchanged.Type of change:
High-level design:
RdfMcpTool.executestaysfinaland calls an overridableauthorizehook. The default requiresExecuteSparqlQueryon the RDF resource (reusingRdfQueryResourceContext);shacl_validateoverrides it back to admin, andontology_describeskips it when noresourceis given. Authorization runs before the RDF-enabled check, so an unauthorized caller learns nothing about deployment configuration.SparqlQueryToolpicks the profile fromDefaultAuthorizer.getSubjectContext(...).isAdmin(), the same definitionauthorizeAdminuses and the pattern other MCP tools already follow; the admin branch is the previous code. Non-admins go throughAgentSparqlService.forRepository(...), a new shared factory thatRdfResourcealso uses, so the REST endpoint and MCP share one execution profile, guard and audit path.om:fromColumn/om:toColumnreference column IRIs (FQNs are inom:fromColumnFqn/om:toColumnFqn), so traversal binds the start column byom:fullyQualifiedName, walks^om:fromColumn/om:toColumnand the asset join is the inverse path?c (^om:hasChildColumn)*/^om:hasColumn ?asset(the forward form measured ~6.6 s/page vs ~50 ms). Published page size is 250 rows (400 rows overflowed the 80,000-byte MCP body).PUT /v1/lineagewrites andRdfIndexAppboth project column mappings. A store indexed before 2.1 keeps literal endpoints until it is rebuilt, so the tool text tells clients that an empty result there does not prove there is no lineage.ExecuteSparqlQuerycan see aggregates over assets they cannot otherwise view. Same decision as the agent endpoint (Add permissioned read-only SPARQL execution for the 2.1 graph agent tool #33384/Fixes #34231: grant ExecuteSparqlQuery to the Data Consumer role by default #34253); recorded in the ADR amendment "MCP knowledge-graph tools (MCP knowledge-graph tools: non-admin access and column-level lineage at scale #34270)".docs/rdf-ontology-contract.md.Known limitation (pre-existing, tracked in #34826): removing
ExecuteSparqlQueryfrom a policy may not take effect for a principal whose first request after the edit arrives via /mcp. With the default cache providernone, a local run saw the principal stay allowed for at least 171 s while the policy row and API already had the rule removed, and REST andGET /v1/permissions/rdfthen also reported allow; an explicitSubjectCache.invalidateAll()ended it. This is the existing policy-cache behavior (the in-transactionSubjectCache.invalidateAll()inPolicyRepository); this PR does not change it, and it is not shown to be specific to MCP. The "no grant" ITs work around it:RdfAccessFixturesreads the test principals' permissions right after each policy edit (see its Javadoc).Release note: with the #34253 default grant, the MCP graph tools (
sparql_query,entity_neighborhood,find_by_tag,ontology_describewith a resource) are open to every user and bot, and results are not filtered by asset or domain policies (ADR A5). Admins who rely on deny or domain policies for metadata confidentiality should removeDataConsumerPolicy-ExecuteSparqlQuery-Rule; because of #34826 that removal can lag for principals already active over MCP. The rule's description now says which tools it covers; existing installs get the text through an appended, description-only statement in the 2.1.0 migration, and the shipped INSERT is left untouched. After upgrading to 2.1, run a fullRdfIndexApprebuild (recreateIndex=true) so column lineage written before the upgrade uses column IRIs; until then the published column-lineage query can miss those edges.Scope note for reviewers: #34270's checklist includes a "Benchmark" item (a column-lineage row in ai-platform's
collate_graph_routing_v1.tsv). That item is moved out of this PR's scope, so there is no companion ai-platform PR. That benchmark measures how the Collate agent routes betweengetLineageand the graph, not MCP; the MCP capability is proven byRdfMcpKnowledgeGraphIT(a regular user pages all 5,006 column links). The row would be meaningful together with the Collate routing rule, which is separate work, and adding it changes a pinned benchmark contract and invalidates saved baselines.Tests:
Use cases covered
tools/listand refused on direct call;ontology_describewith aresourcereturns 400 "RDF knowledge graph is not enabled".om:hasChildColumn(struct columns) is materialized by an actualRdfIndexApprun.Unit tests
RdfColumnLineageTraversalTest,ColumnLineageFixture(shared fixture built by the two production writers),RdfToolDescriptionVocabularyTest,SparqlQueryToolAgentProfileTest,AgentSparqlToolErrorsTest,RdfToolAuthorization(helper), updates toSparqlQueryToolTest,ShaclValidateToolTest,FindByTagToolTest,EntityNeighborhoodToolTest,OntologyDescribeToolTest,DefaultToolContextTest,AgentSparqlServiceTest,RdfProjectionStateResolverTest.e01ac33c2e: theopenmetadata-serviceunit suite, 11,517 tests, 0 failures, 1 skipped, which includesDataConsumerSparqlGrantSqlMigrationTest28/28 against MySQL 8 and Postgres 15 andFlowableCharsetMigrationTest6/6. Locally the wholeopenmetadata-mcpmodule, 765 tests, 0 failures;mvn spotless:checkonopenmetadata-service,openmetadata-mcpandopenmetadata-integration-testsis clean.Backend integration tests
openmetadata-integration-tests/for new/changed API endpoints.RdfMcpKnowledgeGraphIT(21),McpRdfNotEnabledIT(4), sharedRdfAccessFixtures;AgentSparqlResourceIT(22) re-run becauseRdfResourcenow shares the new factory.e01ac33c2eis 86 pass, 0 fail (22 skipped). In the RDF lane, on MySQL + Elasticsearch (job) and on PostgreSQL + OpenSearch (job),RdfMcpKnowledgeGraphITran 21/21 andAgentSparqlResourceIT22/22.McpRdfNotEnabledITran 4/4 locally (-Ppostgres-opensearch) on an earlier head.Ingestion integration tests
Playwright (UI) tests
Manual testing performed
No manual UI testing; the change has no UI. Verification was through the integration tests above, which run a real RDF store (Fuseki), a real MCP endpoint and real reindexing. Reproduce locally:
mvn -pl openmetadata-integration-tests verify -Ppostgres-rdf-tests -Dit.test='RdfMcpKnowledgeGraphIT,AgentSparqlResourceIT'mvn -pl openmetadata-integration-tests verify -Ppostgres-opensearch -Dit.test='McpRdfNotEnabledIT'(The IT module needs
openmetadata-spec,-sdk,-serviceand-mcpinstalled into the local Maven repository first.)UI screen recording / screenshots:
Not applicable.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.