Skip to content

feat(mcp): account-scoped SQL query tool - #378

Closed
alosec wants to merge 5 commits into
mainfrom
feat/analytics-query-mcp
Closed

alosec wants to merge 5 commits into
mainfrom
feat/analytics-query-mcp

Conversation

@alosec

@alosec alosec commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Adds the read-only query MCP tool for one SQL SELECT against account-scoped assistant views. It forwards the caller's authorization and account context unchanged; the backend enforces caller eligibility, SQL restrictions and response limits.

The response contract now supports legacy and proposed persisted-result responses:

  • result_id, expires_at, column_types, preview_row_count and total_count are optional. total_count may be null when unknown.
  • rows may contain only a backend-selected preview. row_count describes stored rows and may exceed returned rows; truncated: false does not mean the preview is complete.
  • The runtime already returned the whole backend JSON and continues doing so. New transport tests verify exact preservation in MCP text and structuredContent for legacy, sampled, truncated and unknown-total responses.
  • Input remains SQL-only. Preview sizing belongs to the backend; the newer demo sizes it by bytes. No fixed preview-row policy, retrieval tool, rendering or export implementation is introduced.

Current-main synchronization includes the externally merged docs-search tool; both protocol smoke scripts require twelve tools including query and search_docs. All six protocol versions passed locally. Frozen Node 24 workspace install, build and checks passed; 396 tests passed and one live-token test skipped.

Backend dependencies: Terminal49/t49#3967 and #3968 remain open; #3968 is stacked on #3967. The newer byte-budget policy is proposed by draft Terminal49/t49#4149. These fields remain optional because the staged legacy response may not include them. Live persisted-result rollout, retrieval/render/export integration and customer access are separate follow-ups. Existing draft state is preserved.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Final-head CI, Claude review, Vercel and both HTTP protocol previews passed at 7493f1f4749a15a5099078c196a85b712c474c0e.

@vercel

vercel Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
api Ready Ready Preview Oct 6, 2026 5:31am UTC

Request Review

@SylvainGravejat

Copy link
Copy Markdown
Member

@alosec a few design notes on the tool contract, from a conversation with Claude about how AskT49 should read data. Longer write-up: AskT49 Read Tools.

  • What the model sees vs what the client gets. Could structuredContent carry the full result (for UI rendering) while the text content carries a summary for the model: columns, total count, the first ~20 rows? That keeps tokens down, and it stops the model retyping rows into tables it can misquote. One thing to confirm: whether Eve's MCP connection can route those two parts separately. If not, a thin Eve-local wrapper over the same endpoint would give that control.
  • Guidance. query-guidance currently covers the 500 cap, COUNT for totals, and one example. The hackathon prompt had rules that noticeably helped: aggregate first (GROUP BY down to ≤20 rows), then offer a drill-down; never paste rows; when truncated, say so and offer to narrow by date, terminal or status. Worth adding them.
  • Rollout. Since connected MCP clients get this tool without an extra flag, a dedicated feature flag would give us a kill switch. That also depends on the entitlement gap I raised on Terminal49/t49#3812.
@alosec

alosec commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@alosec a few design notes on the tool contract, from a conversation with Claude about how AskT49 should read data. Longer write-up: AskT49 Read Tools.

  • What the model sees vs what the client gets. Could structuredContent carry the full result (for UI rendering) while the text content carries a summary for the model: columns, total count, the first ~20 rows? That keeps tokens down, and it stops the model retyping rows into tables it can misquote. One thing to confirm: whether Eve's MCP connection can route those two parts separately. If not, a thin Eve-local wrapper over the same endpoint would give that control.

Does result_id and the fetch endpoint from t49 #3968 cover this without depending on the client? Sorry I missed this last week @SylvainGravejat

@alosec

alosec commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

Closing: superseded by Sylvain's SQL work in t49 (#4149 and follow-ups). AskT49 now runs SQL through its own agent tool against /v2/assistant_queries, and this PR targets the older result contract. If we want SQL for external MCP clients, we'll open a fresh PR against the current API.

This branch was successfully deployed

1 active deployment
Preview — 7493f1f4 Deployed Oct 6, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants