[{"data":1,"prerenderedAt":420},["ShallowReactive",2],{"integration:\u002Fintegrations\u002Fmastra":3},{"id":4,"title":5,"body":6,"description":411,"extension":412,"keywords":413,"logo":414,"meta":415,"navigation":155,"order":213,"path":416,"product":18,"seo":417,"stem":418,"__hash__":419},"integrations\u002Fintegrations\u002Fmastra.md","Use 402.report with Mastra",{"type":7,"value":8,"toc":406},"minimark",[9,29,34,62,75,79,319,334,338,350,399,402],[10,11,12,19,20,24,25,28],"p",{},[13,14,18],"a",{"href":15,"rel":16},"https:\u002F\u002Fmastra.ai",[17],"nofollow","Mastra"," agents connect to remote MCP servers through ",[21,22,23],"code",{},"@mastra\u002Fmcp","'s\n",[21,26,27],{},"MCPClient",". 402.report ships a helper that returns the exact server entry, so your agent can\nquery its own x402 spend and debug failed payments in-loop.",[30,31,33],"h2",{"id":32},"_1-install","1. Install",[35,36,41],"pre",{"className":37,"code":38,"language":39,"meta":40,"style":40},"language-bash shiki shiki-themes github-light github-dark","npm install @402report\u002Fsdk @mastra\u002Fmcp\n","bash","",[21,42,43],{"__ignoreMap":40},[44,45,48,52,56,59],"span",{"class":46,"line":47},"line",1,[44,49,51],{"class":50},"sScJk","npm",[44,53,55],{"class":54},"sZZnC"," install",[44,57,58],{"class":54}," @402report\u002Fsdk",[44,60,61],{"class":54}," @mastra\u002Fmcp\n",[10,63,64,65,70,71,74],{},"Create an API key in the ",[13,66,69],{"href":67,"rel":68},"https:\u002F\u002F402.report",[17],"402.report dashboard"," and set it as\n",[21,72,73],{},"REPORT402_API_KEY",".",[30,76,78],{"id":77},"_2-add-the-mcp-tools-to-your-agent","2. Add the MCP tools to your agent",[35,80,84],{"className":81,"code":82,"language":83,"meta":40,"style":40},"language-ts shiki shiki-themes github-light github-dark","import { MCPClient } from \"@mastra\u002Fmcp\";\nimport { mastraMcpServer } from \"@402report\u002Fsdk\";\nimport { Agent } from \"@mastra\u002Fcore\u002Fagent\";\nimport { openai } from \"@ai-sdk\u002Fopenai\";\n\nconst mcp = new MCPClient({\n  servers: {\n    report402: mastraMcpServer({ apiKey: process.env.REPORT402_API_KEY! }),\n  },\n});\n\nexport const agent = new Agent({\n  name: \"spend-aware-agent\",\n  instructions:\n    \"You can inspect your own x402 payment activity with the 402.report tools — check spend \" +\n    \"and failed payments before and after paying for resources.\",\n  model: openai(\"gpt-4o\"),\n  tools: await mcp.getTools(),\n});\n","ts",[21,85,86,105,120,135,150,157,179,185,205,211,217,222,243,255,261,270,278,296,314],{"__ignoreMap":40},[44,87,88,92,96,99,102],{"class":46,"line":47},[44,89,91],{"class":90},"szBVR","import",[44,93,95],{"class":94},"sVt8B"," { MCPClient } ",[44,97,98],{"class":90},"from",[44,100,101],{"class":54}," \"@mastra\u002Fmcp\"",[44,103,104],{"class":94},";\n",[44,106,108,110,113,115,118],{"class":46,"line":107},2,[44,109,91],{"class":90},[44,111,112],{"class":94}," { mastraMcpServer } ",[44,114,98],{"class":90},[44,116,117],{"class":54}," \"@402report\u002Fsdk\"",[44,119,104],{"class":94},[44,121,123,125,128,130,133],{"class":46,"line":122},3,[44,124,91],{"class":90},[44,126,127],{"class":94}," { Agent } ",[44,129,98],{"class":90},[44,131,132],{"class":54}," \"@mastra\u002Fcore\u002Fagent\"",[44,134,104],{"class":94},[44,136,138,140,143,145,148],{"class":46,"line":137},4,[44,139,91],{"class":90},[44,141,142],{"class":94}," { openai } ",[44,144,98],{"class":90},[44,146,147],{"class":54}," \"@ai-sdk\u002Fopenai\"",[44,149,104],{"class":94},[44,151,153],{"class":46,"line":152},5,[44,154,156],{"emptyLinePlaceholder":155},true,"\n",[44,158,160,163,167,170,173,176],{"class":46,"line":159},6,[44,161,162],{"class":90},"const",[44,164,166],{"class":165},"sj4cs"," mcp",[44,168,169],{"class":90}," =",[44,171,172],{"class":90}," new",[44,174,175],{"class":50}," MCPClient",[44,177,178],{"class":94},"({\n",[44,180,182],{"class":46,"line":181},7,[44,183,184],{"class":94},"  servers: {\n",[44,186,188,191,194,197,199,202],{"class":46,"line":187},8,[44,189,190],{"class":94},"    report402: ",[44,192,193],{"class":50},"mastraMcpServer",[44,195,196],{"class":94},"({ apiKey: process.env.",[44,198,73],{"class":165},[44,200,201],{"class":90},"!",[44,203,204],{"class":94}," }),\n",[44,206,208],{"class":46,"line":207},9,[44,209,210],{"class":94},"  },\n",[44,212,214],{"class":46,"line":213},10,[44,215,216],{"class":94},"});\n",[44,218,220],{"class":46,"line":219},11,[44,221,156],{"emptyLinePlaceholder":155},[44,223,225,228,231,234,236,238,241],{"class":46,"line":224},12,[44,226,227],{"class":90},"export",[44,229,230],{"class":90}," const",[44,232,233],{"class":165}," agent",[44,235,169],{"class":90},[44,237,172],{"class":90},[44,239,240],{"class":50}," Agent",[44,242,178],{"class":94},[44,244,246,249,252],{"class":46,"line":245},13,[44,247,248],{"class":94},"  name: ",[44,250,251],{"class":54},"\"spend-aware-agent\"",[44,253,254],{"class":94},",\n",[44,256,258],{"class":46,"line":257},14,[44,259,260],{"class":94},"  instructions:\n",[44,262,264,267],{"class":46,"line":263},15,[44,265,266],{"class":54},"    \"You can inspect your own x402 payment activity with the 402.report tools — check spend \"",[44,268,269],{"class":90}," +\n",[44,271,273,276],{"class":46,"line":272},16,[44,274,275],{"class":54},"    \"and failed payments before and after paying for resources.\"",[44,277,254],{"class":94},[44,279,281,284,287,290,293],{"class":46,"line":280},17,[44,282,283],{"class":94},"  model: ",[44,285,286],{"class":50},"openai",[44,288,289],{"class":94},"(",[44,291,292],{"class":54},"\"gpt-4o\"",[44,294,295],{"class":94},"),\n",[44,297,299,302,305,308,311],{"class":46,"line":298},18,[44,300,301],{"class":94},"  tools: ",[44,303,304],{"class":90},"await",[44,306,307],{"class":94}," mcp.",[44,309,310],{"class":50},"getTools",[44,312,313],{"class":94},"(),\n",[44,315,317],{"class":46,"line":316},19,[44,318,216],{"class":94},[10,320,321,322,325,326,329,330,333],{},"Your agent now has tools like ",[21,323,324],{},"get_spend_summary",", ",[21,327,328],{},"get_spend_by_domain",", and\n",[21,331,332],{},"list_failed_payments"," — all read-only and scoped to your API key.",[30,335,337],{"id":336},"_3-optional-route-the-agents-http-through-402report","3. (Optional) Route the agent's HTTP through 402.report",[10,339,340,341,345,346,349],{},"To ",[342,343,344],"em",{},"observe"," the x402 payments your agent makes (not just query them), route its outbound HTTP\nthrough the proxy with a drop-in ",[21,347,348],{},"fetch",":",[35,351,353],{"className":81,"code":352,"language":83,"meta":40,"style":40},"import { createProxyFetch } from \"@402report\u002Fsdk\";\n\nconst fetch402 = createProxyFetch({ apiKey: process.env.REPORT402_API_KEY! });\n\u002F\u002F Pass `fetch402` to whatever your tools use to call paid APIs.\n",[21,354,355,368,372,393],{"__ignoreMap":40},[44,356,357,359,362,364,366],{"class":46,"line":47},[44,358,91],{"class":90},[44,360,361],{"class":94}," { createProxyFetch } ",[44,363,98],{"class":90},[44,365,117],{"class":54},[44,367,104],{"class":94},[44,369,370],{"class":46,"line":107},[44,371,156],{"emptyLinePlaceholder":155},[44,373,374,376,379,381,384,386,388,390],{"class":46,"line":122},[44,375,162],{"class":90},[44,377,378],{"class":165}," fetch402",[44,380,169],{"class":90},[44,382,383],{"class":50}," createProxyFetch",[44,385,196],{"class":94},[44,387,73],{"class":165},[44,389,201],{"class":90},[44,391,392],{"class":94}," });\n",[44,394,395],{"class":46,"line":137},[44,396,398],{"class":397},"sJ8bj","\u002F\u002F Pass `fetch402` to whatever your tools use to call paid APIs.\n",[10,400,401],{},"That's it — no SDK lock-in, no change to how your agent pays. 402.report is non-custodial: it\nobserves, it never holds or settles funds.",[403,404,405],"style",{},"html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}",{"title":40,"searchDepth":107,"depth":107,"links":407},[408,409,410],{"id":32,"depth":107,"text":33},{"id":77,"depth":107,"text":78},{"id":336,"depth":107,"text":337},"Give a Mastra agent its own x402 spend and forensics as MCP tools, and route its HTTP through 402.report — with one API key.","md","Mastra MCP, Mastra 402.report, x402 Mastra, agent spend Mastra, MCPClient","\u002Fmastra.svg",{},"\u002Fintegrations\u002Fmastra",{"title":5,"description":411},"integrations\u002Fmastra","y03AYJ3XzULRT9DbCSuBvTawSmNj-dqYbHMkTdIf_wo",1784841652774]