Repository navigation
refactor(api): look up MCP connections through one helper - #3776
Conversation
Add mcp/utils/connections.ts (getMcpConnections, getMcpConnection, validateMcpConnectionId) taking the full McpContext, and route every MCP tool and prompt connection lookup through it, including getMcpClickhouseClient. No behavior change.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🔵 Tier 2 — Low RiskSmall, isolated change with no API route or data model modifications. Why this tier:
Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns. Stats
|
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
PR Review
2 finding(s): 🔴 0 P0/P1 · 🟡 0 P2 · 🔵 2 P3 No inline comments. 2 P3 folded at the bottom. 🔵 2 P3 — no action needed before merge
Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides. |
Deep Review✅ No critical issues found. This is a pure mechanical refactor: three thin wrappers in
Team-scoping and tenant isolation are preserved — every helper keys off No P0/P1/P2 findings. Reviewers (6): ce-correctness-reviewer, ce-testing-reviewer, ce-maintainability-reviewer, ce-kieran-typescript-reviewer, ce-security-reviewer, ce-project-standards-reviewer Testing gaps: none — new helper behavior is fully covered; rewired call sites are unchanged existing code. |
E2E Test Results✅ All tests passed • 475 passed • 1 skipped • 1247s
Tests ran across 4 shards in parallel. |
Will adjust PromQL in a different PR |
…lper (#3777) ## Summary Follow-up to #3776. #3776 routed MCP connection lookups through `mcp/utils/connections.ts`. Two PromQL paths still skipped it, because they get their connection inside the shared `controllers/promql.ts`: - PromQL tiles (`runPromqlTile`, via `resolvePromqlTarget`) - PromQL `describe_source` (`describePromqlSource`, via `getPromqlLabelCatalog`) This PR gives both controller functions an optional `getConnection` lookup. It defaults to the existing team-scoped `getConnectionById`, so the REST `/prometheus` router is unchanged. The MCP paths now take the full `McpContext` and pass `getMcpConnection`, so every MCP connection lookup goes through the helper. The comment in `connections.ts` drops the PromQL exception that #3776 added. No behavior change: the same connection is found, the password is selected the same way, and the "Connection not found" errors are unchanged. No changeset: internal refactor with no user-facing change. ### How to reproduce **Starting point:** N/A, internal refactor with no user-visible change. **Testing:** 1. `cd packages/api && yarn ci:unit` runs the new `controllers/__tests__/promqlConnectionLookup.test.ts` (default lookup, custom lookup, and not-found handling) and a new `describeSourceTimeout.test.ts` case that checks PromQL `describe_source` looks up connections through the MCP helper. 2. `make dev-int FILE="promql prometheus"` covers the MCP PromQL tools and tiles plus the REST `/prometheus` router: 5 suites, 189 tests pass. The full MCP integration suite (`make dev-int FILE=src/mcp/__tests__`) also passes: 23 suites, 636 tests. ### How to test on Vercel preview N/A, non-UI change. ### References - Related PRs: #3776, #3771 (same pattern for source lookups)
Summary
MCP tools and prompts called the connection controller directly (
getConnectionsByTeam,getConnectionById,validateConnectionId) from five places. This addsmcp/utils/connections.tswith three helpers that take the fullMcpContext:getMcpConnections(context)getMcpConnection(context, connectionId, { selectPassword }?)validateMcpConnectionId(context, connectionId)Every MCP call site now uses them, including
getMcpClickhouseClient. The rules about which connections an MCP caller can use now live in one place, matching howmcp/utils/clickhouse.tsandmcp/utils/sources.tsalready work.No behavior change: same return values, null when a connection is not found, and the same validation messages and tool output.
No changeset: internal refactor with no user-facing change.
How to reproduce
Starting point: N/A, internal refactor with no user-visible change.
Testing:
cd packages/api && yarn ci:unitruns the newsrc/mcp/__tests__/mcpConnections.test.tsand the existing MCP unit tests, including the dashboard prompt tests.make dev-int FILE=src/mcp/__tests__runs the MCP integration suites (sources, dashboards, saved searches and more): 23 suites, 636 tests pass.How to test on Vercel preview
N/A, non-UI change.
References