-
Notifications
You must be signed in to change notification settings - Fork 13
Add MPP integration page #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| --- | ||
| title: MPP | ||
| subtitle: Pay-per-use AgentMail with Stripe's Machine Payments Protocol | ||
| slug: integrations/mpp | ||
| description: AgentMail's MPP integration for machine-to-machine payments via Stripe | ||
| --- | ||
|
|
||
| ## Getting started | ||
|
|
||
| [MPP (Machine Payments Protocol)](https://mpp.dev) is Stripe's open protocol that enables machine-to-machine payments. By integrating MPP with AgentMail, your agents can pay for API usage directly without managing API keys or subscriptions. | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - A crypto wallet with funds (EVM-compatible wallet) | ||
| - Node.js installed | ||
|
|
||
| ### Install dependencies | ||
|
|
||
| ```bash | ||
| npm install agentmail mppx viem | ||
| ``` | ||
|
|
||
| ### Quickstart | ||
|
|
||
| ```typescript | ||
| import { privateKeyToAccount } from "viem/accounts"; | ||
| import { Mppx, tempo } from "mppx/client"; | ||
|
|
||
| import { AgentMailClient } from "agentmail"; | ||
|
|
||
|
|
||
| // setup MPP client | ||
|
|
||
| const PRIVATE_KEY = "0x..."; | ||
|
|
||
| const account = privateKeyToAccount(PRIVATE_KEY); | ||
|
|
||
| export const mppx = Mppx.create({ methods: [tempo({ account })] }); | ||
|
|
||
|
|
||
| // setup AgentMail client | ||
|
|
||
| export const client = new AgentMailClient({ mppx }); | ||
|
|
||
|
|
||
| // create inbox | ||
|
|
||
| const inboxRes = await client.inboxes.create({ | ||
| username: `mpp-${Date.now()}`, | ||
| }); | ||
| console.log("Created inbox: ", inboxRes.inboxId); | ||
|
|
||
|
|
||
| // subscribe to inbox | ||
|
|
||
| const socket = await client.websockets.connect(); | ||
| console.log("Connected to websocket"); | ||
|
|
||
| socket.on("message", async (event) => { | ||
| if (event.type === "subscribed") { | ||
| console.log("Subscribed to", event.inboxIds); | ||
| } else if (event.type === "event" && event.eventType === "message.received") { | ||
| console.log("Received message from: ", event.message.from); | ||
| } | ||
| }); | ||
|
|
||
| socket.sendSubscribe({ | ||
| type: "subscribe", | ||
| inboxIds: [inboxRes.inboxId], | ||
| }); | ||
| ``` | ||
|
|
||
| ## How it works | ||
|
|
||
| When you pass an `mppx` client to `AgentMailClient`, the SDK automatically handles payment negotiation for each API request. The MPP client signs payments using your wallet, enabling your agent to pay per request seamlessly. | ||
|
|
||
| This means your agent can use the full AgentMail API (inboxes, messages, threads, attachments) without needing a traditional API key. Payment happens per-request via Stripe's Machine Payments Protocol. | ||
|
|
||
| ## Resources | ||
|
|
||
| - [MPP documentation](https://mpp.dev) | ||
| - [AgentMail API reference](/api-reference) | ||
| - [WebSockets overview](/websockets) | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Disable MPP's default global fetch polyfill here.
AgentMailClient({ mppx })already consumesmppx.fetch, so leaving the default on adds an unnecessary process-wide side effect for unrelated requests.Prompt for AI agents