update_rule
Update an existing automated rule by modifying its name, conditions, actions, schedule, or status.
Instructions
Update an existing automated rule.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rule_id | Yes | Rule ID | |
| name | No | New rule name | |
| evaluation_spec | No | JSON string defining updated rule conditions | |
| execution_spec | No | JSON string defining updated rule actions | |
| schedule_spec | No | JSON string defining updated rule schedule | |
| status | No | Rule status: ENABLED, DISABLED |
Implementation Reference
- src/tools/rules.ts:75-83 (handler)The handler function for the 'update_rule' tool. It destructures rule_id from params, makes a POST request to /{rule_id}, and returns the response or an error message.
async ({ rule_id, ...params }) => { try { const { data, rateLimit } = await client.post(`/${rule_id}`, { ...params }); return { content: [{ type: "text" as const, text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] }; } catch (error) { return { content: [{ type: "text" as const, text: `Failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } ); - src/tools/rules.ts:67-74 (schema)Zod schema definitions for the 'update_rule' tool input parameters: rule_id (required), name, evaluation_spec, execution_spec, schedule_spec, and status (all optional).
{ rule_id: z.string().describe("Rule ID"), name: z.string().optional().describe("New rule name"), evaluation_spec: z.string().optional().describe("JSON string defining updated rule conditions"), execution_spec: z.string().optional().describe("JSON string defining updated rule actions"), schedule_spec: z.string().optional().describe("JSON string defining updated rule schedule"), status: z.string().optional().describe("Rule status: ENABLED, DISABLED"), }, - src/tools/rules.ts:64-83 (registration)Registration of the 'update_rule' tool via server.tool() with name 'update_rule', description 'Update an existing automated rule.', schema definitions, and handler function.
server.tool( "update_rule", "Update an existing automated rule.", { rule_id: z.string().describe("Rule ID"), name: z.string().optional().describe("New rule name"), evaluation_spec: z.string().optional().describe("JSON string defining updated rule conditions"), execution_spec: z.string().optional().describe("JSON string defining updated rule actions"), schedule_spec: z.string().optional().describe("JSON string defining updated rule schedule"), status: z.string().optional().describe("Rule status: ENABLED, DISABLED"), }, async ({ rule_id, ...params }) => { try { const { data, rateLimit } = await client.post(`/${rule_id}`, { ...params }); return { content: [{ type: "text" as const, text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] }; } catch (error) { return { content: [{ type: "text" as const, text: `Failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } ); - src/tools/rules.ts:64-83 (registration)Complete registration of the 'update_rule' tool on the MCP server, including its name, description, input schema, and handler function.
server.tool( "update_rule", "Update an existing automated rule.", { rule_id: z.string().describe("Rule ID"), name: z.string().optional().describe("New rule name"), evaluation_spec: z.string().optional().describe("JSON string defining updated rule conditions"), execution_spec: z.string().optional().describe("JSON string defining updated rule actions"), schedule_spec: z.string().optional().describe("JSON string defining updated rule schedule"), status: z.string().optional().describe("Rule status: ENABLED, DISABLED"), }, async ({ rule_id, ...params }) => { try { const { data, rateLimit } = await client.post(`/${rule_id}`, { ...params }); return { content: [{ type: "text" as const, text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] }; } catch (error) { return { content: [{ type: "text" as const, text: `Failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } ); - src/services/ads-client.ts:187-225 (helper)The AdsClient.post() helper method used by the update_rule handler to send the POST request to the Meta Ads API.
async post( path: string, params?: Record<string, unknown> ): Promise<ClientResponse> { return this.request("POST", path, params); } async delete( path: string, params?: Record<string, unknown> ): Promise<ClientResponse> { return this.request("DELETE", path, params); } // --- Upload (URL-based) --- async upload( path: string, fileUrl: string, params?: Record<string, unknown> ): Promise<ClientResponse> { return this.post(path, { ...params, url: fileUrl }); } // --- Account helpers --- get accountPath(): string { return `/act_${this.accountId}`; } get accountId(): string { if (!this.config.adAccountId) { throw new Error( "META_AD_ACCOUNT_ID is not configured. Set it as an environment variable." ); } return this.config.adAccountId; }