Skip to main content
Glama

create-function

Create edge functions for Deno runtime by writing code to files for version control, enabling serverless execution in production cloud infrastructure.

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
nameYes
slugNo
descriptionNo
statusNoactive
codeFileYesPath to JavaScript file containing the function code. Must export: module.exports = async function(request) { return new Response(...) }

Implementation Reference

  • Core handler that reads JavaScript code from a specified file and sends a POST request to the API endpoint to create a new edge function. Handles file reading errors and API responses, formats 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 definition for the create-function tool. Uses functionUploadRequestSchema (omitting code field) and adds required codeFile parameter pointing 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(...) }' ), },
  • Full registration of the 'create-function' tool on the MCP server, 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, }; } }) );
  • Calls registerInsforgeTools to register all tools (including create-function) on the HTTP MCP server.
    registerInsforgeTools(mcpServer, { apiKey, apiBaseUrl, });
  • Calls registerInsforgeTools to register all tools (including create-function) on the stdio MCP server.
    const toolsConfig = registerInsforgeTools(server, { apiKey: api_key, apiBaseUrl: api_base_url || process.env.API_BASE_URL, });

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