update-function
Modify an existing edge function's code or metadata in the Insforge MCP Server to adjust its behavior or configuration.
Instructions
Update an existing edge function code or metadata
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| slug | Yes | The slug identifier of the function to update | |
| name | No | ||
| description | No | ||
| status | No | ||
| codeFile | No | Path to JavaScript file containing the new function code. Must export: module.exports = async function(request) { return new Response(...) } |
Implementation Reference
- src/shared/tools.ts:927-987 (handler)Core handler logic for the 'update-function' tool. Constructs update payload from args (including optional code file read), sends PUT request to backend API /api/functions/{slug}, handles response with success/error formatting and background context addition.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:914-988 (registration)MCP server tool registration for 'update-function', defining name, description, input parameters schema, and 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, }; } }) );
- src/shared/tools.ts:917-925 (schema)Zod input schema validation for the tool parameters: required slug, fields from imported 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(...) }' ),