Skip to main content
Glama

create_rule

Create automated rules for Facebook ad accounts to adjust ads based on performance conditions and scheduled actions.

Instructions

Create a new automated rule for the ad account.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesRule name
evaluation_specYesJSON string defining rule conditions
execution_specYesJSON string defining rule actions
schedule_specNoJSON string defining rule schedule

Implementation Reference

  • The create_rule tool handler. Defined via server.tool('create_rule', ...) with schema (name, evaluation_spec, execution_spec, schedule_spec). Calls client.post to POST to the Meta Ads API endpoint 'adrules_library'.
    server.tool(
      "create_rule",
      "Create a new automated rule for the ad account.",
      {
        name: z.string().describe("Rule name"),
        evaluation_spec: z.string().describe("JSON string defining rule conditions"),
        execution_spec: z.string().describe("JSON string defining rule actions"),
        schedule_spec: z.string().optional().describe("JSON string defining rule schedule"),
      },
      async (params) => {
        try {
          const { data, rateLimit } = await client.post(`${client.accountPath}/adrules_library`, { ...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 };
        }
      }
    );
  • Input schema for create_rule using Zod: name (string), evaluation_spec (string JSON), execution_spec (string JSON), schedule_spec (optional string JSON).
    {
      name: z.string().describe("Rule name"),
      evaluation_spec: z.string().describe("JSON string defining rule conditions"),
      execution_spec: z.string().describe("JSON string defining rule actions"),
      schedule_spec: z.string().optional().describe("JSON string defining rule schedule"),
    },
  • Registration function registerRuleTools that registers create_rule (and other rule tools) on the MCP server.
    export function registerRuleTools(server: McpServer, client: AdsClient): void {
      // ─── list_rules ────────────────────────────────────────────
      server.tool(
        "list_rules",
        "List automated rules for the ad account.",
        {
          fields: z.string().optional().describe("Comma-separated fields to return"),
          limit: z.number().optional().default(25).describe("Number of results to return"),
          after: z.string().optional().describe("Pagination cursor for next page"),
        },
        async (params) => {
          try {
            const { data, rateLimit } = await client.get(`${client.accountPath}/adrules_library`, { ...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 };
          }
        }
      );
    
      // ─── get_rule ──────────────────────────────────────────────
      server.tool(
        "get_rule",
        "Get details of a specific automated rule.",
        {
          rule_id: z.string().describe("Rule ID"),
          fields: z.string().optional().describe("Comma-separated fields to return"),
        },
        async ({ rule_id, ...params }) => {
          try {
            const { data, rateLimit } = await client.get(`/${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 };
          }
        }
      );
    
      // ─── create_rule ───────────────────────────────────────────
      server.tool(
        "create_rule",
        "Create a new automated rule for the ad account.",
        {
          name: z.string().describe("Rule name"),
          evaluation_spec: z.string().describe("JSON string defining rule conditions"),
          execution_spec: z.string().describe("JSON string defining rule actions"),
          schedule_spec: z.string().optional().describe("JSON string defining rule schedule"),
        },
        async (params) => {
          try {
            const { data, rateLimit } = await client.post(`${client.accountPath}/adrules_library`, { ...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 };
          }
        }
      );
    
      // ─── update_rule ───────────────────────────────────────────
      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 };
          }
        }
      );
    
      // ─── delete_rule ───────────────────────────────────────────
      server.tool(
        "delete_rule",
        "Delete an automated rule.",
        {
          rule_id: z.string().describe("Rule ID"),
        },
        async ({ rule_id }) => {
          try {
            const { data, rateLimit } = await client.delete(`/${rule_id}`);
            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/index.ts:75-75 (registration)
    Call site in main server where registerRuleTools is invoked with the live server and client.
    registerRuleTools(server, client);
  • The AdsClient.post method used by create_rule to POST 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}`;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries full burden. Only states 'create' with no disclosure of side effects, permissions, or behavior beyond creation. Fails to describe return value or error states.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence, direct and front-loaded. However, it is too brief for the number of parameters; could add more context without losing conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Missing output schema and annotations. Description does not cover return value, error handling, or prerequisites. For a tool with 4 parameters, more context is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Input schema has 100% coverage with minimal descriptions. The tool description adds no additional meaning to parameters. Baseline 3 applicable.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description clearly states it creates an automated rule for an ad account. Verb 'create' and object 'rule' are specific, but does not distinguish from other 'create' tools beyond object type.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives like update_rule or other create tools. No prerequisites or constraints mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/mikusnuz/meta-ads-mcp'

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