Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/mcp-server-supabase/src/platform/api-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,31 @@ export function createSupabaseApiPlatform(
existingEdgeFunction = await functions.getEdgeFunction(projectId, name);
} catch (error) {}

// If not provided, keep the current setting. New functions default to true.
if (verify_jwt === undefined) {
const currentResponse = await managementApiClient.GET(
'/v1/projects/{ref}/functions/{function_slug}',
{
params: {
path: {
ref: projectId,
function_slug: name,
},
},
}
);

if (currentResponse.response.status === 404) {
verify_jwt = true;
} else {
assertSuccess(
currentResponse,
'Failed to read the current Edge Function settings'
);
verify_jwt = currentResponse.data.verify_jwt ?? true;
}
}

// If not provided, keep the existing import map path while its file is
// still part of the upload. Otherwise fall back to the file name heuristic.
const existingImportMapPath = existingEdgeFunction?.import_map_path;
Expand Down
89 changes: 89 additions & 0 deletions packages/mcp-server-supabase/src/server.functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,95 @@ describe('tools', () => {
expect(result.verify_jwt).toBe(false);
expect(result.version).toBe(2);
});

test('redeploying without verify_jwt keeps it turned off', async () => {
const { callTool } = await setup();
const { project } = await createProjectFixture({
organization: { name: 'My Org', allowed_release_channels: ['ga'] },
project: { name: 'Project 1', region: 'us-east-1' },
});

const functionName = 'stripe-webhook';

// First deploy with verify_jwt: false
await project.deployEdgeFunction(
{
name: functionName,
entrypoint_path: 'index.ts',
verify_jwt: false,
},
[
new File(['console.log("v1");'], 'index.ts', {
type: 'application/typescript',
}),
]
);

// Redeploy without verify_jwt
const result = await callTool({
name: 'deploy_edge_function',
arguments: {
project_id: project.id,
name: functionName,
files: [
{
name: 'index.ts',
content: 'console.log("v2");',
},
],
},
});

expect(result.version).toBe(2);
expect(result.verify_jwt).toBe(false);
});

test('redeploying without verify_jwt stops if the current setting cannot be read', async () => {
const { callTool } = await setup();
const { project } = await createProjectFixture({
organization: { name: 'My Org', allowed_release_channels: ['ga'] },
project: { name: 'Project 1', region: 'us-east-1' },
});

const functionName = 'stripe-webhook';

await project.deployEdgeFunction(
{
name: functionName,
entrypoint_path: 'index.ts',
verify_jwt: false,
},
[
new File(['console.log("v1");'], 'index.ts', {
type: 'application/typescript',
}),
]
);

harness.mockServer?.use(
http.get(
`${API_URL}/v1/projects/${project.id}/functions/${functionName}`,
() => HttpResponse.json({ message: 'Internal error' }, { status: 500 })
)
);

const result = callTool({
name: 'deploy_edge_function',
arguments: {
project_id: project.id,
name: functionName,
files: [
{
name: 'index.ts',
content: 'console.log("v2");',
},
],
},
});

await expect(result).rejects.toThrow();
expect(project.edge_functions.get(functionName)?.verify_jwt).toBe(false);
});
describe('create_edge_function_secret via URL elicitation', () => {
test('url-capable client receives InputRequiredResult with url mode', async () => {
const { client } = await setupUrlCapable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const deployEdgeFunctionInputSchema = z.object({
.optional(),
verify_jwt: z
.boolean()
.default(true)
.optional()
.describe(
'Whether to require a valid JWT in the Authorization header. Keep this `true` unless the user asks to turn it off, the function previously had it turned off, or the function body does its own authentication (e.g. API keys, webhooks).'
'Whether to require a valid JWT in the Authorization header. Leave it out to keep the current setting when updating a function; new functions default to `true`. Set it to `false` only when the user asks, or when the function body does its own authentication (e.g. API keys, webhooks).'
),
files: z
.array(
Expand Down