update_function
Modify an existing custom function in the AI Meta MCP Server by updating its description, parameters schema, implementation code, or execution environment.
Instructions
Update an existing custom MCP function
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name of the function to update | |
| description | No | New description of what the function does | |
| parameters_schema | No | New JSON Schema for parameters | |
| implementation_code | No | New code to implement the function | |
| execution_environment | No | New environment to execute the code in |
Implementation Reference
- src/index.ts:319-406 (handler)The handler function for the 'update_function' tool. It checks if the function exists, validates the execution environment if changed, updates the tool definition, re-registers it with the server, saves to database, and returns success or error response.async ({ name, description, parameters_schema, implementation_code, execution_environment }) => { console.error(`Updating function: ${name}`); // Check if function exists if (!customTools[name]) { return { isError: true, content: [ { type: "text", text: `No function named "${name}" exists. Use define_function to create it.`, }, ], }; } // Validate execution environment if changing if (execution_environment === "javascript" && !ALLOW_JS_EXECUTION) { return { isError: true, content: [ { type: "text", text: "JavaScript execution is not allowed in this environment.", }, ], }; } if (execution_environment === "python" && !ALLOW_PYTHON_EXECUTION) { return { isError: true, content: [ { type: "text", text: "Python execution is not allowed in this environment.", }, ], }; } if (execution_environment === "shell" && !ALLOW_SHELL_EXECUTION) { return { isError: true, content: [ { type: "text", text: "Shell execution is not allowed in this environment.", }, ], }; } // Update the tool definition const updatedTool = { ...customTools[name] }; if (description !== undefined) updatedTool.description = description; if (parameters_schema !== undefined) updatedTool.inputSchema = parameters_schema; if (implementation_code !== undefined) updatedTool.implementation = implementation_code; if (execution_environment !== undefined) updatedTool.executionEnvironment = execution_environment; updatedTool.updatedAt = new Date(); // Register the updated tool try { // The server doesn't have a way to update tools, so we'll just re-register it registerToolWithServer(updatedTool); // Store the updated tool customTools[name] = updatedTool; await saveToolsDatabase(); return { content: [ { type: "text", text: `Successfully updated function "${name}".`, }, ], }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Error updating function: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } }
- src/index.ts:312-318 (schema)The input schema for the 'update_function' tool, defining optional parameters for updating name (required), description, schema, code, and environment.{ name: z.string().min(1).describe("Name of the function to update"), description: z.string().optional().describe("New description of what the function does"), parameters_schema: z.record(z.any()).optional().describe("New JSON Schema for parameters"), implementation_code: z.string().optional().describe("New code to implement the function"), execution_environment: z.enum(["javascript", "python", "shell"]).optional().describe("New environment to execute the code in"), },
- src/index.ts:309-407 (registration)The registration of the 'update_function' tool using server.tool(), including name, description, schema, and handler.server.tool( "update_function", "Update an existing custom MCP function", { name: z.string().min(1).describe("Name of the function to update"), description: z.string().optional().describe("New description of what the function does"), parameters_schema: z.record(z.any()).optional().describe("New JSON Schema for parameters"), implementation_code: z.string().optional().describe("New code to implement the function"), execution_environment: z.enum(["javascript", "python", "shell"]).optional().describe("New environment to execute the code in"), }, async ({ name, description, parameters_schema, implementation_code, execution_environment }) => { console.error(`Updating function: ${name}`); // Check if function exists if (!customTools[name]) { return { isError: true, content: [ { type: "text", text: `No function named "${name}" exists. Use define_function to create it.`, }, ], }; } // Validate execution environment if changing if (execution_environment === "javascript" && !ALLOW_JS_EXECUTION) { return { isError: true, content: [ { type: "text", text: "JavaScript execution is not allowed in this environment.", }, ], }; } if (execution_environment === "python" && !ALLOW_PYTHON_EXECUTION) { return { isError: true, content: [ { type: "text", text: "Python execution is not allowed in this environment.", }, ], }; } if (execution_environment === "shell" && !ALLOW_SHELL_EXECUTION) { return { isError: true, content: [ { type: "text", text: "Shell execution is not allowed in this environment.", }, ], }; } // Update the tool definition const updatedTool = { ...customTools[name] }; if (description !== undefined) updatedTool.description = description; if (parameters_schema !== undefined) updatedTool.inputSchema = parameters_schema; if (implementation_code !== undefined) updatedTool.implementation = implementation_code; if (execution_environment !== undefined) updatedTool.executionEnvironment = execution_environment; updatedTool.updatedAt = new Date(); // Register the updated tool try { // The server doesn't have a way to update tools, so we'll just re-register it registerToolWithServer(updatedTool); // Store the updated tool customTools[name] = updatedTool; await saveToolsDatabase(); return { content: [ { type: "text", text: `Successfully updated function "${name}".`, }, ], }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Error updating function: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );