Skip to main content
Glama

Check Lightning budget

l402_balance
Read-onlyIdempotent

Check the remaining Bitcoin Lightning budget for the current MCP session to confirm sufficient sats before making API calls.

Instructions

Returns the remaining Bitcoin Lightning budget for this MCP session. Use this before calling l402_fetch to confirm you have enough sats — avoids wasted attempts when budget is exhausted. Returns: ' sats remaining of total (spent: sats)'. Read-only — does not trigger any payment or side effect. Budget is set at server startup via BUDGET_SATS (default: 1000 sats ≈ $0.60); to increase it, restart the MCP server.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • mcp/server.ts:163-194 (registration)
    Registration of the l402_balance tool via server.registerTool(...) with description and handler.
    // Tool: l402_balance
    server.registerTool(
      "l402_balance",
      {
        title: "Check Lightning budget",
        description:
          "Returns the remaining Bitcoin Lightning budget for this MCP session. " +
          "Use this before calling l402_fetch to confirm you have enough sats — avoids wasted attempts when budget is exhausted. " +
          "Returns: '<remaining> sats remaining of <total> total (spent: <spent> sats)'. " +
          "Read-only — does not trigger any payment or side effect. " +
          "Budget is set at server startup via BUDGET_SATS (default: 1000 sats ≈ $0.60); to increase it, restart the MCP server.",
        inputSchema: {},
        annotations: {
          readOnlyHint: true,
          idempotentHint: true,
        },
      },
      async () => {
        const report = requireClient().spendingReport();
        if (!report) {
          return {
            content: [{ type: "text" as const, text: "No budget configured." }],
          };
        }
        return {
          content: [{
            type: "text" as const,
            text: `Budget: ${report.remaining} sats remaining of ${budgetSats} total (spent: ${report.total} sats)`,
          }],
        };
      }
    );
  • Handler function for l402_balance tool. Calls requireClient().spendingReport() and returns a formatted string of remaining budget.
    async () => {
      const report = requireClient().spendingReport();
      if (!report) {
        return {
          content: [{ type: "text" as const, text: "No budget configured." }],
        };
      }
      return {
        content: [{
          type: "text" as const,
          text: `Budget: ${report.remaining} sats remaining of ${budgetSats} total (spent: ${report.total} sats)`,
        }],
      };
    }
  • SpendingReport interface defining the shape of the report returned by BudgetTracker.report() — used by l402_balance handler.
    export interface SpendingReport {
      total: number;
      remaining: number;
      byDomain: Record<string, number>;
      transactions: Array<{ url: string; sats: number; ts: number }>;
    }
    
    export class BudgetTracker {
      private spent = 0;
      private byDomain: Record<string, number> = {};
      private transactions: Array<{ url: string; sats: number; ts: number }> = [];
    
      constructor(
        private readonly limitSats: number,
        private readonly perDomain?: Record<string, number>,
        private readonly onSpend?: (sats: number, url: string) => void,
        private readonly onBudgetExceeded?: (url: string, sats: number) => void,
      ) {}
    
      check(url: string, sats: number): void {
        const remaining = this.limitSats - this.spent;
        if (sats > remaining) {
          this.onBudgetExceeded?.(url, sats);
          throw new BudgetExceededError(url, sats, remaining);
        }
    
        if (this.perDomain) {
          const domain = this._domain(url);
          const domainLimit = this.perDomain[domain];
          if (domainLimit !== undefined) {
            const domainSpent = this.byDomain[domain] ?? 0;
            const domainRemaining = domainLimit - domainSpent;
            if (sats > domainRemaining) {
              this.onBudgetExceeded?.(url, sats);
              throw new BudgetExceededError(url, sats, domainRemaining);
            }
          }
        }
      }
    
      record(url: string, sats: number): void {
        this.spent += sats;
        const domain = this._domain(url);
        this.byDomain[domain] = (this.byDomain[domain] ?? 0) + sats;
        this.transactions.push({ url, sats, ts: Date.now() });
        this.onSpend?.(sats, url);
      }
    
      report(): SpendingReport {
        return {
          total: this.spent,
          remaining: Math.max(0, this.limitSats - this.spent),
          byDomain: { ...this.byDomain },
          transactions: [...this.transactions],
        };
      }
    
      private _domain(url: string): string {
        try { return new URL(url).hostname; }
        catch { return url; }
      }
    }
  • BudgetTracker.report() method produces the SpendingReport consumed by spendingReport() on L402Client.
      report(): SpendingReport {
        return {
          total: this.spent,
          remaining: Math.max(0, this.limitSats - this.spent),
          byDomain: { ...this.byDomain },
          transactions: [...this.transactions],
        };
      }
    
      private _domain(url: string): string {
        try { return new URL(url).hostname; }
        catch { return url; }
      }
    }
  • L402Client.spendingReport() — delegates to BudgetTracker.report(). Called by the l402_balance handler to get budget data.
    /** Returns a spending report. Only available when budgetSats is configured. */
    spendingReport() {
      if (!this.budget) return null;
      return this.budget.report();
    }
Behavior5/5

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

Annotations already declare readOnlyHint and idempotentHint. The description adds that it is read-only with no side effects, and provides background on budget configuration (BUDGET_SATS default and restart requirement), going beyond 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?

Four sentences: first states purpose, second gives usage guidance, third provides return format, fourth adds behavioral context. Every sentence adds value; no wasted words.

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 no parameters, no output schema, and strong annotations, the description fully covers how to use the tool, what it returns, and important context about budget limits and configuration.

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?

Input schema has zero parameters with 100% schema coverage. Baseline for 0 params is 4; description adds no parameter info, which is appropriate since none are needed.

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 'Returns the remaining Bitcoin Lightning budget for this MCP session,' specifying the verb and resource. It distinguishes itself from sibling tools by noting it should be used before l402_fetch and that it is read-only.

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

Usage Guidelines5/5

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

Explicitly instructs to use this tool before l402_fetch to check budget sufficiency, avoiding wasted attempts. Also explains how to increase budget, providing clear when-to-use context.

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/ShinyDapps/l402-kit'

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