x402 Stellar MCP Server

x402 Stellar MCP Server

Enables AI agents to pay for protected HTTP resources using Stellar USDC via the x402 protocol, facilitating automated payments and access to paid APIs.

Category
访问服务器

README

x402 Stellar MCP Server

Local MCP server (stdio) that can call x402-protected HTTP resources and automatically pay in Stellar USDC.

Features

  • Payment flow (stellar:testnet or stellar:pubnet)
  • Default testnet configuration
  • Mainnet-ready via env switch
  • Optional OpenZeppelin facilitator auth via env
  • No resource whitelist: URL is provided at tool call time

Tools Exposed

  • x402_wallet_info: shows active wallet address/network/config
  • x402_facilitator_supported: checks configured facilitator /supported endpoint
  • fetch_paid_resource: generic paid fetch (url, method, optional body/headers)

Prerequisites

  • Node.js 20+
  • A Stellar wallet funded with testnet XLM + testnet USDC
  • x402 resource server running (your app/index.js demo)
  • x402 facilitator running on http://localhost:4022

Setup

npm install
cp .env.example .env

Testnet

For testnet you'll need to run a facilitator locally on port 4022. I'd recommend using the one included in the coinbase x402 repo: https://github.com/coinbase/x402/tree/main/examples/typescript/facilitator/advanced

Update .env with your wallet key:

STELLAR_SECRET_KEY=S...
STELLAR_NETWORK=stellar:testnet

Pubnet

For mainnet you'll just need an OpenZeppelin API Key for the relayer. You can get one here (Thank you for making this easy): https://channels.openzeppelin.com/gen

STELLAR_NETWORK=stellar:pubnet
STELLAR_RPC_URL=https://rpc.lightsail.network/
X402_FACILITATOR_URL=https://channels.openzeppelin.com/x402
X402_FACILITATOR_API_KEY=<your-openzeppelin-api-key>

X402_FACILITATOR_API_KEY is optional in general, but required for OpenZeppelin channels. When set, fetch_paid_resource auto-adds Authorization: Bearer <key> for requests under X402_FACILITATOR_URL (unless you provide Authorization explicitly).

Run

npm run dev

The MCP server runs over stdio for Claude/Codex integrations.

TTS Proxy

The paid /api/tts route can use either elevenlabs or smallest. Set a default provider in .env, and optionally override it per request by sending "provider": "elevenlabs" or "provider": "smallest" in the JSON body. You can also send "provider": "auto" with a routing "priority" of "cheap", "fast", or "quality" to let the server pick a provider dynamically.

To run the real x402-protected TTS proxy, configure:

STELLAR_NETWORK=stellar:testnet
X402_FACILITATOR_URL=http://localhost:4022
TTS_PROVIDER=elevenlabs
ELEVENLABS_API_KEY=<your-elevenlabs-api-key>
ELEVENLABS_MODEL_ID=eleven_flash_v2_5
ELEVENLABS_VOICE_ID=21m00Tcm4TlvDq8ikWAM
ELEVENLABS_ESTIMATED_PRICE_USD=0.06
ELEVENLABS_ESTIMATED_LATENCY_MS=900
ELEVENLABS_QUALITY_SCORE=9.5
SMALLEST_API_KEY=<your-smallest-api-key>
SMALLEST_MODEL=lightning
SMALLEST_VOICE_ID=emily
SMALLEST_LANGUAGE=en
SMALLEST_ESTIMATED_PRICE_USD=0.03
SMALLEST_ESTIMATED_LATENCY_MS=500
SMALLEST_QUALITY_SCORE=8.3
ALLOW_SYSTEM_PROXY=false
PAY_TO_ADDRESS=<your-stellar-receiving-address>

For pubnet, also set:

STELLAR_NETWORK=stellar:pubnet
STELLAR_RPC_URL=https://rpc.lightsail.network/
X402_FACILITATOR_URL=https://channels.openzeppelin.com/x402
X402_FACILITATOR_API_KEY=<your-openzeppelin-api-key>

Then start the proxy with:

npm run start:elevenlabs

The protected route is:

POST http://localhost:3000/api/tts

Example request for automatic routing:

{
  "text": "Hello from the voice marketplace",
  "provider": "auto",
  "priority": "cheap",
  "language": "en"
}

The response includes marketplace metadata headers like:

X-TTS-Provider
X-TTS-Priority
X-TTS-Reason
X-TTS-Estimated-Price-Usd
X-TTS-Estimated-Latency-Ms
X-TTS-Quality-Score

This server now requires a real facilitator and will not fall back to a mock implementation. By default it also ignores HTTP_PROXY / HTTPS_PROXY / ALL_PROXY so upstream TTS requests go direct during local testing. Set ALLOW_SYSTEM_PROXY=true if you intentionally want to use a proxy.

Add To Claude / Codex

Use an MCP entry like (don't forget to change the path/):

Codex

codex mcp add x402-stellar -- npm --silent --prefix /absolute/path/to/x402-mcp-stellar run dev

Claude Code

claude mcp add x402-stellar -- npm --silent --prefix /absolute/path/to/x402-mcp-stellar run dev

Claude Desktop (untested)

{
  "mcpServers": {
    "x402-stellar": {
      "command": "npm",
      "args": ["--silent", "--prefix", "/absolute/path/to/x402-mcp-stellar", "run", "dev"]
    }
  }
}

This server loads .env from the project directory (/absolute/path/to/x402-mcp-stellar/.env).

Claude Usage

After loading the MCP server, you can ask:

Can you fetch the resource at http://localhost:3000/my-service, use the x402-stellar MCP server to pay for it, and print the response?

The tool call will pass that full URL at runtime; no URL allowlist or hardcoded endpoint is required in this MCP server.

Notes

  • @x402/stellar is not currently published on npm, so this repo vendors the Stellar mechanism under src/stellar.
  • Default testnet Soroban RPC is used automatically.
  • Mainnet requires STELLAR_RPC_URL.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选