Documentation Index
Fetch the complete documentation index at: https://docs.solvapay.com/llms.txt
Use this file to discover all available pages before exploring further.
Table of Contents
Installation
Install the required packages:Basic Setup
1. Initialize SolvaPay
Create a SolvaPay instance in your MCP server:2. Create MCP Server
Set up your MCP server:3. Define Tools
Define your MCP tools:Protecting MCP Tools
Basic Tool Protection
Wrap your tool handlers withpayable.mcp():
Multiple Tools with Same Plan
Create onepayable handler and apply it to all protected tools:
Authentication
Customer Reference in Tool Arguments
The MCP adapter expects customer reference in theauth object:
Extract Customer Reference
The MCP adapter automatically extractscustomer_ref from args.auth.customer_ref:
Custom Customer Reference Extraction
Override customer reference extraction:OAuth Bearer Token Helper
For MCP servers that authenticate with bearer tokens, you can use the server SDK helper utilities:customerRef, customer_ref, sub) and do not verify signatures.
Use them after token validation (for example with /v1/customer/auth/userinfo).
Fail closed on auth failures. Do not substitute fallback identities such as anonymous.
Non-hosted OAuth Bridge Pattern
If your MCP server runs on localhost/custom domain (not SolvaPay hosted MCP proxy):- Serve local discovery endpoints:
/.well-known/oauth-protected-resource/.well-known/oauth-authorization-server
- Point discovery metadata to SolvaPay OAuth endpoints (
/v1/customer/auth/*) - Ensure
registration_endpointincludesmcp_server_id - Protect
/mcpwith bearer auth and return RFC9728WWW-Authenticatechallenge when missing
examples/mcp-oauth-bridge.
Plan activation from MCP tools
Exposeactivate_plan (backed by activatePlanCore from @solvapay/server or the @solvapay/next wrapper) so the agent can upgrade the customer without a browser round-trip. The result shape depends on plan type:
- Free plan —
{ status: 'activated', purchaseRef }. - Usage-based plan —
{ status: 'activated', purchaseRef, creditBalance }even whencreditBalance === 0. The customer can start calling paid tools immediately; top-up is optional and flows throughcreate_topup_payment_intent. - Recurring / hybrid plan —
{ status: 'topup_required' | 'payment_required', checkoutUrl }when the customer has no credit balance and no card on file. Return thecheckoutUrlso the agent can surface it via a hosted checkout link.
createSolvaPayMcpServer tool surface, activate_plan, upgrade, and topup already map to these flows — you rarely need to implement them by hand.
Error Handling
Basic Error Handling
The MCP adapter routes paywall gate outcomes through a typedformatGate channel — the transport emits isError: false, a plain-string
narration in content[0].text, and the machine-readable gate payload on
structuredContent. Merchants don’t need to try/catch for the happy path:
Custom Paywall Responses
Usepaywall.decide() directly when you want full control over the paywall
response shape (e.g. a hand-rolled MCP handler that doesn’t use
payable().mcp()):
try/catch a PaywallError keep working —
PaywallError is exported as a compat shim:
Complete Example
Here’s a complete MCP server with SolvaPay integration:Testing the Example
- Save the code to
src/index.ts - Set environment variable:
SOLVAPAY_SECRET_KEY=sk_... - Run the server:
node dist/index.js
Tool Response Format
The MCP adapter automatically formats responses. Your business logic should return:- Object: Automatically converted to MCP response format
- Error: Thrown as exception (PaywallError handled automatically)
Best Practices
-
Customer Reference: Always require
customer_refin theauthobject for tool arguments. -
Error Handling: Handle
PaywallErrorappropriately to provide clear error messages to MCP clients. - Tool Documentation: Provide clear descriptions in tool schemas so users understand what each tool does.
- Type Safety: Use TypeScript for better type safety and developer experience.
- Environment Variables: Store API keys in environment variables, not in code.
- Tool Naming: Use clear, descriptive names for your tools.
Next Steps
- Express.js Integration Guide - Learn HTTP framework integration
- Usage Events - Track and bill tool usage
- Custom Authentication Adapters - Build custom auth adapters
- API Reference - Full API documentation