Documentation
¶
Overview ¶
Package x402mcp serves a local x402-paid MCP (Model Context Protocol) server.
It wraps MCP tools with x402 payment using x402-foundation/x402/go/mcp and the official modelcontextprotocol/go-sdk, gated by an x402 facilitator. Buyers (e.g. hermes-agent's pay_mcp plugin) settle in-band via the MCP request _meta["x402/payment"] field, per specs/transports-v2/mcp.md. Verify -> execute -> settle happens inside the tool call, so a caller is never charged for a failed tool. This is the application-layer (in-band) counterpart to the HTTP ForwardAuth gate in internal/x402.
The paid tool proxies the buyer's JSON arguments to a backend HTTP service and returns the response, so any real service — e.g. a paid weather/data API — can be resold to agents per call. This mirrors the canonical x402 paid-MCP example (a paid get_weather tool), with the upstream generalised from a stub to a real backend. The backend's own auth (if any) is configured server-side and is never exposed to buyers. (Inference is just one possible upstream, not the point.)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Options ¶
type Options struct {
Name string // server display name
ToolName string // paid tool name (default "call")
Description string // human-readable tool description (document the arg shape here)
Port int // HTTP port (default 4022)
PayTo string // payment recipient address (required)
Price string // per-call price, USD-denominated (e.g. "0.001"); a "$" is added if absent
Chain string // base | base-sepolia | ethereum | polygon
FacilitatorURL string // x402 facilitator (verify/settle); caller supplies a default
Upstream string // backend HTTP service the paid tool POSTs the buyer's JSON args to (e.g. a weather/data API)
UpstreamHeaders map[string]string // optional auth headers for the backend (e.g. "X-Api-Key": "<key>"); set server-side, never exposed to buyers
}
Options configures an x402-paid MCP server.