Skip to main content
Glama
AGICoffe

solana-402-agent-wallet

README.md

# ⚡ Solana USDC 402 Merchant Gate & MCP Server for AI Agents

An open-source, zero-dependency **Model Context Protocol (MCP)** server and HTTP 402 payment gateway built for Cloudflare Workers and Node.js.

This project enables AI agents (Claude Desktop, Cursor, etc.) to natively discover, negotiate, and autonomously pay for digital resources over Solana USDC using standardized MCP tools and standard `HTTP 402 Payment Required` headers.

---

## 🤖 Model Context Protocol (MCP) Integration

This repository natively implements the official `@modelcontextprotocol/sdk` to expose agentic payment verification capabilities as standard MCP Tools.

### Exposed MCP Tools

1. **`check_payment_requirement`**
   * **Description**: Queries the merchant endpoint to fetch required payment metadata (Price in USDC, Recipient Wallet Address, and Token Mint ID).
   * **Input Schema**: None.
   * **Returns**: Standardized HTTP 402 payment requirements for LLM evaluation.

2. **`verify_and_fetch_product`**
   * **Description**: Submits a Solana transaction signature (`X-SOLANA-TX`) to verify on-chain USDC transfer and retrieve the protected payload.
   * **Input Schema**:
     * `txSignature` (`string`, **required**): The Solana transaction signature proving 0.01 USDC transfer to the recipient wallet.
   * **Returns**: Protected digital asset or API payload upon successful verification.

---

## 💻 MCP Server Implementation Code

This MCP Server connects via `StdioServerTransport` using `@modelcontextprotocol/sdk`:

```javascript
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";

const server = new Server(
  { name: "solana-402-merchant-server", version: "1.0.0" },
  { capabilities: { tools: {} } }
);

// Register MCP Tools
server.setRequestHandler(ListToolsRequestSchema, async () => {
  return {
    tools: [
      {
        name: "check_payment_requirement",
        description: "Returns price, recipient wallet, and token details required to unlock this product.",
        inputSchema: { type: "object", properties: {} }
      },
      {
        name: "verify_and_fetch_product",
        description: "Verifies a Solana transaction signature and unlocks the paid content.",
        inputSchema: {
          type: "object",
          properties: {
            txSignature: { type: "string", description: "Solana transaction signature" }
          },
          required: ["txSignature"]
        }
      }
    ]
  };
});

// Handle Tool Requests
server.setRequestHandler(CallToolRequestSchema, async (request) => {
  const { name, arguments: args } = request.params;

  if (name === "check_payment_requirement") {
    return {
      content: [{
        type: "text",
        text: JSON.stringify({
          status: 402,
          price: "0.01 USDC",
          recipient: process.env.RECIPIENT_WALLET || "YOUR_SOLANA_WALLET_ADDRESS",
          tokenMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
          instructions: "Send 0.01 USDC on Solana and submit the signature via verify_and_fetch_product."
        }, null, 2)
      }]
    };
  }

  if (name === "verify_and_fetch_product") {
    const { txSignature } = args;
    // On-chain verification logic via Helius RPC...
    return {
      content: [{
        type: "text",
        text: JSON.stringify({
          success: true,
          tx: txSignature,
          data: "PROTECTED_DIGITAL_CONTENT"
        }, null, 2)
      }]
    };
  }

  throw new Error(`Tool not found: ${name}`);
});

async function main() {
  const transport = new StdioServerTransport();
  await server.connect(transport);
}

main().catch(console.error);

📋 Prerequisites & Requirements

To run this MCP server, ensure you have:

  • Node.js: v18.0.0 or higher.

  • Solana Wallet: A self-custody wallet address (RECIPIENT_WALLET) to collect USDC payments.

  • Helius RPC API Key: Free API key from Helius (HELIUS_API_KEY) for on-chain transaction validation.

  • Cloudflare Workers & KV (Optional for HTTP Deployment): A Cloudflare KV namespace named USED_TX to store used transaction hashes and prevent double-spending replay attacks.


Related MCP server: @true402.dev/mcp-server

⚙️ How to Setup and Run

1. Installation

git clone [https://github.com/YOUR_USERNAME/solana-402-mcp-merchant.git](https://github.com/YOUR_USERNAME/solana-402-mcp-merchant.git)
cd solana-402-mcp-merchant
npm install
npm run build

2. Claude Desktop Integration (claude_desktop_config.json)

To use this server inside Claude Desktop or Cursor, add the following to your config file:

{
  "mcpServers": {
    "solana-402-merchant": {
      "command": "node",
      "args": [
        "/path/to/solana-402-mcp-merchant/build/index.js"
      ],
      "env": {
        "RECIPIENT_WALLET": "YOUR_SOLANA_WALLET_ADDRESS",
        "HELIUS_API_KEY": "YOUR_HELIUS_API_KEY"
      }
    }
  }
}

📄 License

MIT License - Open source and free for commercial and personal use.

A
license - permissive license
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Related MCP Servers

View all related MCP servers

Related MCP Connectors

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/AGICoffe/solana-402-agent-wallet'

If you have feedback or need assistance with the MCP directory API, please join our Discord server