Skip to main content
Glama
DynamicEndpoints

PayPal MCP

create_payment

Process PayPal payments by specifying payment intent, payer details, and transaction amounts to complete online transactions.

Instructions

Create a payment

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
intentYes
payerYes
transactionsYes

Implementation Reference

  • The core handler logic for the 'create_payment' tool. It validates the input arguments, makes a POST request to the PayPal v2/payments/payment endpoint using axios, and returns the API response as formatted JSON text.
    case 'create_payment': { const args = this.validatePayment(request.params.arguments); const response = await axios.post<PayPalPayment>( 'https://api-m.sandbox.paypal.com/v2/payments/payment', args, { headers } ); return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }] }; }
  • src/index.ts:819-873 (registration)
    Tool registration in the ListTools response, defining name, description, and detailed JSON input schema for parameter validation.
    name: 'create_payment', description: 'Create a payment', inputSchema: { type: 'object', properties: { intent: { type: 'string' }, payer: { type: 'object', properties: { payment_method: { type: 'string' }, funding_instruments: { type: 'array', items: { type: 'object', properties: { credit_card: { type: 'object', properties: { number: { type: 'string' }, type: { type: 'string' }, expire_month: { type: 'number' }, expire_year: { type: 'number' }, cvv2: { type: 'string' }, first_name: { type: 'string' }, last_name: { type: 'string' } } } } } } }, required: ['payment_method'] }, transactions: { type: 'array', items: { type: 'object', properties: { amount: { type: 'object', properties: { total: { type: 'string' }, currency: { type: 'string' } }, required: ['total', 'currency'] }, description: { type: 'string' } }, required: ['amount'] } } }, required: ['intent', 'payer', 'transactions'] } },
  • TypeScript interface defining the structure of PayPalPayment used for type safety in the handler and validation.
    interface PayPalPayment { id?: string; intent: string; payer: { payment_method: string; funding_instruments?: Array<{ credit_card?: { number: string; type: string; expire_month: number; expire_year: number; cvv2: string; first_name: string; last_name: string; }; }>; }; transactions: Array<{ amount: { total: string; currency: string; }; description?: string; }>; }
  • Helper function validatePayment that parses, validates, and structures the tool arguments according to the PayPalPayment interface, throwing MCP errors on invalid input.
    private validatePayment(args: unknown): PayPalPayment { if (typeof args !== 'object' || !args) { throw new McpError(ErrorCode.InvalidParams, 'Invalid payment data'); } const payment = args as Record<string, unknown>; if (typeof payment.intent !== 'string' || !payment.payer || typeof payment.payer !== 'object' || !Array.isArray(payment.transactions) || payment.transactions.length === 0) { throw new McpError(ErrorCode.InvalidParams, 'Missing required payment fields'); } const payer = payment.payer as Record<string, unknown>; if (typeof payer.payment_method !== 'string') { throw new McpError(ErrorCode.InvalidParams, 'Invalid payment method'); } const transactions = payment.transactions.map(transaction => { const trans = transaction as Record<string, unknown>; if (!trans.amount || typeof trans.amount !== 'object') { throw new McpError(ErrorCode.InvalidParams, 'Invalid transaction amount'); } const amount = trans.amount as Record<string, unknown>; if (typeof amount.total !== 'string' || typeof amount.currency !== 'string') { throw new McpError(ErrorCode.InvalidParams, 'Invalid amount fields'); } const validatedTransaction = { amount: { total: amount.total, currency: amount.currency } }; if (typeof trans.description === 'string') { (validatedTransaction as any).description = trans.description; } return validatedTransaction; }); return { intent: payment.intent, payer: { payment_method: payer.payment_method, funding_instruments: payer.funding_instruments as PayPalPayment['payer']['funding_instruments'] }, transactions }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/DynamicEndpoints/Paypal-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server