Add MCP Payment Support Specification #2007
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SEP-2009: Payment Support for MCP Servers
Abstract
This SEP introduces payment capabilities to the Model Context Protocol (MCP), enabling MCP servers to request payment for premium features, usage-based billing, or access to restricted resources. The specification defines a protocol-agnostic framework that supports multiple payment methods, with X402 Protocol v2 as the first supported payment protocol. The framework includes payment discovery, challenge/response flows, and secure payment verification mechanisms.
Motivation
As MCP adoption grows, there is increasing demand for monetization capabilities that allow server operators to:
Current MCP implementations lack standardized payment mechanisms, leading to:
A standardized payment framework addresses these issues by:
Specification
1. Core Payment Framework
1.1 Payment Discovery
MCP servers that support payments SHOULD provide payment metadata through the
payments/listJSON-RPC method. This metadata includes:Request:
{ "jsonrpc": "2.0", "id": 1, "method": "payments/list", "params": {} }Response:
{ "jsonrpc": "2.0", "id": 1, "result": { "protocols": { "x402": { "version": 2, "schemes": ["eip155:8453", "eip155:1"], "description": "X402 Protocol v2 for micropayments" } }, "terms": "https://example.com/terms", "privacy": "https://example.com/privacy" } }1.2 Payment Challenge Flow
When payment is required for a tool invocation, servers MUST return error code
-32803with protocol-specific payment information:{ "jsonrpc": "2.0", "id": 1, "error": { "code": -32803, "message": "Payment Required", "data": { "protocol": "x402", "paymentInfo": { // Protocol-specific payment information } } } }1.3 Payment Processing
Clients MUST implement protocol-specific payment handling based on the
protocolfield. After successful payment, clients include payment proof in protocol-specific headers when retrying the tool invocation.1.4 Payment Verification
Servers MUST verify payment proofs through protocol-specific facilitators before granting access to paid tools.
1.5 Settlement Response
Servers SHOULD include protocol-specific settlement information in successful responses and MUST include settlement details in payment failure responses to provide confirmation and audit trail details.
2. X402 Protocol Support
2.1 Protocol Selection
X402 Protocol v2 is the recommended payment protocol for MCP implementations due to:
2.2 X402 Integration
For X402 payments:
X-Paymentheader for payment proofsexactscheme for tool-based payments2.3 X402 Payment Structure
{ "x402Version": 2, "error": "Payment required for premium API access", "resource": { "url": "https://api.example.com/premium-data", "description": "Access to premium market data", "mimeType": "application/json" }, "accepts": [ { "scheme": "exact", "network": "eip155:8453", "amount": "10000", "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", "payTo": "0xReceiverAddress", "maxTimeoutSeconds": 60, "extra": { "name": "USDC", "version": "2" } } ], "extensions": {} }3. Security Requirements
3.1 Error Handling
Payment implementations MUST handle various error scenarios with appropriate JSON-RPC error responses:
3.2 Resource Identification
Payment-related resources SHOULD use MCP-specific URI schemes:
mcp://tool/{tool_name}mcp://resource/{resource_name}mcp://prompt/{prompt_name}3.3 General Security
All implementations MUST:
3.4 Privacy Protection
Implementations MUST protect user privacy by:
Rationale
Rationale
Design Decisions
Protocol-Agnostic Framework: Supports multiple payment methods rather than a single protocol to enable future-proofing, broader market adoption, and risk mitigation across different payment ecosystems.
X402 as First Protocol: Chosen for its maturity, decentralization, cryptographic proofs, and existing ecosystem, making it ideal for initial implementation while maintaining protocol flexibility.
JSON-RPC Integration: Uses
payments/listmethod for discovery and-32803error code for payment requirements to maintain transport-agnostic design and consistency with MCP's JSON-RPC approach.Structured Payment Proofs: Uses JSON structure in
paymentProoffield rather than base64 encoding to improve developer experience, debugging capabilities, and protocol consistency while maintaining transport independence.Protocol Consistency
X402 Proxy Considerations
While MCP servers proxying X402 endpoints need to convert JSON to base64 headers, this conversion is minimal:
The trivial nature of this conversion (a single line of base64 encoding) does not justify sacrificing the significant developer experience benefits of structured JSON. Most programming languages provide built-in base64 encoding, and this conversion can be abstracted into helper libraries for common use cases.
Backward Compatibility
This specification is fully backward compatible with existing MCP implementations:
Reference Implementation
A reference implementation will include:
The reference implementation will be provided in TypeScript/JavaScript to align with the existing MCP ecosystem.
Client Implementation
MCP clients SHOULD provide a payment hook interface to enable custom payment integration:
This allows client builders to integrate their preferred payment methods without modifying the core MCP client implementation.
References