Skip to content

Commit 0535994

Browse files
authored
Merge pull request #18 from supabase-community/feat/branch-logs
feat: add branch action logs
2 parents 43fc682 + 7883655 commit 0535994

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

packages/mcp-server-supabase/src/logs.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { stripIndent } from 'common-tags';
33
export function getLogQuery(
44
service:
55
| 'api'
6+
| 'branch-action'
67
| 'postgres'
78
| 'edge-function'
89
| 'auth'
@@ -21,6 +22,12 @@ export function getLogQuery(
2122
order by timestamp desc
2223
limit ${limit}
2324
`;
25+
case 'branch-action':
26+
return stripIndent`
27+
select workflow_run, workflow_run_logs.timestamp, id, event_message from workflow_run_logs
28+
order by timestamp desc
29+
limit ${limit}
30+
`;
2431
case 'postgres':
2532
return stripIndent`
2633
select identifier, postgres_logs.timestamp, id, event_message, parsed.error_severity from postgres_logs

packages/mcp-server-supabase/src/server.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ describe('tools', () => {
456456
const project = mockProjects.values().next().value!;
457457
const services = [
458458
'api',
459+
'branch-action',
459460
'postgres',
460461
'edge-function',
461462
'auth',

packages/mcp-server-supabase/src/server.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ export function createSupabaseMcpServer(options: SupabaseMcpServerOptions) {
337337
service: z
338338
.enum([
339339
'api',
340+
'branch-action',
340341
'postgres',
341342
'edge-function',
342343
'auth',
@@ -346,7 +347,13 @@ export function createSupabaseMcpServer(options: SupabaseMcpServerOptions) {
346347
.describe('The service to fetch logs for'),
347348
}),
348349
execute: async ({ project_id, service }) => {
349-
const now = Date.now();
350+
// Omitting start and end time defaults to the last minute.
351+
// But since branch actions are async, we need to wait longer
352+
// for jobs to be scheduled and run to completion.
353+
const timestamp =
354+
service === 'branch-action'
355+
? new Date(Date.now() - 5 * 60 * 1000)
356+
: undefined;
350357
const response = await managementApiClient.GET(
351358
'/v1/projects/{ref}/analytics/endpoints/logs.all',
352359
{
@@ -355,7 +362,7 @@ export function createSupabaseMcpServer(options: SupabaseMcpServerOptions) {
355362
ref: project_id,
356363
},
357364
query: {
358-
// Omitting start and end time defaults to the last minute
365+
iso_timestamp_start: timestamp?.toISOString(),
359366
sql: getLogQuery(service),
360367
},
361368
},

0 commit comments

Comments
 (0)