Repository navigation
feat(mcp): accept sourceId in clickstack_sql so $__sourceTable resolves - #3355
Conversation
🦋 Changeset detectedLatest commit: 1731b9f 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 |
|
@squaredg is attempting to deploy a commit to the HyperDX Team on Vercel. A member of the Team first needs to authorize it. |
|
| 'connection or drop sourceId from the call.', | ||
| ); | ||
| } | ||
| } else if (hasMacro(input.sql, 'sourceTable')) { |
There was a problem hiding this comment.
SQL comments block valid queries
hasMacro also matches $__sourceTable inside SQL comments. Without sourceId, a query such as SELECT 1 /* previously FROM $__sourceTable */ now returns an error even though the renderer skips that comment. Use the renderer's comment-aware scan for this check and add a test for a commented-out macro.
clickstack_sql took only a connectionId, so agents had to write table names themselves and guessed them. $__sourceTable already exists, and raw SQL dashboard tiles resolve it through runConfigTile; the MCP tool just never accepted a source. Add an optional sourceId, passed to the tile. Reject a source that does not exist or belongs to another team, a source whose connection differs from connectionId, and $__sourceTable without a sourceId (the renderer's own message says to select a source in the UI). The time-series example now reads FROM $__sourceTable.
a59ccf6 to
1731b9f
Compare
Deep Review✅ No critical issues found. The change is small and well-scoped: an optional 🔵 P3 nitpicks (1)
Reviewers (7): correctness, security, testing, maintainability, api-contract, kieran-typescript, previous-comments. 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 |
Summary
clickstack_sqltakes only aconnectionId, so an agent has to write the table name itself, and it often guesses wrong (#3354 covers the guessing).$__sourceTablealready exists in common-utils, and raw SQL dashboard tiles resolve it throughrunConfigTile. The MCP SQL tool just never accepted a source.This adds an optional
sourceIdtoclickstack_sqland passes it to the tile, so$__sourceTableexpands to that source'sdatabase.table. It reuses the existingrunConfigTilepath that dashboard tiles use.Checks on the input:
sourceIdthat doesn't exist or belongs to another team is rejected as "Source not found".connectionIdis rejected. Otherwise$__sourceTablewould expand against a table on another server.$__sourceTablewithout asourceIdis rejected with an error that says to pass one. Today the renderer's message comes through instead ("requires a source to be selected"), which is written for the dashboard UI.The time-series example now reads
FROM $__sourceTable. The table example keepsFROM <table>to show the path for tables that aren't registered as sources.Tests (all failed before the change):
$__sourceTableresolves to the source's table (counts seeded rows).$__sourceTablewithoutsourceIdis rejected, and the error says to pass one.sourceIdand another team'ssourceIdare both rejected as not found.connectionIdis rejected.sourceId.$__sourceTableand the table example uses<table>.This matches the
sourceIdhandling in our enterprise build, which has had it since source filters were added. That build also scopes it with source filters and RBAC, which aren't part of OSS and aren't included here.How to test on Vercel preview
N/A — non-UI change.
References
🤖 Generated with Claude Code