-
Notifications
You must be signed in to change notification settings - Fork 129
Add partner integration guides #770
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
+290
−0
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5cf9ab9
docs: add Vercel AI SDK partner guide
parvahuja a3966c3
docs: add Cloudflare Agents partner guide
parvahuja aea9cfe
docs: use partner integration routes
parvahuja 69f09d0
docs: remove stale partner sdk redirect
parvahuja 054c3c4
docs: use addMcpServer in Cloudflare guide
parvahuja d567f42
docs: add official MCP SDK partner guide
parvahuja 5b0e895
docs: remove draft partner redirects
parvahuja dc94c19
docs: clarify MCP SDK payment-aware fetch
parvahuja f9908d7
docs: address partner integration feedback
parvahuja 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,94 @@ | ||
| --- | ||
| description: "Use MPP with the Cloudflare Agents SDK." | ||
| imageDescription: "Connect Cloudflare Agents to paid MPP MCP tools and HTTP APIs" | ||
| --- | ||
|
|
||
| # Cloudflare Agents | ||
|
|
||
| Use [`McpClient.wrap`](/sdk/typescript/client/McpClient.wrap) and [`Mppx.create`](/sdk/typescript/client/Mppx.create) to let a [Cloudflare Agent](https://developers.cloudflare.com/agents/) pay for MCP tools and HTTP requests through MPP. Free calls pass through untouched; when a paid tool or a 402-protected request returns an MPP Challenge, the wrapped client creates a Credential, retries the call, and returns the result. | ||
|
|
||
| ```bash [terminal] | ||
| $ pnpm add agents mppx viem | ||
| ``` | ||
|
|
||
| ```ts [payments.ts] | ||
| import { privateKeyToAccount } from 'viem/accounts' | ||
|
|
||
| export const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`) | ||
| ``` | ||
|
|
||
| :::info | ||
| The example uses an environment private key for brevity. For production agents, manage spend with scoped access keys instead of giving the runtime a private key. See [Managing agent spend](/guides/managing-agent-spend). | ||
| ::: | ||
|
|
||
| ## Pay for MCP tools | ||
|
|
||
| Add the MCP server, then wrap the client stored on the Cloudflare MCP connection. Calls through the wrapped client are payment-aware. | ||
|
|
||
| ```ts [agent.ts] | ||
| import { Agent } from 'agents' | ||
| import { tempo } from 'mppx/client' | ||
| import { McpClient } from 'mppx/mcp/client' | ||
| import { account } from './payments' | ||
|
|
||
| export class MyAgent extends Agent { | ||
| async onStart() { | ||
| const { id } = await this.addMcpServer('premium-search', '<mcp-url>') | ||
| const client = McpClient.wrap(this.mcp.mcpConnections[id].client, { | ||
| methods: [tempo({ account })], | ||
| }) | ||
|
|
||
| const result = await client.callTool({ | ||
| name: 'premium_search', | ||
| arguments: { query: 'tempo' }, | ||
| }) | ||
|
|
||
| console.log(result) | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| `McpClient.wrap` keeps the Cloudflare MCP connection shape intact. The agent can keep using the same client APIs. | ||
|
|
||
| ## Pay for HTTP requests | ||
|
|
||
| Call `Mppx.create` before the agent makes HTTP requests. It installs the payment-aware fetch, so later `fetch` calls in the same runtime can handle free responses, paid MPP responses, and [x402 payment challenges](/guides/use-mpp-with-x402). | ||
|
|
||
| ```ts [agent.ts] | ||
| import { Mppx, tempo } from 'mppx/client' | ||
| import { account } from './payments' | ||
|
|
||
| Mppx.create({ | ||
| methods: [tempo({ account })], | ||
| }) | ||
|
|
||
| export async function paidPing() { | ||
| const response = await fetch('https://mpp.dev/api/ping/paid') | ||
| return response.json() | ||
| } | ||
| ``` | ||
|
|
||
| ## Manage agent spend | ||
|
|
||
| The examples above use a standard viem account. For long-running apps or agents, use scoped access keys when the runtime should pay in the background with spending limits, call scopes, recipient restrictions, and independent revocation. | ||
|
parvahuja marked this conversation as resolved.
|
||
|
|
||
| Create the access key first, then pass the Tempo account into the same setup. | ||
|
|
||
| ```ts [agent.ts] | ||
| const method = tempo({ | ||
| account: provider.getAccount(), | ||
| ...provider.getMppxParameters({ accessKey }), | ||
| }) | ||
|
|
||
| // Use the method for paid MCP tool calls. | ||
| McpClient.wrap(this.mcp.mcpConnections[id].client, { | ||
| methods: [method], | ||
| }) | ||
|
|
||
| // Use the same method for payment-aware fetch calls. | ||
| Mppx.create({ | ||
| methods: [method], | ||
| }) | ||
| ``` | ||
|
|
||
| See [Managing agent spend](/guides/managing-agent-spend) for limits, scopes, recipients, and revocation. | ||
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,78 @@ | ||
| --- | ||
| description: "Use MPP with the official TypeScript MCP SDK." | ||
| --- | ||
|
|
||
| # Official MCP SDK | ||
|
|
||
| Use [`Mppx.create`](/sdk/typescript/client/Mppx.create) to let the [official TypeScript MCP SDK](https://github.com/modelcontextprotocol/typescript-sdk) pay for MCP tools and HTTP requests through MPP. Free calls pass through untouched; when a paid tool or a 402-protected request returns an MPP Challenge, the payment-aware fetch wrapper creates a Credential, retries the call, and returns the result. | ||
|
|
||
| ```bash [terminal] | ||
| $ pnpm add mppx viem @modelcontextprotocol/sdk | ||
| ``` | ||
|
|
||
| ```ts [payments.ts] | ||
| import { Mppx, tempo } from 'mppx/client' | ||
| import { privateKeyToAccount } from 'viem/accounts' | ||
|
|
||
| const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`) | ||
|
|
||
| Mppx.create({ | ||
| methods: [tempo({ account })], | ||
| }) | ||
| ``` | ||
|
|
||
| ## Pay for MCP tools | ||
|
|
||
| Create the MCP client after `Mppx.create`. The Streamable HTTP transport uses the payment-aware fetch for both free and paid tool calls. | ||
|
|
||
| ```ts [client.ts] | ||
| import { Client } from '@modelcontextprotocol/sdk/client/index.js' | ||
| import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js' | ||
| import './payments' | ||
|
|
||
| const client = new Client({ | ||
| name: 'mpp-app', | ||
| version: '1.0.0', | ||
| }) | ||
|
|
||
| await client.connect(new StreamableHTTPClientTransport(new URL('<mcp-url>'))) | ||
|
|
||
| const result = await client.callTool({ | ||
| name: 'premium_search', | ||
| arguments: { query: 'tempo' }, | ||
| }) | ||
|
|
||
| console.log(result) | ||
| ``` | ||
|
|
||
| ## Pay for HTTP requests | ||
|
|
||
| Call `Mppx.create` before making HTTP requests. It installs the payment-aware fetch, so later `fetch` calls in the same runtime can handle free responses, paid MPP responses, and [x402 payment challenges](/guides/use-mpp-with-x402). | ||
|
|
||
| ```ts [client.ts] | ||
| import './payments' | ||
|
|
||
| export async function paidPing() { | ||
| const response = await fetch('https://mpp.dev/api/ping/paid') | ||
| return response.json() | ||
| } | ||
| ``` | ||
|
|
||
| ## Manage agent spend | ||
|
|
||
| The example above uses a standard viem account. For long-running apps or agents, use scoped access keys when the runtime should pay in the background with spending limits, call scopes, recipient restrictions, and independent revocation. | ||
|
|
||
| Create the access key first, then pass the Tempo account into the same setup. | ||
|
|
||
| ```ts [payments.ts] | ||
| Mppx.create({ | ||
| methods: [ | ||
| tempo({ | ||
| account: provider.getAccount(), | ||
| ...provider.getMppxParameters({ accessKey }), | ||
| }), | ||
| ], | ||
| }) | ||
| ``` | ||
|
|
||
| See [Managing agent spend](/guides/managing-agent-spend) for limits, scopes, recipients, and revocation. |
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,98 @@ | ||
| --- | ||
| description: "Use MPP with the Vercel AI SDK." | ||
| --- | ||
|
|
||
| # Vercel AI SDK | ||
|
|
||
| Use [`Mppx.create`](/sdk/typescript/client/Mppx.create) to let a [Vercel AI SDK agent](https://ai-sdk.dev/docs/agents/overview) pay for MCP tools and HTTP requests through MPP. Free calls pass through untouched; when a paid tool or a 402-protected request returns an MPP Challenge, the wrapped client creates a Credential, retries the call, and returns the result. | ||
|
|
||
| ```bash [terminal] | ||
| $ pnpm add mppx viem ai @ai-sdk/mcp zod | ||
| ``` | ||
|
|
||
| ```ts [payments.ts] | ||
| import { Mppx, tempo } from 'mppx/client' | ||
| import { privateKeyToAccount } from 'viem/accounts' | ||
|
|
||
| const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`) | ||
|
|
||
| Mppx.create({ | ||
| methods: [tempo({ account })], | ||
| }) | ||
| ``` | ||
|
|
||
| ## Pay for MCP tools | ||
|
|
||
| Create the MCP client after `Mppx.create`. The AI SDK MCP transport uses the payment-aware fetch for both free and paid tool calls. | ||
|
|
||
| ```ts [agent.ts] | ||
| import { createMCPClient } from '@ai-sdk/mcp' | ||
| import { generateText } from 'ai' | ||
| import { yourProvider } from 'your-custom-provider' | ||
|
|
||
| const mcp = await createMCPClient({ | ||
| transport: { | ||
| type: 'http', | ||
| url: '<mcp-url>', | ||
| }, | ||
| }) | ||
|
|
||
| const { toolResults } = await generateText({ | ||
| model: yourProvider('your-model-id'), | ||
| prompt: 'Call the MCP tool.', | ||
| tools: await mcp.tools(), | ||
| toolChoice: 'required', | ||
| }) | ||
|
|
||
| console.log(toolResults) | ||
| await mcp.close() | ||
| ``` | ||
|
|
||
| ## Pay for HTTP requests | ||
|
|
||
| Define a normal AI SDK tool and call `fetch` inside `execute`. Because `Mppx.create` ran first, the HTTP request is payment-aware. | ||
|
|
||
| ```ts [agent.ts] | ||
| import { generateText, tool } from 'ai' | ||
| import { yourProvider } from 'your-custom-provider' | ||
| import { z } from 'zod' | ||
|
|
||
| const { toolResults } = await generateText({ | ||
| model: yourProvider('your-model-id'), | ||
| prompt: 'Call paidPing.', | ||
| tools: { | ||
| paidPing: tool({ | ||
| description: 'Call a paid MPP HTTP endpoint.', | ||
| inputSchema: z.object({}), | ||
| execute: async () => { | ||
| const response = await fetch('https://mpp.dev/api/ping/paid') | ||
| return response.json() | ||
| }, | ||
| }), | ||
| }, | ||
| toolChoice: { type: 'tool', toolName: 'paidPing' }, | ||
| }) | ||
|
|
||
| console.log(toolResults) | ||
| ``` | ||
|
|
||
| The `tempo({ account })` helper used above supports Tempo [charge](/payment-methods/tempo/charge) and [session](/payment-methods/tempo/session) challenges. | ||
|
|
||
| ## Manage agent spend | ||
|
|
||
| The example above uses a standard viem account. For long-running apps or agents, use scoped access keys when the runtime should pay in the background with spending limits, call scopes, recipient restrictions, and independent revocation. | ||
|
|
||
| Create the access key first, then pass the Tempo account into the same setup. | ||
|
|
||
| ```ts [payments.ts] | ||
| Mppx.create({ | ||
| methods: [ | ||
| tempo({ | ||
| account: provider.getAccount(), | ||
| ...provider.getMppxParameters({ accessKey }), | ||
| }), | ||
| ], | ||
| }) | ||
| ``` | ||
|
|
||
| See [Managing agent spend](/guides/managing-agent-spend) for limits, scopes, recipients, and revocation. |
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
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.
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.
what is this local import? can we just inline this?
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.
it makes a little more sense in the rendered guide - but the "account" is created once on line 17 and then used on line 38 and 62 - so would have to inline in two places wdyt.
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.
lmk what you think this is the only comment i didnt address