Skip to content

feat(self-hosted): implement queryLogs for the MCP debugging tools - #48900

Open
Rodriguespn wants to merge 3 commits into
masterfrom
feat/self-hosted-query-logs
Open

feat(self-hosted): implement queryLogs for the MCP debugging tools#48900
Rodriguespn wants to merge 3 commits into
masterfrom
feat/self-hosted-query-logs

Conversation

@Rodriguespn

@Rodriguespn Rodriguespn commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Important

Only merge this when (https://github.com/supabase/platform/pull/36804) is merged, as the AI assistant will not have access to the query_logs tool for the remote MCP server

I have read the CONTRIBUTING.md file.

YES

What kind of change does this PR introduce?

Feature (self-hosted / CLI Studio MCP server).

What is the current behavior?

Self-hosted getDebuggingOperations (apps/studio/lib/api/self-hosted/mcp.ts) implements only getLogs, so the MCP debugging group exposes get_logs — a fixed per-service log dump built by getLogQuery. Logs are served by Logflare, which speaks BigQuery SQL.

What is the new behavior?

Bumps @supabase/mcp-server-supabase to ^0.10.0 (adds query_logs + logsDialect, and hides get_logs wherever a platform declares queryLogs) and moves logs over to it.

  • Self-hosted query_logs: declares logsDialect: 'bigquery' and implements queryLogs, passing the model's SQL straight through to the same Logflare logs.all endpoint (arbitrary sql param) — no new endpoint, no dialect translation.
  • Drops get_logs from self-hosted: getLogs throws (the server hides it once queryLogs exists) and the per-service getLogQuery builder is deleted; the model now writes its own BigQuery SQL, guided by the dialect schema hint.
  • Honors no-logs mode: query_logs throws when logs:all is disabled — the self-hosted default, enabled via the docker-compose.logs.yml override.
  • Assistant: switches the dashboard assistant from get_logs to query_logs (allowlist, drift guard, prompt, mocks, evals).

Refs AI-1046

Summary by CodeRabbit

  • New Features

    • AI debugging can query recent project logs using read-only SQL.
    • Log queries support optional time-range filters, filtering, aggregation, and joins.
    • Self-hosted debugging checks whether logging is enabled before running queries.
  • Bug Fixes

    • Updated debugging workflows and validation to consistently use the new log-query capability.
    • Removed reliance on legacy service-specific log filtering and query behavior.
  • Documentation

    • Updated MCP debugging tool guidance to describe SQL-based log queries.
  • Tests

    • Expanded coverage for enabled, disabled, and unsupported logging scenarios.

Declare `logsDialect: 'bigquery'` and implement `queryLogs` in the
self-hosted `getDebuggingOperations`. `queryLogs` passes the model's SQL
straight through to the same Logflare `logs.all` endpoint `getLogs`
already uses, which accepts an arbitrary `sql` param.

Pairs with supabase/mcp#357: once the platform declares its dialect, the
MCP server exposes `query_logs` (with the BigQuery-dialect description)
and hides `get_logs` on self-hosted/CLI, matching hosted.

Refs AI-1046
@vercel

vercel Bot commented Aug 10, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, v0 Aug 10, 2026 8:10pm
6 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Aug 10, 2026 8:10pm
design-system Skipped Skipped Aug 10, 2026 8:10pm
studio-self-hosted Skipped Skipped Aug 10, 2026 8:10pm
studio-staging Skipped Skipped Aug 10, 2026 8:10pm
ui-library Skipped Skipped Aug 10, 2026 8:10pm
zone-www-dot-com Skipped Skipped Aug 10, 2026 8:10pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 90dd0cc2-2352-44bb-93a3-09cb72c8e2aa

📥 Commits

Reviewing files that changed from the base of the PR and between 8893a9a and 8186503.

📒 Files selected for processing (1)
  • apps/docs/content/guides/ai-tools/mcp.mdx

📝 Walkthrough

Walkthrough

The debugging MCP flow now uses query_logs with read-only SQL and optional timestamp filters. Self-hosted requests forward SQL to analytics, while AI prompts, tool filters, mocks, evaluations, documentation, and tests use the renamed tool.

Changes

Query logs MCP migration

Layer / File(s) Summary
Self-hosted query flow
apps/studio/lib/api/self-hosted/mcp.ts, apps/studio/lib/api/self-hosted/logs.ts, apps/studio/lib/api/self-hosted/mcp.test.ts
The debugging API adds queryLogs, validates log availability, forwards SQL and timestamp filters to analytics, and rejects getLogs. The obsolete query-generation helper is removed.
MCP tool contracts and mocks
apps/studio/lib/ai/tools/*, apps/studio/package.json
Remote and mock tool definitions use query_logs. Mock inputs now require SQL and support timestamp bounds. The MCP server dependency is updated.
AI wiring and validation
apps/studio/lib/ai/tool-filter.ts, apps/studio/lib/ai/tool-filter.test.ts, apps/studio/lib/ai/prompts.ts, apps/studio/evals/dataset.ts, apps/docs/content/guides/ai-tools/mcp.mdx
Tool filtering, prompts, evaluations, documentation, and tests recognize query_logs and its read-only SQL usage.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MCPClient
  participant getDebuggingOperations
  participant LogsFeatureGate
  participant retrieveAnalyticsData
  MCPClient->>getDebuggingOperations: queryLogs(projectRef, SQL, timestamp filters)
  getDebuggingOperations->>LogsFeatureGate: validate logs availability
  LogsFeatureGate-->>getDebuggingOperations: enabled
  getDebuggingOperations->>retrieveAnalyticsData: request logs.all with SQL and filters
  retrieveAnalyticsData-->>getDebuggingOperations: analytics log results
  getDebuggingOperations-->>MCPClient: query results
Loading

Possibly related PRs

Suggested labels: ai, do-not-merge

Suggested reviewers: czenko

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: adding queryLogs to the self-hosted MCP debugging tools.
Description check ✅ Passed The description follows the template and explains the current behavior, new behavior, change type, testing context, and merge dependency.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/self-hosted-query-logs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@supabase

supabase Bot commented Aug 10, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (next)

passed  243 passed
skipped  5 skipped

Details

stats  248 tests across 29 suites
duration  4 minutes, 3 seconds
commit  8186503

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

…ging tools

Bump @supabase/mcp-server-supabase to ^0.10.0, which adds query_logs and
(when a platform declares queryLogs) hides get_logs.

- Honor no-logs mode: query_logs throws when logs:all is disabled — the
  self-hosted default, enabled via the docker-compose.logs.yml override.
- Remove get_logs from self-hosted: getLogs now throws (the server hides
  it once queryLogs exists) and the per-service getLogQuery SQL builder is
  deleted; the model writes its own BigQuery SQL via query_logs instead.
- Switch the dashboard assistant from get_logs to query_logs (allowlist,
  drift guard, prompt, mocks, evals).

Refs AI-1046

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Rodriguespn
Rodriguespn marked this pull request as ready for review August 10, 2026 19:47
@Rodriguespn
Rodriguespn requested a review from a team as a code owner August 10, 2026 19:47
@Rodriguespn Rodriguespn self-assigned this Aug 10, 2026

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/studio/lib/api/self-hosted/mcp.ts (1)

121-121: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the redundant Feature[] cast.

getEnabledFeaturesOverrideDisabledList() filters environment variables against knownFeatureKeys, so it returns only known feature keys. Expose that return value as Feature[] instead of casting it at this call site. No additional runtime validation is required.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/studio/lib/api/self-hosted/mcp.ts` at line 121, Update
getEnabledFeaturesOverrideDisabledList to declare and return Feature[] based on
its knownFeatureKeys filtering, then remove the redundant Feature[] cast from
the disabledFeatures assignment. Preserve the existing runtime behavior without
adding validation.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/studio/lib/api/self-hosted/mcp.test.ts`:
- Around line 126-137: Update the queryLogs test to pass both
iso_timestamp_start and iso_timestamp_end in the request, then assert the exact
params object forwarded to retrieveAnalyticsDataMock, including sql and both
timestamp bounds. Keep the existing logs-enabled setup and queryLogs invocation
coverage unchanged.

---

Nitpick comments:
In `@apps/studio/lib/api/self-hosted/mcp.ts`:
- Line 121: Update getEnabledFeaturesOverrideDisabledList to declare and return
Feature[] based on its knownFeatureKeys filtering, then remove the redundant
Feature[] cast from the disabledFeatures assignment. Preserve the existing
runtime behavior without adding validation.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: fcbfbe9b-3ce2-45a2-a13f-ec4a8e360c99

📥 Commits

Reviewing files that changed from the base of the PR and between 957e9fe and 8893a9a.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (12)
  • apps/studio/evals/dataset.ts
  • apps/studio/lib/ai/prompts.ts
  • apps/studio/lib/ai/tool-filter.test.ts
  • apps/studio/lib/ai/tool-filter.ts
  • apps/studio/lib/ai/tools/mcp-tools.test.ts
  • apps/studio/lib/ai/tools/mcp-tools.ts
  • apps/studio/lib/ai/tools/mock-tools.test.ts
  • apps/studio/lib/ai/tools/mock-tools.ts
  • apps/studio/lib/api/self-hosted/logs.ts
  • apps/studio/lib/api/self-hosted/mcp.test.ts
  • apps/studio/lib/api/self-hosted/mcp.ts
  • apps/studio/package.json
💤 Files with no reviewable changes (1)
  • apps/studio/lib/api/self-hosted/logs.ts

Comment on lines +126 to +137
it('queryLogs passes the model-provided SQL straight through when logs are enabled', async () => {
vi.stubEnv('ENABLED_FEATURES_LOGS_ALL', 'true')
retrieveAnalyticsDataMock.mockResolvedValue({ data: ['log entry'], error: null })

const ops = getDebuggingOperations({})
await ops.queryLogs!('default', { sql: 'select * from edge_logs' })

expect(retrieveAnalyticsDataMock).toHaveBeenCalledWith(
expect.objectContaining({
params: expect.objectContaining({ sql: 'select * from edge_logs' }),
})
)

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Test timestamp forwarding.

The new request contract includes iso_timestamp_start and iso_timestamp_end, but this test only asserts sql. Pass both bounds and assert the exact params object. This guards the forwarding at apps/studio/lib/api/self-hosted/mcp.ts Lines 153-155.

As per coding guidelines, “Include relevant tests by default.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/studio/lib/api/self-hosted/mcp.test.ts` around lines 126 - 137, Update
the queryLogs test to pass both iso_timestamp_start and iso_timestamp_end in the
request, then assert the exact params object forwarded to
retrieveAnalyticsDataMock, including sql and both timestamp bounds. Keep the
existing logs-enabled setup and queryLogs invocation coverage unchanged.

Source: Coding guidelines

query_logs supersedes get_logs in the MCP debugging tools; on hosted
projects get_logs is already hidden in favor of query_logs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Rodriguespn
Rodriguespn requested a review from a team as a code owner August 10, 2026 20:06
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Aug 10, 2026

@czenko czenko left a comment

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.

Approved the documentation piece

Comment thread apps/docs/content/guides/ai-tools/mcp.mdx

@joshenlim joshenlim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changes for hosted studio generally LGTM - just renaming the tool call, will approve to unblock, but I'll defer to @aantti for the self-hosted side of things though 🙏 🙂

Let's wait for his approval before we merge this

@joshenlim
joshenlim requested a review from aantti August 11, 2026 08:33

if (!isFeatureEnabled('logs:all', disabledFeatures)) {
throw new Error(
'Logs are disabled on this instance. Enable the `docker-compose.logs.yml` override to query logs.'

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.

CLI was planning to disable logs by default as well. When/if that happens, this error message should be adjusted :)

async getLogs(projectRef: string, options: GetLogsOptions) {
const sql = getLogQuery(options.service)
// Self-hosted logs are served by Logflare, which speaks BigQuery SQL.
logsDialect: 'bigquery',

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.

Worth double-checking.

@aantti aantti added cli Related to supabase/cli self-hosted Related to self-hosted Supabase mcp Related to MCP (Model Context Protocol) labels Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Related to supabase/cli documentation Improvements or additions to documentation mcp Related to MCP (Model Context Protocol) self-hosted Related to self-hosted Supabase

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants