Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(ai): temporarily remove log tools (#37274)

Greg Richardson2afd0c92abd3
diff --git a/apps/studio/lib/ai/tool-filter.test.ts b/apps/studio/lib/ai/tool-filter.test.ts
index 03b12fe66f3..4ad47d1cf06 100644
--- a/apps/studio/lib/ai/tool-filter.test.ts
+++ b/apps/studio/lib/ai/tool-filter.test.ts
@@ -9,14 +9,12 @@ import {
createPrivacyMessageTool,
toolSetValidationSchema,
transformToolResult,
- DatabaseExtension,
} from './tool-filter'
describe('TOOL_CATEGORY_MAP', () => {
it('should categorize tools correctly', () => {
expect(TOOL_CATEGORY_MAP['display_query']).toBe(TOOL_CATEGORIES.UI)
expect(TOOL_CATEGORY_MAP['list_tables']).toBe(TOOL_CATEGORIES.SCHEMA)
- expect(TOOL_CATEGORY_MAP['get_logs']).toBe(TOOL_CATEGORIES.LOG)
})
})
@@ -35,9 +33,7 @@ describe('tool allowance by opt-in level', () => {
list_edge_functions: { execute: vitest.fn().mockResolvedValue({ status: 'success' }) },
list_branches: { execute: vitest.fn().mockResolvedValue({ status: 'success' }) },
// Log tools
- get_logs: { execute: vitest.fn().mockResolvedValue({ status: 'success' }) },
get_advisors: { execute: vitest.fn().mockResolvedValue({ status: 'success' }) },
- get_log_counts: { execute: vitest.fn().mockResolvedValue({ status: 'success' }) },
} as unknown as ToolSet
const filtered = filterToolsByOptInLevel(mockTools, optInLevel as any)
@@ -64,7 +60,6 @@ describe('tool allowance by opt-in level', () => {
expect(tools).not.toContain('list_extensions')
expect(tools).not.toContain('list_edge_functions')
expect(tools).not.toContain('list_branches')
- expect(tools).not.toContain('get_logs')
expect(tools).not.toContain('execute_sql')
})
@@ -78,9 +73,7 @@ describe('tool allowance by opt-in level', () => {
expect(tools).toContain('list_edge_functions')
expect(tools).toContain('list_branches')
expect(tools).toContain('search_docs')
- expect(tools).not.toContain('get_logs')
expect(tools).not.toContain('get_advisors')
- expect(tools).not.toContain('get_log_counts')
expect(tools).not.toContain('execute_sql')
})
@@ -94,9 +87,7 @@ describe('tool allowance by opt-in level', () => {
expect(tools).toContain('list_edge_functions')
expect(tools).toContain('list_branches')
expect(tools).toContain('search_docs')
- expect(tools).toContain('get_logs')
expect(tools).toContain('get_advisors')
- expect(tools).toContain('get_log_counts')
expect(tools).not.toContain('execute_sql')
})
@@ -110,9 +101,7 @@ describe('tool allowance by opt-in level', () => {
expect(tools).toContain('list_edge_functions')
expect(tools).toContain('list_branches')
expect(tools).toContain('search_docs')
- expect(tools).toContain('get_logs')
expect(tools).toContain('get_advisors')
- expect(tools).toContain('get_log_counts')
expect(tools).not.toContain('execute_sql')
})
})
@@ -130,9 +119,7 @@ describe('filterToolsByOptInLevel', () => {
list_branches: { execute: vitest.fn().mockResolvedValue({ status: 'success' }) },
search_docs: { execute: vitest.fn().mockResolvedValue({ status: 'success' }) },
// Log tools
- get_logs: { execute: vitest.fn().mockResolvedValue({ status: 'success' }) },
get_advisors: { execute: vitest.fn().mockResolvedValue({ status: 'success' }) },
- get_log_counts: { execute: vitest.fn().mockResolvedValue({ status: 'success' }) },
// Unknown tool - should be filtered out entirely
some_other_tool: { execute: vitest.fn().mockResolvedValue({ status: 'success' }) },
} as unknown as ToolSet
@@ -186,9 +173,7 @@ describe('filterToolsByOptInLevel', () => {
'list_extensions',
'list_edge_functions',
'list_branches',
- 'get_logs',
'get_advisors',
- 'get_log_counts',
])
})
@@ -200,16 +185,14 @@ describe('filterToolsByOptInLevel', () => {
'list_extensions',
'list_edge_functions',
'list_branches',
- 'get_logs',
'get_advisors',
- 'get_log_counts',
])
})
it('should stub log tools for schema opt-in level', async () => {
const tools = filterToolsByOptInLevel(mockTools, 'schema')
- await expectStubsFor(tools, ['get_logs', 'get_advisors', 'get_log_counts'])
+ await expectStubsFor(tools, ['get_advisors'])
})
// No execute_sql tool, so nothing additional to stub for schema_and_log opt-in level
@@ -293,7 +276,6 @@ describe('toolSetValidationSchema', () => {
it('should accept subset of known tools', () => {
const validSubset = {
list_tables: { parameters: z.object({}), execute: vitest.fn() },
- get_logs: { parameters: z.object({}), execute: vitest.fn() },
display_query: { parameters: z.object({}), execute: vitest.fn() },
}
@@ -327,13 +309,11 @@ describe('toolSetValidationSchema', () => {
list_extensions: { parameters: z.object({}), execute: vitest.fn() },
list_edge_functions: { parameters: z.object({}), execute: vitest.fn() },
list_branches: { parameters: z.object({}), execute: vitest.fn() },
- get_logs: { parameters: z.object({}), execute: vitest.fn() },
search_docs: { parameters: z.object({}), execute: vitest.fn() },
get_advisors: { parameters: z.object({}), execute: vitest.fn() },
display_query: { parameters: z.object({}), execute: vitest.fn() },
display_edge_function: { parameters: z.object({}), execute: vitest.fn() },
rename_chat: { parameters: z.object({}), execute: vitest.fn() },
- get_log_counts: { parameters: z.object({}), execute: vitest.fn() },
}
const validationResult = toolSetValidationSchema.safeParse(allExpectedTools)
diff --git a/apps/studio/lib/ai/tool-filter.ts b/apps/studio/lib/ai/tool-filter.ts
index e16e52b27f3..ac07b32bb10 100644
--- a/apps/studio/lib/ai/tool-filter.ts
+++ b/apps/studio/lib/ai/tool-filter.ts
@@ -23,7 +23,6 @@ export const toolSetValidationSchema = z.record(
'list_extensions',
'list_edge_functions',
'list_branches',
- 'get_logs',
'search_docs',
'get_advisors',
@@ -31,7 +30,6 @@ export const toolSetValidationSchema = z.record(
'display_query',
'display_edge_function',
'rename_chat',
- 'get_log_counts',
'getSchemaTables',
'getRlsKnowledge',
'getFunctions',
@@ -98,9 +96,7 @@ export const TOOL_CATEGORY_MAP: Record<string, ToolCategory> = {
list_branches: TOOL_CATEGORIES.SCHEMA,
// Log tools - MCP and local
- get_logs: TOOL_CATEGORIES.LOG,
get_advisors: TOOL_CATEGORIES.LOG,
- get_log_counts: TOOL_CATEGORIES.LOG,
}
/**
diff --git a/apps/studio/pages/api/ai/sql/generate-v4.ts b/apps/studio/pages/api/ai/sql/generate-v4.ts
index 1ff811f2781..989cbaf5548 100644
--- a/apps/studio/pages/api/ai/sql/generate-v4.ts
+++ b/apps/studio/pages/api/ai/sql/generate-v4.ts
@@ -12,9 +12,6 @@ import { getAiOptInLevel } from 'hooks/misc/useOrgOptedIntoAi'
import { getModel } from 'lib/ai/model'
import apiWrapper from 'lib/api/apiWrapper'
import { queryPgMetaSelfHosted } from 'lib/self-hosted'
-import { getUnifiedLogsChart } from 'data/logs/unified-logs-chart-query'
-import { getUnifiedLogs } from 'data/logs/unified-logs-infinite-query'
-import { QuerySearchParamsType } from 'components/interfaces/UnifiedLogs/UnifiedLogs.types'
import { createSupabaseMCPClient } from 'lib/ai/supabase-mcp'
import { filterToolsByOptInLevel, toolSetValidationSchema } from 'lib/ai/tool-filter'
import { getTools } from './tools'
@@ -170,188 +167,6 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse) {
return { status: 'Tool call sent to client for rendering.' }
},
}),
- get_log_counts: tool({
- description:
- 'Get log counts aggregated by time buckets to understand system health and activity levels. Returns success, warning, and error counts over time. Can filter by log types (edge, auth, postgres, etc.) and levels.',
- parameters: z.object({
- dateStart: z
- .string()
- .optional()
- .describe('Start date as ISO string (defaults to 1 hour ago)'),
- dateEnd: z.string().optional().describe('End date as ISO string (defaults to now)'),
- level: z
- .array(z.enum(['success', 'warning', 'error']))
- .optional()
- .describe('Filter by log levels'),
- log_type: z
- .array(
- z.enum([
- 'postgres',
- 'edge_function',
- 'auth',
- 'postgrest',
- 'storage',
- 'edge',
- 'function_events',
- 'postgres_upgrade',
- 'supavisor',
- ])
- )
- .optional()
- .describe('Filter by log types (e.g., ["edge"] for edge logs only)'),
- }),
- execute: async (args) => {
- try {
- let dateArray: Date[] | null = null
- if (args.dateStart && args.dateEnd) {
- dateArray = [new Date(args.dateStart), new Date(args.dateEnd)]
- }
-
- const search: QuerySearchParamsType = {
- date: dateArray,
- level: args.level || null,
- log_type: args.log_type || null,
- latency: null,
- 'timing.dns': null,
- 'timing.connection': null,
- 'timing.tls': null,
- 'timing.ttfb': null,
- 'timing.transfer': null,
- status: null,
- regions: null,
- method: null,
- host: null,
- pathname: null,
- sort: null,
- size: 40,
- start: 0,
- direction: 'next',
- cursor: new Date(),
- id: null,
- }
-
- let headers = new Headers()
- if (authorization) headers.set('Authorization', authorization)
-
- const chartData = await getUnifiedLogsChart({ projectRef, search }, undefined, headers)
-
- const totalSuccess = chartData.reduce((sum: number, point) => sum + point.success, 0)
- const totalWarning = chartData.reduce((sum: number, point) => sum + point.warning, 0)
- const totalError = chartData.reduce((sum: number, point) => sum + point.error, 0)
-
- return {
- status: 'success',
- data: chartData,
- summary: `Found ${chartData.length} time buckets. Total: ${totalSuccess} success, ${totalWarning} warning, ${totalError} error logs`,
- totals: {
- success: totalSuccess,
- warning: totalWarning,
- error: totalError,
- },
- }
- } catch (error) {
- return {
- status: 'error',
- error: error instanceof Error ? error.message : 'Unknown error occurred',
- }
- }
- },
- }),
- get_logs: tool({
- description:
- 'Get detailed log entries for analysis and debugging. Use this after get_log_counts to examine specific logs during time periods with errors or unusual activity.',
- parameters: z.object({
- dateStart: z
- .string()
- .optional()
- .describe('Start date as ISO string (defaults to 1 hour ago)'),
- dateEnd: z.string().optional().describe('End date as ISO string (defaults to now)'),
- level: z
- .array(z.enum(['success', 'warning', 'error']))
- .optional()
- .describe('Filter by log levels'),
- log_type: z
- .array(
- z.enum([
- 'postgres',
- 'edge_function',
- 'auth',
- 'postgrest',
- 'storage',
- 'edge',
- 'function_events',
- 'postgres_upgrade',
- 'supavisor',
- ])
- )
- .optional()
- .describe('Filter by log types'),
- limit: z
- .number()
- .min(1)
- .max(20)
- .default(10)
- .describe('Maximum number of logs to return (1-100, defaults to 20)'),
- }),
- execute: async (args) => {
- try {
- let dateArray: Date[] | null = null
- if (args.dateStart && args.dateEnd) {
- dateArray = [new Date(args.dateStart), new Date(args.dateEnd)]
- }
-
- const search: QuerySearchParamsType = {
- date: dateArray,
- level: args.level || null,
- log_type: args.log_type || null,
- latency: null,
- 'timing.dns': null,
- 'timing.connection': null,
- 'timing.tls': null,
- 'timing.ttfb': null,
- 'timing.transfer': null,
- status: null,
- regions: null,
- method: null,
- host: null,
- pathname: null,
- sort: null,
- size: 40,
- start: 0,
- direction: 'next',
- cursor: new Date(),
- id: null,
- }
-
- let headers = new Headers()
- if (authorization) headers.set('Authorization', authorization)
-
- const logsData = await getUnifiedLogs(
- {
- projectRef,
- search,
- },
- undefined,
- headers
- )
-
- const logs = logsData.data.slice(0, args.limit)
-
- return {
- status: 'success',
- data: logs,
- summary: `Found ${logs.length} log entries. Showing details for analysis.`,
- totalFetched: logs.length,
- hasMore: logsData.nextCursor !== null,
- }
- } catch (error) {
- return {
- status: 'error',
- error: error instanceof Error ? error.message : 'Unknown error occurred',
- }
- }
- },
- }),
rename_chat: tool({
description: `Rename the current chat session when the current chat name doesn't describe the conversation topic.`,
parameters: z.object({
@@ -474,15 +289,6 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse) {
- **If \`execute_sql\` is NOT available**: Explain the issue and provide the corrected SQL using \`display_query\` with \`sql\`, \`label\`, and \`runQuery: true\`. Include \`view\`, \`xAxis\`, \`yAxis\` if the corrected query might return visualizable data.
- **If debugging a WRITE/DDL query**: Explain the issue and provide the corrected SQL using \`display_query\` with \`sql\`, \`label\`, and \`runQuery: false\`. Include \`view\`, \`xAxis\`, \`yAxis\` if the corrected query might return visualizable data.
- # Supabase Health & Debugging
- - **General Status**:
- - **If \`get_log_counts\`, \`get_logs\`, \`list_tables\`, \`list_extensions\` are available**: Use \`get_log_counts\` first to get a high-level view of system health by checking success/warning/error counts over time. You can filter by specific log types (e.g., \`log_type: ["edge"]\` for edge logs, \`log_type: ["postgres"]\` for database logs). Then use \`get_logs\` and schema tools to provide a detailed summary overview of the project's health (check recent errors/activity for relevant services like 'postgres', 'api', 'auth').
- - **If tools are NOT available**: Ask the user to check their Supabase dashboard or logs for project health information.
- - **Service Errors**:
- - **If \`get_log_counts\` and \`get_logs\` are available**: Start with \`get_log_counts\` to understand the overall error patterns and timeframes. Use log type filtering to focus on specific services (e.g., \`log_type: ["edge"]\` for API errors, \`log_type: ["postgres"]\` for database errors). Then use \`get_logs\` to dive deeper into specific errors. When facing specific errors related to the database, Edge Functions, or other Supabase services, explain the problem and use the \`get_logs\` tool, specifying the relevant service type (e.g., 'postgres', 'edge functions', 'api') to retrieve logs and diagnose the issue. Briefly summarize the relevant log information in your text response before suggesting a fix.
- - **If only \`get_logs\` is available**: Use the \`get_logs\` tool directly to retrieve logs for the service experiencing errors.
- - **If tools are NOT available**: Ask the user to provide relevant logs for the service experiencing errors.
-
# SQL Style:
- Generated SQL must be valid Postgres SQL.
- Always use double apostrophes for escaped single quotes (e.g., 'Night''s watch').