Documentation
¶
Overview ¶
Package client pays for MCP tool calls made with the official MCP Go SDK (github.com/modelcontextprotocol/go-sdk), matching mppx's McpClient.wrap.
Wrap installs sending middleware on an *mcp.Client, so every session it connects, and every CallTool on them, handles payment challenges whether they arrive as payment-required JSON-RPC errors (-32042 or -32043) or as tool results carrying _meta["org.paymentauth/payment-required"]. The client pays with a configured method and retries the call with the Credential in _meta["org.paymentauth/credential"]; Receipt reads the receipt from the result:
c := mcp.NewClient(&mcp.Implementation{Name: "my-client", Version: "1.0.0"}, nil)
mcpclient.Wrap(c, mcpclient.Config{Methods: []client.Method{method}})
session, err := c.Connect(ctx, transport, nil)
...
result, err := session.CallTool(ctx, &mcp.CallToolParams{Name: "premium_tool"})
receipt, err := mcpclient.Receipt(result)
Index ¶
- Variables
- func IsPaymentRequiredError(err error) bool
- func Receipt(result *mcp.CallToolResult) (*mpp.MCPReceipt, error)
- func WithOnPaymentRequired(ctx context.Context, fn OnPaymentRequired) context.Context
- func Wrap(c *mcp.Client, config Config) *mcp.Client
- type Config
- type OnPaymentRequired
- type OrderChallenges
Constants ¶
This section is empty.
Variables ¶
var ErrPaymentDeclined = errors.New("mpp: payment declined")
ErrPaymentDeclined is returned when the approval hook declines a payment.
Functions ¶
func IsPaymentRequiredError ¶
IsPaymentRequiredError reports whether err is an MCP payment-required or payment-verification-failed error that carries at least one Challenge.
func Receipt ¶
func Receipt(result *mcp.CallToolResult) (*mpp.MCPReceipt, error)
Receipt returns the payment receipt in a tool result's _meta["org.paymentauth/receipt"], or nil when it has none.
func WithOnPaymentRequired ¶
func WithOnPaymentRequired(ctx context.Context, fn OnPaymentRequired) context.Context
WithOnPaymentRequired returns a context whose tool calls use fn instead of Config.OnPaymentRequired. A nil fn pays without asking.
Types ¶
type Config ¶
type Config struct {
// Methods are the payment methods the client can pay with.
Methods []mppclient.Method
// OnPaymentRequired, when set, approves every payment before it is made.
OnPaymentRequired OnPaymentRequired
// OrderChallenges, when set, filters and sorts payable Challenges.
OrderChallenges OrderChallenges
// PaymentPreferences ranks Challenges by "method/intent" q-values.
PaymentPreferences mppclient.PaymentPreferences
// TrustedTempoProofRealms lists the realms the client signs zero-amount
// Tempo proofs for. A zero-amount tempo/charge Challenge authenticates the
// payer at the realm it names, and an MCP server has no origin to compare
// that realm with, so other realms are refused, like the HTTP Transport
// refuses realms its origin does not own.
TrustedTempoProofRealms []string
}
Config configures payment handling for an MCP client.
type OnPaymentRequired ¶
OnPaymentRequired approves a payment before a Credential is created for challenge. Returning false declines it.
type OrderChallenges ¶
type OrderChallenges func( ctx context.Context, candidates []mppclient.ChallengeCandidate, ) ([]mppclient.ChallengeCandidate, error)
OrderChallenges filters and sorts the payable Challenges before one is paid; the first one returned is paid.