Overview

Code examples for integrating ClawFirst MCP server with autonomous AI agents across multiple frameworks.

Quick Start

OpenClaw Python Integration

The fastest way to enable autonomous payments for your AI agent:

from openclaw import Agent
from clawfirst import X402Provider

# Configure agent with payment capabilities
agent = Agent(
    name="payment_assistant",
    providers=[
        X402Provider(
            network="mainnet-beta",
            wallet_path="~/.config/solana/agent.json",
            approval_policy={
                "auto_approve_threshold": "100 USDC",
                "daily_limit": "1000 USDC"
            }
        )
    ]
)

# Agent autonomously executes payments
result = agent.run("Pay the $250 invoice from Acme Corp using USDC")
print(f"Payment completed: {result.tx_signature}")

Standalone MCP Server

Run ClawFirst as a framework-agnostic MCP server:

Language-Specific Examples

Complete OpenClaw integration examples including:

  • Autonomous invoice settlement

  • Treasury management agents

  • Subscription payment handling

  • Error handling and retry logic

LangChain and custom MCP client examples:

  • Agent payment workflows

  • React-based approval dashboards

  • Real-time transaction monitoring

  • Production deployment patterns

High-performance agent implementations:

  • Async/await payment flows

  • Concurrent transaction processing

  • Low-latency MCP client

  • Production monitoring

Common Integration Patterns

Pattern 1: Autonomous Invoice Processing

Pattern 2: Treasury Management

Pattern 3: Subscription Management

Pattern 4: Multi-Agent Coordination

Advanced Examples

Session-Based Transaction Management

Real-Time Transaction Monitoring

Approval Workflow Integration

Testing Examples

Development Environment Setup

Integration Tests

Best Practices

1. Start on Devnet

Always test agent behavior on Solana devnet before mainnet deployment.

2. Implement Approval Policies

Never allow unrestricted autonomous spending. Configure multi-tier approval workflows.

3. Monitor Transaction Patterns

Set up alerting for anomalous agent behavior (velocity spikes, unusual amounts).

4. Use Idempotency Keys

Prevent duplicate payments with stable idempotency keys based on payment intent.

5. Enable Audit Logging

Maintain immutable audit trails for compliance and forensic analysis.

6. Test Failure Scenarios

Verify agent behavior during network failures, RPC timeouts, and policy violations.

7. Implement Circuit Breakers

Automatically suspend agents exhibiting suspicious transaction patterns.

8. Use HSM in Production

Never store production keys in file systems. Use hardware security modules.

Next Steps

Pick your language and explore detailed examples:

Additional Resources

Last updated