Skip to main content
Glama

check_budget

Check budget health by combining usage quota and cost data to determine if you are within safe operating limits.

Instructions

Quick pass/fail budget health check. Combines usage quota and cost data to give a summary of whether you're within safe operating limits.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The 'check_budget' tool handler. It calls getUsage() and getCosts() in parallel via Promise.all, computes a usage percentage, classifies the status (critical/warning/healthy), and returns a JSON summary with plan, event usage, costs, and savings.
    name: "check_budget",
    description:
      "Quick pass/fail budget health check. Combines usage quota and cost data " +
      "to give a summary of whether you're within safe operating limits.",
    inputSchema: {
      type: "object",
      properties: {},
    },
    handler: async (client) => {
      const [usage, costs] = await Promise.all([
        client.getUsage(),
        client.getCosts(),
      ]);
    
      const usagePct = usage.event_limit > 0
        ? (usage.event_count / usage.event_limit) * 100
        : 0;
    
      const status = usagePct >= 90
        ? "critical"
        : usagePct >= 75
          ? "warning"
          : "healthy";
    
      return JSON.stringify(
        {
          status,
          plan: usage.plan,
          events: {
            used: usage.event_count,
            limit: usage.event_limit,
            percent: `${usagePct.toFixed(1)}%`,
          },
          costs: {
            monthly_total: costs.monthly.total_cost,
            trace_count: costs.monthly.trace_count,
          },
          savings: costs.savings,
        },
        null,
        2,
      );
    },
  • Registration loop that iterates over all tools (including 'check_budget') and registers each with the MCP server via server.tool().
    // Register each tool with the MCP server
    for (const tool of tools) {
      const shape = buildToolShape(tool.inputSchema.properties, tool.inputSchema.required ?? []);
    
      const toolName = tool.name;
      const handler = tool.handler;
    
      server.tool(toolName, tool.description, shape, async (args) => {
        try {
          const text = await handler(client, args as Record<string, unknown>);
          return { content: [{ type: "text" as const, text }] };
        } catch (err) {
          const message = err instanceof Error ? err.message : String(err);
          return {
            content: [{ type: "text" as const, text: `Error: ${message}` }],
            isError: true,
          };
        }
      });
    }
  • Input schema for 'check_budget': an empty object (no parameters required).
    inputSchema: {
      type: "object",
      properties: {},
    },
  • The AgentGuardClient.getUsage() method that fetches /api/v1/usage for plan and event count/limit data.
    async getUsage() {
      return this.fetch<{
        plan: string;
        current_month: string;
        event_count: number;
        event_limit: number;
        retention_days: number;
        max_keys: number;
        max_users: number;
      }>("/api/v1/usage");
    }
    
    async getCosts() {
      return this.fetch<{
        monthly: { total_cost: number; trace_count: number };
        by_model: Array<{ model: string; total_cost: number; call_count: number }>;
        savings: { guard_events: number; estimated_savings: number };
      }>("/api/v1/costs");
    }
  • The AgentGuardClient.getCosts() method that fetches /api/v1/costs for monthly total cost, trace count, and savings data.
    async getCosts() {
      return this.fetch<{
        monthly: { total_cost: number; trace_count: number };
        by_model: Array<{ model: string; total_cost: number; call_count: number }>;
        savings: { guard_events: number; estimated_savings: number };
      }>("/api/v1/costs");
    }
Behavior2/5

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

No annotations provided, and description does not disclose return format, side effects, or whether it is read-only. 'Pass/fail' is vague without precise details.

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?

Two concise sentences front-load the purpose and behavior with no wasted words.

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

Completeness4/5

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

Given zero parameters and no output schema, the description adequately explains the tool's function but lacks specification of return type (e.g., boolean or string).

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?

No parameters exist, so the description does not need to add parameter info. Baseline 4 applies.

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 clearly states it is a 'pass/fail budget health check' combining usage quota and cost data, distinct from sibling tools like get_costs and get_usage which return raw data.

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

Usage Guidelines3/5

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

The description implies quick assessment, but lacks explicit guidance on when to use versus alternatives like get_alerts or get_trace.

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/bmdhodl/agent47'

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