Overview

The @atxp/server package is a support package used for packages like @atxp/express. You should generally not need to reference @atxp/server directly.
This package depends on types and utilities from @atxp/common. All shared types like ATXPArgs and payment utilities are documented in the common package.

Installation

npm install @atxp/server

Functions

requirePayment

requirePayment({
  price: BigNumber,
  getExistingPaymentId?: () => Promise<string | null>
  }): Promise<void>
Requires payment before executing a tool. This function must be called before any paid tool logic.
The requirePayment function uses BigNumber for precise decimal arithmetic. Install it with npm install bignumber.js and import it as shown above.
Arguments Example usage
import { requirePayment } from '@atxp/server'
import BigNumber from 'bignumber.js'

server.tool(
  "add",
  "Use this tool to add two numbers together.",
  {
    a: z.number().describe("The first number to add"),
    b: z.number().describe("The second number to add"),
  },
  async ({ a, b }) => {
    // Require payment for the tool call
    await requirePayment({price: BigNumber(0.01)});
    return {
      content: [
        {
          type: "text",
          text: `${a + b}`,
        },
      ],
    };
  }
);