Skip to content

mcp: split mz_mcp_data_products into lightweight discovery and detailed views#35747

Merged
bobbyiliev merged 1 commit intoMaterializeInc:mainfrom
bobbyiliev:mcp-split-data-product-views
Mar 30, 2026
Merged

mcp: split mz_mcp_data_products into lightweight discovery and detailed views#35747
bobbyiliev merged 1 commit intoMaterializeInc:mainfrom
bobbyiliev:mcp-split-data-product-views

Conversation

@bobbyiliev
Copy link
Copy Markdown
Contributor

@bobbyiliev bobbyiliev commented Mar 27, 2026

Fixes: https://linear.app/materializeinc/issue/DEX-18/mcp-benchmark-agents-endpoint-and-optimize-mz-mcp-data-products-view

Splitting the mz_mcp_data_products into two views to improve discovery performance:

  • mz_mcp_data_products: just a lightweight view returning just name, cluster, and description (fewer joins, no JSON aggregation)
  • mz_mcp_data_product_details: the full view with JSON Schema column for agents that need column-level detail

The get_data_products tool now hits the lightweight view, while get_data_product_details queries the full view. Local benchmarks at 1500 data products show ~25% improvement on the discovery path.

Tagging @ggevay in case that you have some suggestions for further optimizations to those 2 builtin views 🙏

@github-actions
Copy link
Copy Markdown
Contributor

Thanks for opening this PR! Here are a few tips to help make the review process smooth for everyone.

PR title guidelines

  • Use imperative mood: "Fix X" not "Fixed X" or "Fixes X"
  • Be specific: "Fix panic in catalog sync when controller restarts" not "Fix bug" or "Update catalog code"
  • Prefix with area if helpful: compute: , storage: , adapter: , sql:

Pre-merge checklist

  • The PR title is descriptive and will make sense in the git log.
  • This PR has adequate test coverage / QA involvement has been duly considered. (trigger-ci for additional test/nightly runs)
  • If this PR includes major user-facing behavior changes, I have pinged the relevant PM to schedule a changelog post.
  • This PR has an associated up-to-date design doc, is a design doc (template), or is sufficiently small to not require a design.
  • If this PR evolves an existing $T ⇔ Proto$T mapping (possibly in a backwards-incompatible way), then it is tagged with a T-proto label.
  • If this PR will require changes to cloud orchestration or tests, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label (example).

@bobbyiliev bobbyiliev marked this pull request as ready for review March 27, 2026 10:51
@bobbyiliev bobbyiliev requested review from a team as code owners March 27, 2026 10:51
@bobbyiliev bobbyiliev requested a review from ohbadiah March 27, 2026 10:51
represents a queryable dataset with a defined schema.
The `mz_mcp_data_products` view lists data products (indexed materialized views)
available through the Model Context Protocol (MCP) server that the current user
has privileges to access. This is a lightweight discovery view — use
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an ambiguity w.r.t. what the "that the current user has privileges to access" is referring to. Did you mean more:

The mz_mcp_data_products view lists data products (i.e., indexed materialized views) that are available through the Model Context Protocol (MCP) server and that the current user can access.

@bobbyiliev bobbyiliev force-pushed the mcp-split-data-product-views branch 2 times, most recently from 762c2d8 to 06bc662 Compare March 28, 2026 07:10
@bobbyiliev bobbyiliev requested review from ggevay, jubrad and kay-kim March 28, 2026 07:59
Copy link
Copy Markdown
Contributor

@ggevay ggevay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, unfortunately our RBAC functions are crazy slow. Here specifically pg_has_role is the bottleneck (which comes in twice, once through mz_show_my_object_privileges, and once through mz_show_my_cluster_privileges). There have been some recent discussions in trying to speed it up, because it's also hurting some Console queries: https://materializeinc.slack.com/archives/C06GZ7GBKB5/p1767631065049339?thread_ts=1767080460.197769&cid=C06GZ7GBKB5

If the performance is unacceptable for the MCP stuff, then we could certainly schedule some work on this. By just speeding up pg_has_role by rewriting it in Rust instead of SQL (https://github.com/MaterializeInc/database-issues/issues/11262), we could gain ~2x here (which we can see by temporarily commenting out pg_has_role). Then, to further speed things up, we could work on some optimizer slowness in EquivalencePropagation. There are some ideas here: https://github.com/MaterializeInc/database-issues/issues/8470.

@bobbyiliev bobbyiliev force-pushed the mcp-split-data-product-views branch from 06bc662 to 079272d Compare March 30, 2026 09:15
@bobbyiliev bobbyiliev enabled auto-merge (squash) March 30, 2026 09:18
@bobbyiliev
Copy link
Copy Markdown
Contributor Author

Yeah, unfortunately our RBAC functions are crazy slow. Here specifically pg_has_role is the bottleneck (which comes in twice, once through mz_show_my_object_privileges, and once through mz_show_my_cluster_privileges). There have been some recent discussions in trying to speed it up, because it's also hurting some Console queries: https://materializeinc.slack.com/archives/C06GZ7GBKB5/p1767631065049339?thread_ts=1767080460.197769&cid=C06GZ7GBKB5

If the performance is unacceptable for the MCP stuff, then we could certainly schedule some work on this. By just speeding up pg_has_role by rewriting it in Rust instead of SQL (MaterializeInc/database-issues#11262), we could gain ~2x here (which we can see by temporarily commenting out pg_has_role). Then, to further speed things up, we could work on some optimizer slowness in EquivalencePropagation. There are some ideas here: MaterializeInc/database-issues#8470.

Thanks @ggevay I've created a tracking issue for this: https://linear.app/materializeinc/issue/DEX-19/mcp-improve-mz-mcp-data-products-view-performance-by-addressing-pg-has

@bobbyiliev bobbyiliev merged commit 00e718d into MaterializeInc:main Mar 30, 2026
122 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants