Learn how to build a complete MCP server that charges for tool usage using ATXP payments
atxp-math-server
and intialize a new Node.js project.
tsconfig.json
file with the following content at the root of our project to configure the TypeScript compiler.
package.json
file. We’ll add a few scripts to make it easier to build and run our project and set some project build settings.
.env
file in the root of your project and add the following line:
.env
to your .gitignore
file to prevent it from being committed.index.ts
file:
npm run build
. We can even start it locally by running npm run start
or npm run dev
to start it in development mode. However, we haven’t defined any tools yet, so it won’t be very useful.
npm run build
to verify that it compiles without errors. At this point, we could connect a client like Goose to it and test that our tool does in fact add two numbers together, but it will be more exciting to see it in action after we’ve integrated payments. Skip forward a few steps to see how to connect to our MCP server and test it out if you want to try it out without payments.
requirePayment
function from the ATXP server SDK. This function takes a price
parameter that specifies the amount of USDC to charge for the tool call.
add
tool. Now let’s test the payment integration by running the MCP server locally and connecting to it using Goose.
http
protocol and the port that the MCP server is listening on (3000).
https
URL. If you are using a free ngrok account (or are not authenticated with ngrok), the URL you are looking for will be something like https://<random-id>.ngrok-free.app
.