Skip to content

feat: Add MCP example and enhance A2A example with Smart Account support#23

Merged
pcarranzav merged 19 commits intomainfrom
feat/example-migration
Dec 10, 2025
Merged

feat: Add MCP example and enhance A2A example with Smart Account support#23
pcarranzav merged 19 commits intomainfrom
feat/example-migration

Conversation

@pcarranzav
Copy link
Member

@pcarranzav pcarranzav commented Dec 6, 2025

Summary

Add MCP buyer example and enhance existing A2A buyer example with production-ready patterns and comprehensive documentation.

Builds on: #22 (X402RemoteAgentToolset)
Chain: This PR targets feat/x402-local-agent-toolset branch (will rebase to main after #22 merges)

What's Included

New: MCP Buyer Example

Location: examples/src/examples/mcp/buyer/adk/

Example demonstrating MCP protocol integration with x402 payments via ampersend-proxy.

  • Uses McpToolset to connect through proxy
  • Defaults to staging MCP service (testnet)
  • Full inline documentation with setup instructions

Enhanced: A2A Buyer Example

Location: examples/src/examples/a2a/buyer/adk/

Enhanced with production-ready patterns:

  • ✅ Smart Account + EOA auto-detection
  • ✅ AmpersendTreasurer vs NaiveTreasurer mode selection
  • ✅ Defaults to staging A2A service (testnet)
  • ✅ Comprehensive inline documentation

Documentation

MCP Proxy Guide

Location: examples/docs/running-mcp-proxy.md

Complete guide for running the MCP x402 proxy:

  • Installation instructions (npm, pnpm, from source)
  • Smart Account + EOA configuration
  • Architecture diagram
  • Troubleshooting guide

Updated Python README

Location: python/README.md

Comprehensive update with Ampersend-first approach:

  • "Getting Started" section promoting Smart Account + Ampersend
  • "Standalone Alternative" for testing without account
  • Complete examples section (A2A, MCP, Seller)
  • Production upgrade path
  • Circle USDC faucet link

Documentation Approach

All examples follow consistent pattern:

  1. Getting Started (Testnet) - Smart Account + Ampersend (shown first)
  2. Production - Upgrade to mainnet
  3. Standalone Alternative - EOA + Naive (testing only)

Staging Defaults

All examples default to staging (free testnet):

  • Dashboard: https://app.staging.ampersend.ai
  • API: https://api.staging.ampersend.ai
  • A2A: https://subgraph-a2a.x402.staging.thegraph.com
  • MCP: https://subgraph-mcp.x402.staging.ampersend.ai

With clear notes that staging is rate-limited, and production endpoints documented.

Testing

  • ✅ Type checking: All examples pass mypy strict mode
  • ✅ Linting: All examples pass ruff
  • ✅ Markdown formatting: Passes prettier
  • ✅ Uses default validator address from SmartAccountConfig

🤖 Generated with Claude Code

@pcarranzav pcarranzav force-pushed the feat/example-migration branch from f731092 to c29fda3 Compare December 8, 2025 16:41
@pcarranzav pcarranzav changed the title feat: Migrate examples with Smart Account support and staging defaults feat: Add MCP example and enhance A2A example with Smart Account support Dec 8, 2025
@pcarranzav pcarranzav marked this pull request as ready for review December 8, 2025 17:15
Copy link

@benface benface left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

pcarranzav and others added 12 commits December 9, 2025 12:33
…ng defaults

Migrate and enhance buyer examples with production-ready patterns:

- Add MCP buyer example using McpToolset via ampersend-proxy
- Update A2A buyer example with Smart Account + EOA auto-detection
- Add AmpersendTreasurer vs NaiveTreasurer mode selection
- Default to staging endpoints (testnet, free)
- Add comprehensive inline documentation

Documentation improvements:
- Create running-mcp-proxy.md guide with installation and setup
- Update python/README.md with Getting Started (Ampersend-first)
- Document Standalone Alternative for testing
- Link to Circle USDC faucet for testnet funding
- Show production upgrade path

All examples follow Ampersend-first pattern:
- Primary: Smart Account + AmpersendTreasurer (with spend limits)
- Alternative: EOA + NaiveTreasurer (standalone testing)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
SmartAccountConfig has OWNABLE_VALIDATOR as default, so validator_address
parameter is not needed in examples and documentation.
- Mention AmpersendTreasurer as recommended option with spend limits
- Clarify NaiveTreasurer is for testing only
- Note SmartAccountWallet supports ERC-7579 OwnableValidator from Rhinestone
Clarify that users need to create an account at app.ampersend.ai
before switching to production endpoints.
Include steps to create agent account, fund it, and update
Smart Account credentials along with API and service endpoints.
SmartAccountConfig uses OWNABLE_VALIDATOR as default, so the
validator_address env var is not needed.
Remove non-null assertion on BUYER_SMART_ACCOUNT_VALIDATOR_ADDRESS
since the env schema provides OWNABLE_VALIDATOR as default.

Also remove from documentation as it's not required to be set.
Note that app.staging.ampersend.ai is for testnet and
app.ampersend.ai is for production/mainnet.
Clarify that users can replace The Graph subgraph service URLs
with any other MCP-x402 or A2A-x402 compatible service.
@pcarranzav pcarranzav force-pushed the feat/example-migration branch from b2b790f to 611ddd8 Compare December 9, 2025 15:33
Add AmpersendTreasurer as the default treasurer for MCP proxy when
AMPERSEND_API_URL is provided, with NaiveTreasurer as fallback.

Changes:
- Import createAmpersendTreasurer in cli.ts
- Select treasurer based on AMPERSEND_API_URL presence
- Export AmpersendTreasurer from ampersend/index.ts
- Add AMPERSEND_API_URL to env schema
- Update logging to show treasurer type

Documentation updates:
- Explain TS__MCP_PROXY__ env prefix used by pnpm proxy:dev
- Document --env-prefix flag to disable prefix
- Show both prefixed and non-prefixed examples
- Promote Smart Account + Ampersend as recommended
- Document EOA + Naive as standalone alternative

The proxy now follows the same Ampersend-first pattern as the
A2A examples with spend limits and monitoring by default.
Update MCP proxy README and MCP buyer example to document:
- Environment variable prefix (TS__MCP_PROXY__ for pnpm proxy:dev)
- AmpersendTreasurer as recommended (with AMPERSEND_API_URL)
- NaiveTreasurer as standalone alternative
- Correct proxy startup commands with prefix
Parse AMPERSEND_API_URL with the env prefix so it's correctly
read when using --env-prefix flag.
Use CustomMcpError from FastMCP fork to solve instanceof failures
across module boundaries when using tsx or different bundlers.

Changes:
- Import CustomMcpError instead of McpError in middleware
- Update fastmcp dependency to github:edgeandnode/fastmcp#598d18f
- Fix bridge to process ALL responses through middleware (not just errors)
- This allows payment response detection in successful results
- Enables onStatus('accepted') to be called properly

Fixes payment status reporting so payments appear as 'Accepted' in
dashboard instead of staying 'Pending'.
Base automatically changed from feat/x402-local-agent-toolset to main December 10, 2025 17:43
@pcarranzav pcarranzav merged commit a768e5e into main Dec 10, 2025
6 checks passed
@pcarranzav pcarranzav deleted the feat/example-migration branch December 10, 2025 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants