Skip to main content
Glama
DynamicEndpoints

PayPal MCP

create_invoice

Generate and send PayPal invoices with itemized details, currency specifications, and recipient information for payment processing.

Instructions

Create a new invoice

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
invoice_numberYes
referenceYes
currency_codeYes
recipient_emailYes
itemsYes

Implementation Reference

  • Handler for 'create_invoice' tool: validates arguments using validatePayPalInvoice, constructs the invoice data, sends POST to PayPal invoicing API, and returns the response.
    case 'create_invoice': {
      const args = this.validatePayPalInvoice(request.params.arguments);
      const invoiceData: PayPalInvoice = {
        detail: {
          invoice_number: args.detail.invoice_number,
          reference: args.detail.reference,
          currency_code: args.detail.currency_code
        },
        primary_recipients: [{
          billing_info: {
            email_address: args.primary_recipients[0].billing_info.email_address
          }
        }],
        items: args.items
      };
      const response = await axios.post<PayPalInvoice>(
        'https://api-m.sandbox.paypal.com/v2/invoicing/invoices',
        invoiceData,
        { headers }
      );
      return {
        content: [{
          type: 'text',
          text: JSON.stringify(response.data, null, 2)
        }]
      };
    }
  • src/index.ts:1108-1137 (registration)
    Registration of the 'create_invoice' tool in the ListTools response, including name, description, and input schema definition.
      name: 'create_invoice',
      description: 'Create a new invoice',
      inputSchema: {
        type: 'object',
        properties: {
          invoice_number: { type: 'string' },
          reference: { type: 'string' },
          currency_code: { type: 'string' },
          recipient_email: { type: 'string' },
          items: {
            type: 'array',
            items: {
              type: 'object',
              properties: {
                name: { type: 'string' },
                quantity: { type: 'string' },
                unit_amount: {
                  type: 'object',
                  properties: {
                    currency_code: { type: 'string' },
                    value: { type: 'string' }
                  }
                }
              }
            }
          }
        },
        required: ['invoice_number', 'reference', 'currency_code', 'recipient_email', 'items']
      }
    }
  • Helper function validatePayPalInvoice that validates and structures the input arguments for creating an invoice according to PayPalInvoice interface.
    private validatePayPalInvoice(args: unknown): PayPalInvoice {
      if (typeof args !== 'object' || !args) {
        throw new McpError(ErrorCode.InvalidParams, 'Invalid invoice data');
      }
    
      const invoice = args as Record<string, unknown>;
      
      if (!invoice.detail || typeof invoice.detail !== 'object' ||
          !Array.isArray(invoice.primary_recipients) || invoice.primary_recipients.length === 0 ||
          !Array.isArray(invoice.items) || invoice.items.length === 0) {
        throw new McpError(ErrorCode.InvalidParams, 'Missing required invoice fields');
      }
    
      const detail = invoice.detail as Record<string, unknown>;
      if (typeof detail.invoice_number !== 'string' ||
          typeof detail.reference !== 'string' ||
          typeof detail.currency_code !== 'string') {
        throw new McpError(ErrorCode.InvalidParams, 'Invalid invoice detail fields');
      }
    
      const recipient = invoice.primary_recipients[0] as Record<string, unknown>;
      if (!recipient.billing_info || typeof recipient.billing_info !== 'object' ||
          typeof (recipient.billing_info as any).email_address !== 'string') {
        throw new McpError(ErrorCode.InvalidParams, 'Invalid recipient information');
      }
    
      const items = invoice.items as Array<Record<string, unknown>>;
      const validatedItems = items.map(item => {
        if (typeof item.name !== 'string' ||
            typeof item.quantity !== 'string' ||
            !item.unit_amount || typeof item.unit_amount !== 'object') {
          throw new McpError(ErrorCode.InvalidParams, 'Invalid invoice item');
        }
    
        const amount = item.unit_amount as Record<string, unknown>;
        if (typeof amount.currency_code !== 'string' || typeof amount.value !== 'string') {
          throw new McpError(ErrorCode.InvalidParams, 'Invalid item amount');
        }
    
        return {
          name: item.name,
          quantity: item.quantity,
          unit_amount: {
            currency_code: amount.currency_code,
            value: amount.value
          }
        };
      });
    
      return {
        detail: {
          invoice_number: detail.invoice_number,
          reference: detail.reference,
          currency_code: detail.currency_code
        },
        primary_recipients: [{
          billing_info: {
            email_address: (recipient.billing_info as any).email_address
          }
        }],
        items: validatedItems
      };
    }
  • TypeScript interface defining the structure of a PayPalInvoice, used for type safety in validation and API calls.
    interface PayPalInvoice {
      id?: string;
      detail: {
        invoice_number: string;
        reference: string;
        currency_code: string;
      };
      primary_recipients: Array<{
        billing_info: {
          email_address: string;
        };
      }>;
      items: Array<{
        name: string;
        quantity: string;
        unit_amount: {
          currency_code: string;
          value: string;
        };
      }>;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. 'Create a new invoice' implies a write/mutation operation but provides no information about permissions required, whether the invoice becomes immediately active, what happens on failure, rate limits, or what the response contains. For a creation tool with 5 required parameters and no annotations, this is insufficient behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is maximally concise at just three words. There's no wasted language or unnecessary elaboration. While this conciseness comes at the cost of completeness, the description itself is perfectly structured and front-loaded with the essential information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a creation tool with 5 required parameters (including a complex 'items' array with nested objects), 0% schema description coverage, no annotations, and no output schema, the description is woefully incomplete. It doesn't explain what constitutes a valid invoice, what happens after creation, error conditions, or provide any parameter guidance - leaving the agent to guess about critical aspects of the operation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, meaning none of the 5 parameters have descriptions in the schema. The tool description provides no information about what parameters are needed or their meanings. The agent must infer everything from parameter names alone, which is inadequate for parameters like 'items' with complex nested structure or 'currency_code' which likely has format requirements.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Create a new invoice' clearly states the action (create) and resource (invoice), which is better than a tautology. However, it doesn't differentiate this from sibling tools like 'create_order' or 'create_product' - it's generic rather than specific about what makes invoice creation unique compared to other creation operations in this system.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With multiple 'create_' sibling tools available (create_order, create_product, create_payment, etc.), there's no indication of when invoice creation is appropriate versus other creation operations, nor any mention of prerequisites or constraints for using this tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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