Skip to main content
Glama

create-function

Generate edge functions for Deno runtime by writing code to files for version control. Create serverless functions that handle HTTP requests and return responses.

Instructions

Create a new edge function that runs in Deno runtime. The code must be written to a file first for version control

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeFileYesPath to JavaScript file containing the function code. Must export: module.exports = async function(request) { return new Response(...) }
descriptionNo
nameYes
slugNo
statusNoactive

Implementation Reference

  • Full registration of the 'create-function' MCP tool using server.tool(), including name, description, input schema, and handler function wrapped with usage tracking.
    server.tool( 'create-function', 'Create a new edge function that runs in Deno runtime. The code must be written to a file first for version control', { ...functionUploadRequestSchema.omit({ code: true }).shape, codeFile: z .string() .describe( 'Path to JavaScript file containing the function code. Must export: module.exports = async function(request) { return new Response(...) }' ), }, withUsageTracking('create-function', async (args) => { try { let code: string; try { 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'}` ); } const response = await fetch(`${API_BASE_URL}/api/functions`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': getApiKey(), }, body: JSON.stringify({ slug: args.slug, name: args.name, code: code, description: args.description, status: args.status, }), }); const result = await handleApiResponse(response); return await addBackgroundContext({ content: [ { type: 'text', text: formatSuccessMessage( `Edge function '${args.slug}' created successfully from ${args.codeFile}`, result ), }, ], }); } catch (error) { const errMsg = error instanceof Error ? error.message : 'Unknown error occurred'; return { content: [ { type: 'text', text: `Error creating function: ${errMsg}`, }, ], isError: true, }; } }) );
  • The handler function executes the tool: reads the function code from the provided file path, sends a POST request to the backend API to create the edge function, handles the response, and formats the output with success/error messages.
    withUsageTracking('create-function', async (args) => { try { let code: string; try { 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'}` ); } const response = await fetch(`${API_BASE_URL}/api/functions`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': getApiKey(), }, body: JSON.stringify({ slug: args.slug, name: args.name, code: code, description: args.description, status: args.status, }), }); const result = await handleApiResponse(response); return await addBackgroundContext({ content: [ { type: 'text', text: formatSuccessMessage( `Edge function '${args.slug}' created successfully from ${args.codeFile}`, result ), }, ], }); } catch (error) { const errMsg = error instanceof Error ? error.message : 'Unknown error occurred'; return { content: [ { type: 'text', text: `Error creating function: ${errMsg}`, }, ], isError: true, }; }
  • Input schema for 'create-function' tool: uses functionUploadRequestSchema (omitting 'code') and adds required 'codeFile' parameter for the path to the JS source file.
    { ...functionUploadRequestSchema.omit({ code: true }).shape, codeFile: z .string() .describe( 'Path to JavaScript file containing the function code. Must export: module.exports = async function(request) { return new Response(...) }' ), },

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/InsForge/insforge-mcp'

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