x402mcp

package
v0.10.0-rc15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

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

func Serve

func Serve(ctx context.Context, opts Options) error

Serve builds and runs the x402-paid MCP server in the foreground over streamable HTTP (endpoint /mcp). It blocks until ctx is cancelled or the server stops.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL