Skip to main content
This guide explains how to integrate the Nevermined Payments Python SDK with MCP (Model Context Protocol) servers.

Overview

MCP (Model Context Protocol) enables AI applications to interact with external tools, resources, and prompts. The Nevermined SDK provides built-in MCP integration to:
  • Protect tools, resources, and prompts with paywalls
  • Handle OAuth 2.1 authentication
  • Manage credit consumption per operation

MCP Integration API

Access the MCP integration through payments.mcp:
The simplified API handles server setup automatically:

Register a Tool

Register a Resource

Register a Prompt

Start the Server

Advanced API

For more control, use the advanced API:

Configure and Protect Handlers

Attach to Existing Server

Complete Example

Server Configuration

Handler Options

Response Metadata (_meta)

After each paywall-protected call, the SDK injects a _meta field into the response following the MCP specification. This field is always present regardless of whether credit redemption succeeded or failed:

Endpoints

The MCP server exposes:
  • /.well-known/oauth-authorization-server - OAuth 2.1 discovery
  • /.well-known/oauth-protected-resource - Resource metadata
  • /.well-known/oauth-protected-resource/mcp - MCP-specific protected resource metadata
  • /.well-known/x402-payment - x402 payment discovery for MCP-aware payment clients
  • /register - Client registration
  • /mcp - MCP protocol endpoint (POST/GET/DELETE)
  • /health - Health check

MCP OAuth and x402 Discovery

MCP and standard x402 use different HTTP challenge shapes: Do not make the /mcp streamable HTTP endpoint return 402 for every missing token: MCP clients expect the OAuth 401 challenge and may fail before they can initialize. Instead, expose x402 payment metadata separately at /.well-known/x402-payment while keeping OAuth discovery enabled. Example discovery response:
This lets:
  • MCP-native clients follow OAuth 2.1 and send Authorization: Bearer <token>.
  • x402-aware clients discover the payment headers and endpoint before calling /mcp.
  • Browser-based agents read payment challenge/response headers because CORS allows and exposes payment-signature, payment-required, and payment-response.
The x402 discovery shape is marked experimental and may evolve as MCP transport support aligns with the x402 v2 MCP transport specification.

Next Steps

A2A Integration

Agent-to-Agent protocol

x402 Protocol

Payment protocol details