Repository navigation
feat: describe PromQL sources in MCP - #3496
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: bee902c The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🟡 Tier 3 — StandardIntroduces new logic, modifies core functionality, or touches areas with non-trivial risk. Why this tier:
Review process: Full human review — logic, architecture, edge cases. Stats
|
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
PR Review
4 finding(s): 🔴 0 critical · 🟠 0 major · 🔵 4 minor 3 posted as inline comment(s) on the changed lines. 1 listed below. Findings outside the changed lines1 minor
Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides. |
[Medium impact] The PR appears safe to merge; both previous findings are fixed and no new blocking issue was found. SummaryAdds PromQL source descriptions to MCP and hides PromQL sources when the feature is disabled.
Reviews (2) · Last reviewed commit: "fix: Send Prometheus host credentials as..." · Reviewed by Greptile |
Deep Review✅ No critical issues found. No P0/P1 ship-blockers. Credential handling and the PromQL visibility gate are implemented carefully and backed by integration tests: credentials are stripped from the URL into a Basic auth header before 🟡 P2 -- recommended
🔵 P3 nitpicks (4)
Reviewers (6): previous-comments, security, testing, maintainability, reliability, kieran-typescript. (correctness and adversarial were dispatched but did not return before synthesis; their focus area -- the Testing gaps:
No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
E2E Test Results✅ All tests passed • 459 passed • 1 skipped • 1698s
Tests ran across 4 shards in parallel. |
63f6286 to
b7ee9a5
Compare
| const params = { | ||
| start: String(startMs / 1000), | ||
| end: String(endMs / 1000), | ||
| limit: String(limit + 1), | ||
| }; | ||
| const [labelNames, metricNames] = await Promise.all([ | ||
| fetchPrometheusData( | ||
| connection.host, | ||
| '/api/v1/labels', | ||
| params, | ||
| labelListSchema, | ||
| signal, | ||
| ), | ||
| fetchPrometheusData( | ||
| connection.host, | ||
| '/api/v1/label/__name__/values', | ||
| params, | ||
| labelListSchema, | ||
| signal, | ||
| ), | ||
| ]); |
There was a problem hiding this comment.
I expect we might have to tune this on another iteration. For some set with hundreds of thousands of series, the values could be tens to hundreds of megabytes.
There was a problem hiding this comment.
Good call, yes. I'll add a PR to cap this somehow at the end of the stack
| ); | ||
| recordProxyOutcome(status, 'query_range', backend); | ||
| return; | ||
| } |
There was a problem hiding this comment.
Do you think it makes sense to reuse the new fetchPrometheusData function in prometheus queries like this?
There was a problem hiding this comment.
fetchPrometheusData buffers and parses the whole body and throws on errors, which suits the MCP here. But the router streams responses and passes the status and error body through, so swapping it in would change that behaviour. I have a PR (3rd in the stack) almost ready where the backend choice is moved into controllers/promql.ts. I'll refactor a bit to dedupe some of the request building and move into a shared helper.
2065833 to
0107212
Compare
0107212 to
426f709
Compare
426f709 to
8fa97cc
Compare
…abled describe_source returns a PromQL source's label names and metric names instead of a column schema, from a ClickHouse TimeSeries table or a Prometheus-compatible endpoint. list_sources and describe_source show each PromQL source's backend. A TimeSeries source keeps its table, with a hint for reading it through clickstack_sql's timeSeriesTags and timeSeriesData table functions. A Prometheus endpoint source drops its placeholder database and table. With ENABLE_PROMQL off, MCP hides PromQL sources from list_sources, describe_source, delete_source and the create_dashboard prompt, and save_source drops promql from its kind enum. Move joinPrometheusUpstreamUrl into a new promql controller so MCP can reach Prometheus endpoints without importing the Express router.
…timeout fetch rejects a URL that carries credentials, so a Prometheus host with user:pass@ failed every label lookup. Send them as a Basic auth header. Pass the tool's abort signal to the ClickHouse label queries, and set the describe_source snapshot before the lookup starts so a timed-out PromQL describe still returns the source config.
…roxy proxyToPrometheus passed the connection host to fetch with its userinfo, which fetch rejects, so every PromQL query to a host like http://user:pass@prometheus:9090 failed with a 502. The ClickHouse Prometheus API probe had the same problem. Both now use the header that the MCP label lookup sends.
8fa97cc to
bee902c
Compare
Summary
First PR for PromQL support in MCP: the source tools now understand PromQL sources and hide them when PromQL is disabled.
clickstack_describe_sourcereturns a PromQL source's label names and metric names instead of a column schema, from either a ClickHouse TimeSeries table or a Prometheus-compatible endpoint.clickstack_list_sourcesandclickstack_describe_sourceshow each PromQL source'sbackend. TimeSeries sources keep theirtableand get a hint for reading it withclickstack_sqlthroughtimeSeriesTags/timeSeriesData. Prometheus endpoint sources drop their placeholder database and table.ENABLE_PROMQLoff, PromQL sources are hidden fromlist_sources,describe_source,delete_sourceand thecreate_dashboardprompt, andsave_sourceno longer acceptskind: "promql".joinPrometheusUpstreamUrlinto a newcontrollers/promql.tsso MCP can reach Prometheus endpoints without importing the Express router.How to test
ENABLE_PROMQL=true NEXT_PUBLIC_ENABLE_PROMQL=true yarn dev. The dev collector already writes PromQL metrics todefault.metrics_ts.clickstack_list_sources. Verify the PromQL source shows"backend": "clickhouse"and"table": "default.metrics_ts", and the output includespromqlUsage.clickstack_describe_sourcewith the PromQL source ID. Verify it returnslabelNames,metricNames, and anextSteps.sqlhint.ENABLE_PROMQL. Verifyclickstack_list_sourcesno longer lists the PromQL source orpromqlUsage.clickstack_describe_sourceandclickstack_delete_sourcewith the PromQL source ID. Verify both return "not found" and the source still exists in the UI.References