Repository navigation
examples: Mastra agent checks an x402 endpoint before paying - #13
Open
riccardocens-code wants to merge 2 commits into
Open
riccardocens-code wants to merge 2 commits into
riccardocens-code wants to merge 2 commits into
Conversation
|
👀 We've notified the reward creators here. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
/claim #3
Adds
examples/mastra-prepay-check/, a runnable Mastra example that checks an x402 endpoint before anything pays it.What it does
src/tool.ts: acreateTooltool (check_x402_endpoint) that callsrunCheck402({ url })from@agent402-dev/ai-sdk-toolsand returns its result (fixes,findings,usdcAmounts,signedOrPaid). One request without a payment header; nothing signed or paid, no key read.src/agent.ts: the agent. Its instructions say: do not pay whenfixes > 0(and not whenfixesisnull, whichrunCheck402returns when the URL was refused or the request failed).allowLocal: trueso the check can reachhttp://127.0.0.1for the local server; other URLs must still be public https. The README says how to drop it.src/broken402Server.ts: a small local server whose 402 has aPAYMENT-REQUIREDheader that is not base64 JSON.src/tool.test.ts:npm test, no LLM key: a public http URL is refused with no request, and a local broken 402 givesfixes > 0.package.jsonpins@mastra/core1.87.0,@agent402-dev/ai-sdk-tools0.1.0, zod 4.6.7, tsx 4.23.15. Node 22.13+ (Mastra's requirement).Run by me (@mastra/core 1.87.0, model
google/gemini-3.5-flash-litevia Mastra's model router withGOOGLE_GENERATIVE_AI_API_KEY, ai-sdk-tools 0.1.0 / pay-server 0.15.0, Node 24.22.1, npm 11.21.1).npm install && npm start -- <url>:Live endpoint,
npm start -- "https://agent402-check402.agent402-ebc.workers.dev/x402/check402?url=https://example.com":Local broken 402,
npm run broken-402 &thennpm start -- http://127.0.0.1:4021/paid:npm start -- http://example.com/paid(not https): refused without a request:npm test: 2 tests pass.No payment code, rules, keys, wallets or signing are touched; the change is only the new example folder.