Skip to main content
Glama
metrxbots

Metrx MCP Server

by metrxbots

metrx_get_budget_status

Monitor spending governance across your agent fleet by checking current budget status, including spending versus limits, warning/exceeded counts, and enforcement modes.

Instructions

Get the current status of all budget configurations. Shows spending vs limits, warning/exceeded counts, and enforcement modes. Use this to monitor spending governance across your agent fleet. Do NOT use for creating/changing budgets — use set_budget or update_budget_mode.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Main handler function for get_budget_status tool. Fetches budget status from the API endpoint '/budgets/status', handles errors, and formats the response using formatBudgetStatus helper.
    async () => {
      const result = await client.get<BudgetStatus>('/budgets/status');
    
      if (result.error) {
        return {
          content: [{ type: 'text', text: `Error fetching budget status: ${result.error}` }],
          isError: true,
        };
      }
    
      const text = formatBudgetStatus(result.data!);
    
      return {
        content: [{ type: 'text', text }],
      };
    }
  • Tool registration for 'get_budget_status'. Defines the tool metadata including title, description, input schema (empty - no parameters required), and annotations (readOnly, idempotent).
    server.registerTool(
      'get_budget_status',
      {
        title: 'Get Budget Status',
        description:
          'Get the current status of all budget configurations. ' +
          'Shows spending vs limits, warning/exceeded counts, and enforcement modes. ' +
          'Use this to monitor spending governance across your agent fleet. ' +
          'Do NOT use for creating/changing budgets — use set_budget or update_budget_mode.',
        inputSchema: {},
        annotations: {
          readOnlyHint: true,
          destructiveHint: false,
          idempotentHint: true,
          openWorldHint: false,
        },
      },
      async () => {
        const result = await client.get<BudgetStatus>('/budgets/status');
    
        if (result.error) {
          return {
            content: [{ type: 'text', text: `Error fetching budget status: ${result.error}` }],
            isError: true,
          };
        }
    
        const text = formatBudgetStatus(result.data!);
    
        return {
          content: [{ type: 'text', text }],
        };
      }
    );
  • Type definitions for BudgetStatus and BudgetSummary interfaces. BudgetStatus contains the response structure including has_budgets, total_budgets, warning_count, exceeded_count, paused_count, and budgets array.
    export interface BudgetStatus {
      has_budgets: boolean;
      total_budgets: number;
      paused_count: number;
      warning_count: number;
      exceeded_count: number;
      budgets: BudgetSummary[];
    }
    
    export interface BudgetSummary {
      id: string;
      period: string;
      agent_id: string | null;
      limit_microcents: number;
      spent_microcents: number;
      pct_used: number;
      enforcement_mode: string;
      paused: boolean;
      over_warning: boolean;
      over_limit: boolean;
    }
  • src/index.ts:74-103 (registration)
    Prefix registration logic that adds 'metrx_' namespace to all tools. Wraps the original server.registerTool to apply rate limiting and automatically prefix tool names (e.g., 'get_budget_status' becomes 'metrx_get_budget_status').
    // ── Rate limiting middleware + metrx_ namespace prefix ──
    // All tools are registered exclusively as metrx_{name}.
    // The metrx_ prefix namespaces our tools to avoid collisions when
    // multiple MCP servers are used together.
    const METRX_PREFIX = 'metrx_';
    const originalRegisterTool = server.registerTool.bind(server);
    (server as any).registerTool = function (
      name: string,
      config: any,
      handler: (...handlerArgs: any[]) => Promise<any>
    ) {
      const wrappedHandler = async (...handlerArgs: any[]) => {
        if (!rateLimiter.isAllowed(name)) {
          return {
            content: [
              {
                type: 'text' as const,
                text: `Rate limit exceeded for tool '${name}'. Maximum 60 requests per minute allowed.`,
              },
            ],
            isError: true,
          };
        }
        return handler(...handlerArgs);
      };
    
      // Register with metrx_ prefix (only — no deprecated aliases)
      const prefixedName = name.startsWith(METRX_PREFIX) ? name : `${METRX_PREFIX}${name}`;
      originalRegisterTool(prefixedName, config, wrappedHandler);
    };
  • formatBudgetStatus helper function that formats the BudgetStatus API response into a human-readable markdown string with total budgets, warnings, exceeded counts, and detailed budget information.
    /** Format budget status */
    export function formatBudgetStatus(status: BudgetStatus): string {
      if (!status.has_budgets) {
        return 'No budgets configured. Use set_budget to create spending limits for your agents.';
      }
    
      const lines: string[] = [
        `## Budget Status`,
        '',
        `**Total Budgets**: ${status.total_budgets}`,
        `**Warnings**: ${status.warning_count}`,
        `**Exceeded**: ${status.exceeded_count}`,
        `**Paused**: ${status.paused_count}`,
      ];
    
      if (status.budgets.length > 0) {
        lines.push('');
        for (const b of status.budgets) {
          lines.push(formatBudget(b));
        }
      }
    
      return lines.join('\n');
    }

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/metrxbots/metrx-mcp-server'

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