Skip to main content
Glama

Reallocate Budget

budget_reallocate

Transfer a dollar amount from one campaign's daily budget to another, across platforms like Google Ads and Meta Ads, with safeguards against negative budgets.

Instructions

Transfer a dollar amount from one campaign's daily budget to another. Works across platforms (e.g. shift $50/day from a Google Ads search campaign to a Meta Ads retargeting campaign). Input: from_campaign_id, to_campaign_id (UUIDs, must differ), amount (positive number in campaign currency). Rejects the call if from_campaign_id === to_campaign_id or if the source campaign would go below zero. Returns the updated budgets for both campaigns.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
from_campaign_idYesSource campaign
to_campaign_idYesDestination campaign
amountYesAmount to transfer

Implementation Reference

  • Core handler: reallocateBudget function that transfers daily budget from one campaign to another. Validates source campaign exists, budget availability, then updates both campaigns atomically via storage.
    export async function reallocateBudget(
      fromCampaignId: string,
      toCampaignId: string,
      amount: number,
      store?: Storage,
    ): Promise<{ from: { id: string; name: string; new_budget: number }; to: { id: string; name: string; new_budget: number }; amount: number }> {
      const s = store ?? defaultStorage;
      const fromCamp = await s.getCampaignById(fromCampaignId);
      if (!fromCamp) throw new NotFoundError('Campaign', fromCampaignId);
    
      const toCamp = await s.getCampaignById(toCampaignId);
      if (!toCamp) throw new NotFoundError('Campaign', toCampaignId);
    
      if (amount > fromCamp.daily_budget) {
        throw new ValidationError(`Cannot reallocate $${amount}. Source campaign "${fromCamp.name}" budget is only $${fromCamp.daily_budget}.`);
      }
    
      const newFromBudget = round(fromCamp.daily_budget - amount);
      const newToBudget = round(toCamp.daily_budget + amount);
    
      await s.updateCampaign(fromCampaignId, { daily_budget: newFromBudget });
      await s.updateCampaign(toCampaignId, { daily_budget: newToBudget });
    
      return {
        from: { id: fromCampaignId, name: fromCamp.name, new_budget: newFromBudget },
        to: { id: toCampaignId, name: toCamp.name, new_budget: newToBudget },
        amount,
      };
    }
  • Input schema: BudgetReallocateInputSchema defines the expected inputs: from_campaign_id (UUID), to_campaign_id (UUID), amount (positive number).
    export const BudgetReallocateInputSchema = z.object({
      from_campaign_id: z.string().uuid().describe('Source campaign'),
      to_campaign_id: z.string().uuid().describe('Destination campaign'),
      amount: z.number().min(1).describe('Amount to transfer'),
    });
  • src/index.ts:451-476 (registration)
    Tool registration: server.registerTool('budget_reallocate', ...) with title, description, input schema, and the async handler that validates inputs then calls reallocateBudget.
    // ── Tool 8: budget_reallocate ───────────────────────────────────────
    
    server.registerTool(
      'budget_reallocate',
      {
        title: 'Reallocate Budget',
        description: 'Transfer a dollar amount from one campaign\'s daily budget to another. Works across platforms (e.g. shift $50/day from a Google Ads search campaign to a Meta Ads retargeting campaign). Input: from_campaign_id, to_campaign_id (UUIDs, must differ), amount (positive number in campaign currency). Rejects the call if from_campaign_id === to_campaign_id or if the source campaign would go below zero. Returns the updated budgets for both campaigns.',
        inputSchema: BudgetReallocateInputSchema,
        annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
      },
      async ({ from_campaign_id, to_campaign_id, amount }) => {
        try {
          if (from_campaign_id === to_campaign_id) {
            return { content: [{ type: 'text' as const, text: 'from_campaign_id and to_campaign_id must be different campaigns.' }], isError: true };
          }
          if (amount <= 0) {
            return { content: [{ type: 'text' as const, text: 'amount must be greater than zero.' }], isError: true };
          }
          const result = await reallocateBudget(from_campaign_id, to_campaign_id, amount);
          return { content: [{ type: 'text' as const, text: JSON.stringify({
            message: `Successfully reallocated $${amount}`,
            ...result,
          }, null, 2) }] };
        } catch (e) { return handleToolError(e); }
      },
    );
  • src/index.ts:749-749 (registration)
    Tool listing: 'budget_reallocate' listed in the server tools array with description 'Transfer budget between campaigns'.
    { name: 'budget_reallocate', description: 'Transfer budget between campaigns' },
  • Helper function: round() used to round budget values to 2 decimal places.
    function round(n: number): number {
      return Math.round(n * 100) / 100;
    }
Behavior5/5

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

Since annotations carry minimal behavioral info (readOnlyHint, destructiveHint false), the description fully describes the tool's action (mutation), rejection rules (same ID, negative balance), and return value (updated budgets). This adds critical context beyond the annotations.

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

Conciseness5/5

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

The description is three sentences: purpose, example, then input/behavior details. Every sentence is informative with no redundancy. It is front-loaded with the core action.

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

Completeness5/5

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

With 3 required parameters, no output schema, and minimal annotations, the description covers all necessary aspects: what it does, constraints, acceptance criteria, and return value. No additional information is needed.

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

Parameters4/5

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

Schema coverage is 100%, so baseline is 3. The description goes beyond by explaining that IDs must differ, amount is in campaign currency, and rejection rules. This adds meaningful context beyond the schema's simple descriptions.

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

Purpose5/5

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

The description states a specific verb ('Transfer') and resource ('campaign's daily budget'). It clearly distinguishes from sibling tools like budget_analyze by focusing on reallocation across campaigns and platforms.

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

Usage Guidelines4/5

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

The description provides clear context for when to use the tool (shifting budget between campaigns) with a concrete cross-platform example. It mentions rejection conditions but does not explicitly state when not to use or suggest alternative tools.

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/enzoemir1/adops-mcp'

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