update-function
Modify existing edge function code or metadata to update functionality, change status between draft and active, or revise descriptions and names.
Instructions
Update an existing edge function code or metadata
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| codeFile | No | Path to JavaScript file containing the new function code. Must export: module.exports = async function(request) { return new Response(...) } | |
| description | No | ||
| name | No | ||
| slug | Yes | The slug identifier of the function to update | |
| status | No |
Implementation Reference
- src/shared/tools.ts:930-990 (handler)Core handler logic for updating an edge function. Reads optional code from file, builds update payload with name, description, status, code, performs PUT request to /api/functions/{slug}, handles response and errors.withUsageTracking('update-function', async (args) => { try { const updateData: FunctionUpdateRequest = {}; if (args.name) { updateData.name = args.name; } if (args.codeFile) { try { updateData.code = await fs.readFile(args.codeFile, 'utf-8'); } catch (fileError) { throw new Error( `Failed to read code file '${args.codeFile}': ${fileError instanceof Error ? fileError.message : 'Unknown error'}` ); } } if (args.description !== undefined) { updateData.description = args.description; } if (args.status) { updateData.status = args.status; } const response = await fetch(`${API_BASE_URL}/api/functions/${args.slug}`, { method: 'PUT', headers: { 'Content-Type': 'application/json', 'x-api-key': getApiKey(), }, body: JSON.stringify(updateData), }); const result = await handleApiResponse(response); const fileInfo = args.codeFile ? ` from ${args.codeFile}` : ''; return await addBackgroundContext({ content: [ { type: 'text', text: formatSuccessMessage( `Edge function '${args.slug}' updated successfully${fileInfo}`, result ), }, ], }); } catch (error) { const errMsg = error instanceof Error ? error.message : 'Unknown error occurred'; return { content: [ { type: 'text', text: `Error updating function: ${errMsg}`, }, ], isError: true, }; } })
- src/shared/tools.ts:920-929 (schema)Input schema using Zod: required 'slug', fields from external functionUpdateRequestSchema (excluding code), optional 'codeFile' path.{ slug: z.string().describe('The slug identifier of the function to update'), ...functionUpdateRequestSchema.omit({ code: true }).shape, codeFile: z .string() .optional() .describe( 'Path to JavaScript file containing the new function code. Must export: module.exports = async function(request) { return new Response(...) }' ), },
- src/shared/tools.ts:917-991 (registration)MCP server.tool registration defining the tool name, description, input schema, and wrapped handler function.server.tool( 'update-function', 'Update an existing edge function code or metadata', { slug: z.string().describe('The slug identifier of the function to update'), ...functionUpdateRequestSchema.omit({ code: true }).shape, codeFile: z .string() .optional() .describe( 'Path to JavaScript file containing the new function code. Must export: module.exports = async function(request) { return new Response(...) }' ), }, withUsageTracking('update-function', async (args) => { try { const updateData: FunctionUpdateRequest = {}; if (args.name) { updateData.name = args.name; } if (args.codeFile) { try { updateData.code = await fs.readFile(args.codeFile, 'utf-8'); } catch (fileError) { throw new Error( `Failed to read code file '${args.codeFile}': ${fileError instanceof Error ? fileError.message : 'Unknown error'}` ); } } if (args.description !== undefined) { updateData.description = args.description; } if (args.status) { updateData.status = args.status; } const response = await fetch(`${API_BASE_URL}/api/functions/${args.slug}`, { method: 'PUT', headers: { 'Content-Type': 'application/json', 'x-api-key': getApiKey(), }, body: JSON.stringify(updateData), }); const result = await handleApiResponse(response); const fileInfo = args.codeFile ? ` from ${args.codeFile}` : ''; return await addBackgroundContext({ content: [ { type: 'text', text: formatSuccessMessage( `Edge function '${args.slug}' updated successfully${fileInfo}`, result ), }, ], }); } catch (error) { const errMsg = error instanceof Error ? error.message : 'Unknown error occurred'; return { content: [ { type: 'text', text: `Error updating function: ${errMsg}`, }, ], isError: true, }; } }) );