-
Notifications
You must be signed in to change notification settings - Fork 304
update dependencies #659
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
update dependencies #659
Changes from all commits
Commits
Show all changes
5 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "hono-agents": patch | ||
| "agents": patch | ||
| --- | ||
|
|
||
| update dependencies |
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
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 |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| "author": "Matt Carey <[email protected]>", | ||
| "dependencies": { | ||
| "@a2a-js/sdk": "^0.2.2", | ||
| "hono": "^4.10.4" | ||
| "hono": "^4.10.6" | ||
| }, | ||
| "keywords": [], | ||
| "scripts": { | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -10,6 +10,6 @@ | |
| "deploy": "wrangler deploy" | ||
| }, | ||
| "dependencies": { | ||
| "hono": "^4.10.4" | ||
| "hono": "^4.10.6" | ||
| } | ||
| } | ||
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
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
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,103 @@ | ||
| # x402 MCP Example | ||
|
|
||
| This example demonstrates how to create paid MCP tools using the [x402 payment protocol](https://x402.org) with Cloudflare Agents. | ||
|
|
||
| ## Overview | ||
|
|
||
| The example includes: | ||
|
|
||
| - **PayMCP**: An MCP server that exposes paid and free tools | ||
| - **PayAgent**: A client agent that calls these tools and handles payment confirmation flows | ||
|
|
||
| ## x402 MCP Integration | ||
|
|
||
| This implementation follows the [x402 MCP transport specification](https://github.com/coinbase/x402/blob/main/specs/transports/mcp.md#payment-payload-transmission), which defines: | ||
|
|
||
| 1. **Payment Required Signaling**: Server returns JSON-RPC error with `code: 402` and `PaymentRequirementsResponse` | ||
| 2. **Payment Payload Transmission**: Client sends payment in `_meta["x402/payment"]` | ||
| 3. **Settlement Response**: Server confirms payment in `_meta["x402/payment-response"]` | ||
|
|
||
| ### Price Discovery Extension | ||
|
|
||
| In addition to the core x402 MCP spec, this implementation includes a **Agents extension** for price discovery: | ||
|
|
||
| ```typescript | ||
| _meta: { | ||
| "agents-x402/paymentRequired": true, // Indicates tool requires payment | ||
| "agents-x402/priceUSD": 0.01 // Pre-advertises price in USD | ||
| } | ||
| ``` | ||
|
|
||
| **Note**: The `agents-x402/` namespace is used (not `x402/`) because price pre-advertising is an extension beyond the official x402 MCP specification to allow for a nice user experience. The core spec only defines the reactive payment flow (call → 402 error → retry with payment). | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Server Side: Creating Paid Tools | ||
|
|
||
| ```typescript | ||
| import { withX402 } from "agents/x402"; | ||
| import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; | ||
|
|
||
| const server = withX402(new McpServer({ name: "PayMCP", version: "1.0.0" }), { | ||
| network: "base-sepolia", | ||
| recipient: "0x...", | ||
| facilitator: { url: "https://x402.org/facilitator" } | ||
| }); | ||
|
|
||
| // Create a paid tool | ||
| server.paidTool( | ||
| "square", | ||
| "Squares a number", | ||
| 0.01, // Price in USD | ||
| { number: z.number() }, | ||
| {}, // MCP annotations (readOnlyHint, etc.) | ||
| async ({ number }) => { | ||
| return { content: [{ type: "text", text: String(number ** 2) }] }; | ||
| } | ||
| ); | ||
| ``` | ||
|
|
||
| ### Client Side: Calling Paid Tools | ||
|
|
||
| ```typescript | ||
| import { withX402Client } from "agents/x402"; | ||
| import { privateKeyToAccount } from "viem/accounts"; | ||
|
|
||
| const account = privateKeyToAccount(env.PRIVATE_KEY); | ||
|
|
||
| const x402Client = withX402Client(mcpClient, { | ||
| network: "base-sepolia", | ||
| account | ||
| }); | ||
|
|
||
| // Call tool with payment confirmation callback | ||
| const result = await x402Client.callTool( | ||
| async (requirements) => { | ||
| // Show payment prompt to user | ||
| return await userConfirmsPayment(requirements); | ||
| }, | ||
| { | ||
| name: "square", | ||
| arguments: { number: 5 } | ||
| } | ||
| ); | ||
| ``` | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| ```bash | ||
| # Server: Address to receive payments | ||
| MCP_ADDRESS=0x... | ||
|
|
||
| # Client: Private key for signing payments | ||
| CLIENT_TEST_PK=0x... | ||
| ``` | ||
|
|
||
| ## Running the Example | ||
|
|
||
| ```bash | ||
| npm install | ||
| npx wrangler dev | ||
| ``` | ||
|
|
||
| Then open http://localhost:8787 in your browser. |
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
Oops, something went wrong.
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.