Skip to content

feat: support edge function runtime logs in get_logs#326

Open
barryroodt wants to merge 2 commits into
mainfrom
barryroodt/ai-651-support-edge-function-logs-in-supabase-mcp
Open

feat: support edge function runtime logs in get_logs#326
barryroodt wants to merge 2 commits into
mainfrom
barryroodt/ai-651-support-edge-function-logs-in-supabase-mcp

Conversation

@barryroodt

Copy link
Copy Markdown

Problem

The get_logs MCP tool only exposes edge function invocation logs (function_edge_logs). Edge function runtime logs — console.log output, the dashboard's per-function "Logs" view (function_logs) — are unreachable via MCP. Reported independently by two users in April; confirmed as a gap in logs.ts (Linear: AI-651).

The tool also still queries the deprecated BigQuery logs.all endpoint (Linear: AI-890 / platform PR supabase/platform#35096 context).

Changes

  • New edge-function-runtime service on get_logs, returning edge function console output. edge-function keeps meaning invocation logs (backward compatible).
  • ClickHouse migration (cloud): getLogs now calls /v1/projects/{ref}/analytics/endpoints/logs with ClickHouse SQL against the unified logs table (new getClickHouseLogQuery builder). The endpoint already exists in the generated management API types — no type regen.
  • BigQuery builder retained (getLogQuery, extended with the runtime case) — self-hosted deployments cannot use the ClickHouse endpoint and must keep the legacy path.
  • Prompt-injection guardrails: all get_logs output is now wrapped in the same UUID-salted <untrusted-data> boundary as execute_sql, extracted into a shared wrapWithUntrustedDataBoundary helper (log content is arbitrary user text).
  • Tool description now names both edge function log kinds, states the 24h window, and advises correlate-don't-poll (Log Drains for streaming).
  • Tests: MSW handler for the new endpoint (old logs.all handler kept), service iteration extended, untrusted-data boundary asserted, new logs.test.ts covering both builders for every service.

Notes for reviewers

  • branch-action maps to source = 'workflow_run_logs' with log_attributes['workflow_run'] — matches platform PR #35096 (source added to the endpoint 2 Jul). It's not yet in shared-data/log-constants.ts; flagged to the observability team to confirm.
  • Divergence from platform PR #35096: this PR uses source = 'edge_logs' for the api service (per the ClickHouse logs query reference) where #35096 uses 'api', and it does not repurpose the existing edge-function value. Both raised on the Linear tickets.

Verification

AI-assisted (Claude + Codex via verified-swarm harness); human-reviewed by @barryroodt. Evidence:

  • pnpm typecheck — clean
  • CI=true pnpm test:unit182/182 pass (11 files; baseline on main was 164)
  • pnpm format:check (biome) — clean
  • Independent 3-lens code review (ClickHouse SQL correctness vs. query reference, guardrail parity with execute_sql, API shape/backward compat) — findings adjudicated and folded in

Linear: AI-651, AI-890

🤖 Generated with Claude Code

Adds an edge-function-runtime service to get_logs exposing edge function
console output (function_logs), which was previously unreachable via MCP.
Migrates the cloud logs path from the deprecated BigQuery logs.all
endpoint to the ClickHouse /v1/projects/{ref}/analytics/endpoints/logs
endpoint; the BigQuery query builder is retained for self-hosted
deployments, which cannot use the ClickHouse endpoint.

All get_logs output is now wrapped in the same untrusted-data
prompt-injection boundary as execute_sql, via a shared helper.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@barryroodt barryroodt self-assigned this Jul 9, 2026
get_logs: {
description:
'Gets logs for a Supabase project by service type. Use this to help debug problems with your app. This will return logs within the last 24 hours.',
'Gets logs for a Supabase project by service type. Each call returns logs from the last 24 hours. Edge Function logs are split by kind: `edge-function` returns invocation/request logs, while `edge-function-runtime` returns console output from inside the function. Query one service first, then correlate with other services by timestamp or error anchors. Do not poll get_logs in a loop; use Log Drains for streaming logs.',

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.

Each call returns logs from the last 24 hours.

Might be worth adding "by default". The agent can specify a custom start/end date (which cap at 24 hours too).

use Log Drains for streaming logs

I understand the sentiment behind this but I don't think this has an easy call to action. Log Drains needs a paid account today, then you need to connect a destination, then you need to feed those logs to the agent somehow, probably via another MCP server or CLI. I think it might be simpler to omit this last part.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the feedback 🙏

Both addressed in 66fd246:

  • Description now says the 24h window is the default - and get_logs now actually exposes optional iso_timestamp_start / iso_timestamp_end (the handler previously hardcoded the window even though the platform layer supported custom ranges, so this comment turned a doc tweak into a small feature 🙂). Added a test asserting the params are forwarded to the management API as query params.
  • Dropped the Log Drains pointer, kept the don't-poll guidance.

Comment thread packages/mcp-server-supabase/src/tools/util.ts
Comment thread packages/mcp-server-supabase/src/logs.ts
Review feedback: expose optional iso_timestamp_start/iso_timestamp_end
on get_logs (24h default window unchanged; API caps ranges at 24h) and
drop the Log Drains pointer from the tool description while keeping the
no-polling guidance.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 29079255813

Coverage increased (+0.02%) to 96.267%

Details

  • Coverage increased (+0.02%) from the base build.
  • Patch coverage: 1 uncovered change across 1 file (74 of 75 lines covered, 98.67%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
packages/mcp-server-supabase/src/logs.ts 36 35 97.22%
Total (6 files) 75 74 98.67%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 2880
Covered Lines: 2794
Line Coverage: 97.01%
Relevant Branches: 361
Covered Branches: 326
Branch Coverage: 90.3%
Branches in Coverage %: Yes
Coverage Strength: 40.92 hits per line

💛 - Coveralls

@barryroodt barryroodt marked this pull request as ready for review July 10, 2026 08:26
@barryroodt barryroodt requested a review from a team as a code owner July 10, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants