Skip to main content
Glama
Perufitlife

supabase-security-mcp

by Perufitlife

preview_fix

Test security fix changes safely by wrapping SQL in a transaction and rolling back to preview impact without applying modifications.

Instructions

Preview what a fix would change WITHOUT applying it. Wraps the fix SQL in BEGIN; ... ROLLBACK; and returns what would have happened. Safe to call for any finding.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_refYes
finding_indexYes0-based index from list_findings output

Implementation Reference

  • The handler function for the 'preview_fix' tool. It retrieves a finding from cache by index, strips SQL comments, wraps the fix SQL in BEGIN/ROLLBACK, and executes it via the sql() helper. Returns preview OK on success or error message on failure.
      async ({ project_ref, finding_index }) => {
        const c = cache.get(project_ref);
        if (!c) return { content: [{ type: "text", text: `No cached audit. Run audit_project first.` }], isError: true };
        const f = c.result.findings[finding_index];
        if (!f) return { content: [{ type: "text", text: `Finding index ${finding_index} out of range (have ${c.result.findings.length})` }], isError: true };
    
        // Only attempt preview for SQL-runnable fixes (not Dashboard-toggle ones)
        const sqlOnly = f.fix_sql.split("\n").filter((l) => l.trim() && !l.trim().startsWith("--")).join("\n");
        if (!sqlOnly) {
          return { content: [{ type: "text", text: `Finding "${f.title}" requires a Dashboard change, not SQL. Cannot preview. Fix instructions:\n\n${f.fix_sql}` }] };
        }
    
        try {
          const wrapped = `BEGIN;\n${sqlOnly}\nROLLBACK;`;
          await sql(c.token, project_ref, wrapped);
          return {
            content: [
              { type: "text", text: `Preview OK — fix runs cleanly inside a transaction. Safe to apply with apply_fix(project_ref, ${finding_index}, confirm=true).` },
              { type: "text", text: `SQL that would run:\n\`\`\`sql\n${sqlOnly}\n\`\`\`` },
            ],
          };
        } catch (e) {
          return { content: [{ type: "text", text: `Preview FAILED — fix SQL would error: ${e.message}\n\nDo NOT apply. Investigate first.` }], isError: true };
        }
      }
    );
  • Input schema for preview_fix: project_ref (string) and finding_index (integer, 0-based from list_findings output).
    {
      description: "Preview what a fix would change WITHOUT applying it. Wraps the fix SQL in BEGIN; ... ROLLBACK; and returns what would have happened. Safe to call for any finding.",
      inputSchema: {
        project_ref: z.string(),
        finding_index: z.number().int().describe("0-based index from list_findings output"),
      },
    },
  • src/server.js:87-121 (registration)
    Registration of the 'preview_fix' tool with the MCP server using server.registerTool().
    server.registerTool(
      "preview_fix",
      {
        description: "Preview what a fix would change WITHOUT applying it. Wraps the fix SQL in BEGIN; ... ROLLBACK; and returns what would have happened. Safe to call for any finding.",
        inputSchema: {
          project_ref: z.string(),
          finding_index: z.number().int().describe("0-based index from list_findings output"),
        },
      },
      async ({ project_ref, finding_index }) => {
        const c = cache.get(project_ref);
        if (!c) return { content: [{ type: "text", text: `No cached audit. Run audit_project first.` }], isError: true };
        const f = c.result.findings[finding_index];
        if (!f) return { content: [{ type: "text", text: `Finding index ${finding_index} out of range (have ${c.result.findings.length})` }], isError: true };
    
        // Only attempt preview for SQL-runnable fixes (not Dashboard-toggle ones)
        const sqlOnly = f.fix_sql.split("\n").filter((l) => l.trim() && !l.trim().startsWith("--")).join("\n");
        if (!sqlOnly) {
          return { content: [{ type: "text", text: `Finding "${f.title}" requires a Dashboard change, not SQL. Cannot preview. Fix instructions:\n\n${f.fix_sql}` }] };
        }
    
        try {
          const wrapped = `BEGIN;\n${sqlOnly}\nROLLBACK;`;
          await sql(c.token, project_ref, wrapped);
          return {
            content: [
              { type: "text", text: `Preview OK — fix runs cleanly inside a transaction. Safe to apply with apply_fix(project_ref, ${finding_index}, confirm=true).` },
              { type: "text", text: `SQL that would run:\n\`\`\`sql\n${sqlOnly}\n\`\`\`` },
            ],
          };
        } catch (e) {
          return { content: [{ type: "text", text: `Preview FAILED — fix SQL would error: ${e.message}\n\nDo NOT apply. Investigate first.` }], isError: true };
        }
      }
    );
  • The sql() helper function that executes a query against the Supabase project's database/query API. Used by preview_fix to run the wrapped BEGIN/ROLLBACK fix SQL.
    async function sql(token, ref, query) {
      const r = await fetch(`${API}/projects/${ref}/database/query`, {
        method: "POST",
        headers: {
          Authorization: `Bearer ${token}`,
          "Content-Type": "application/json",
          "User-Agent": UA,
        },
        body: JSON.stringify({ query }),
      });
      if (!r.ok) throw new Error(`SQL ${r.status}: ${await r.text()}`);
      return r.json();
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Discloses that the tool does not apply changes (wrapped in rollback) and is safe. With no annotations, it adequately covers the non-mutating behavioral trait.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, front-loaded with purpose, no wasted words. Efficiently conveys the core function.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Adequate for a simple preview tool, but lacks explanation of return format or what 'returns what would have happened' means. No output schema provided.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 50%, but description adds no meaning for parameters. 'project_ref' lacks description in both schema and description, missing opportunity to explain its role.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool previews changes without applying, wrapping fix SQL in BEGIN...ROLLBACK. It distinguishes from siblings like apply_fix by focusing on preview-only behavior.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly states it is safe to call for any finding, implying usage for testing/reviewing. Does not explicitly exclude scenarios or name alternatives, but context is clear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Perufitlife/supabase-security-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server