create_stripe_customer
Create a new customer in Stripe to manage billing and subscriptions within the PocketBase database system.
Instructions
Create a new customer in Stripe
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/services/stripe.ts:975-981 (registration)Registers the create_stripe_customer MCP tool with input schema, description, and handler function that instantiates StripeService and calls createCustomerexport function registerTools(server: any, pb: any): void { server.tool('create_stripe_customer', 'Create a Stripe customer', { type: 'object', properties: { email: { type: 'string' }, name: { type: 'string' } } }, async (args: any) => { const stripeService = new StripeService(pb); const customer = await stripeService.createCustomer({ email: args.email, name: args.name }); return { success: true, customer }; }); }
- src/services/stripe.ts:69-107 (handler)Core implementation of customer creation: checks for existing customer by email in PocketBase, creates new Stripe customer via Stripe API, saves to PocketBase stripe_customers collectionasync createCustomer(data: { email: string; name?: string; userId?: string; metadata?: Record<string, any>; }): Promise<StripeCustomer> { try { // Check if customer already exists const existingCustomer = await this.pb.collection('stripe_customers') .getFirstListItem(`email="${data.email}"`) .catch(() => null); if (existingCustomer) { return existingCustomer as StripeCustomer; } // Create customer in Stripe const stripeCustomer = await this.stripe.customers.create({ email: data.email, name: data.name, metadata: { userId: data.userId || '', ...data.metadata, }, }); // Save to PocketBase const customerRecord = await this.pb.collection('stripe_customers').create({ email: data.email, name: data.name, stripeCustomerId: stripeCustomer.id, userId: data.userId, metadata: data.metadata || {}, }); return customerRecord as unknown as StripeCustomer; } catch (error: any) { throw new Error(`Failed to create customer: ${error.message}`); } }
- src/services/stripe.ts:976-980 (schema)Input schema for create_stripe_customer tool: requires email and optional nameserver.tool('create_stripe_customer', 'Create a Stripe customer', { type: 'object', properties: { email: { type: 'string' }, name: { type: 'string' } } }, async (args: any) => { const stripeService = new StripeService(pb); const customer = await stripeService.createCustomer({ email: args.email, name: args.name }); return { success: true, customer }; });
- src/agent-simple.ts:589-633 (registration)Alternative registration of create_stripe_customer tool in agent-simple.ts, with more detailed schema and error handling, also delegating to StripeService.createCustomer'create_stripe_customer', 'Create a new customer in Stripe', { type: 'object', properties: { email: { type: 'string', format: 'email', description: 'Customer email' }, name: { type: 'string', description: 'Customer name' } }, required: ['email'] }, async ({ email, name }) => { // Lazy load Stripe service await this.ensureStripeService(); if (!this.stripeService) { return { content: [{ type: 'text', text: JSON.stringify({ error: 'Stripe service not available. Please set STRIPE_SECRET_KEY environment variable.' }) }] }; } try { const customer = await this.stripeService.createCustomer({ email, name }); return { content: [{ type: 'text', text: JSON.stringify(customer, null, 2) }] }; } catch (error: any) { return { content: [{ type: 'text', text: JSON.stringify({ error: `Failed to create Stripe customer: ${error.message}` }) }] }; } } );