import { z } from 'zod';
import { FinixContext, ToolFactory } from '../../types.js';
import { FinixClient } from '../../utils/finixClient.js';
const createBuyerPrompt = () => `
This tool creates a new Buyer Identity in Finix.
It takes the following arguments:
- email (str): The email address of the buyer.
- first_name (str): The first name.
- last_name (str): The last name.
- phone (str): The phone number.
`;
const createBuyerParameters = () => z.object({
email: z.string().email().describe('The email address of the buyer'),
first_name: z.string().describe('The first name'),
last_name: z.string().describe('The last name'),
phone: z.string().describe('The phone number')
});
const createBuyerAnnotations = () => ({
destructiveHint: false,
idempotentHint: false,
openWorldHint: true,
readOnlyHint: false,
title: 'Create Buyer'
});
const createBuyer = async (client: FinixClient, _context: FinixContext, params: any): Promise<any> => {
try {
if (!client.hasCredentials()) {
throw new Error('Finix username and password are required for this operation. Please configure FINIX_USERNAME and FINIX_PASSWORD in your environment.');
}
const { email, first_name, last_name, phone } = params;
const payload = {
entity: {
email,
first_name,
last_name,
phone
},
type: 'PERSONAL',
identity_roles: ['BUYER']
};
const response = await client.post('/identities', payload);
if (response.error) {
throw new Error(`Error creating buyer: ${response.error.message}`);
}
// Return just the ID like Stripe MCP
return { id: response.data.id };
} catch (error) {
throw error;
}
};
const tool: ToolFactory = () => ({
method: 'create_buyer',
name: 'Create Buyer',
description: createBuyerPrompt(),
parameters: createBuyerParameters(),
annotations: createBuyerAnnotations(),
actions: {
identities: {
create: true
}
},
execute: createBuyer
});
export default tool;