Skip to main content
Glama
XeroAPI

Xero MCP Server

Official

create-contact

Add a new contact to Xero via the MCP server by providing essential details like name, email, and phone number for streamlined contact management.

Instructions

Create a contact in Xero.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
emailNo
nameYes
phoneNo

Implementation Reference

  • Defines the MCP tool 'create-contact' with Zod input schema, description, and handler function that calls createXeroContact, generates a deep link, and formats the response.
    const CreateContactTool = CreateXeroTool( "create-contact", "Create a contact in Xero.\ When a contact is created, a deep link to the contact in Xero is returned. \ This deep link can be used to view the contact in Xero directly. \ This link should be displayed to the user.", { name: z.string(), email: z.string().email().optional(), phone: z.string().optional(), }, async ({ name, email, phone }) => { try { const response = await createXeroContact(name, email, phone); if (response.isError) { return { content: [ { type: "text" as const, text: `Error creating contact: ${response.error}`, }, ], }; } const contact = response.result; const deepLink = contact.contactID ? await getDeepLink(DeepLinkType.CONTACT, contact.contactID) : null; return { content: [ { type: "text" as const, text: [ `Contact created: ${contact.name} (ID: ${contact.contactID})`, deepLink ? `Link to view: ${deepLink}` : null, ] .filter(Boolean) .join("\n"), }, ], }; } catch (error) { const err = ensureError(error); return { content: [ { type: "text" as const, text: `Error creating contact: ${err.message}`, }, ], }; } }, );
  • Core helper function createXeroContact that performs the Xero API contact creation using createContact and wraps in standardized response format with error handling.
    export async function createXeroContact( name: string, email?: string, phone?: string, ): Promise<XeroClientResponse<Contact>> { try { const createdContact = await createContact(name, email, phone); if (!createdContact) { throw new Error("Contact creation failed."); } return { result: createdContact, isError: false, error: null, }; } catch (error) { return { result: null, isError: true, error: formatError(error), }; } }
  • Internal helper createContact that constructs the Contact object and calls Xero's createContacts API.
    async function createContact( name: string, email?: string, phone?: string, ): Promise<Contact | undefined> { await xeroClient.authenticate(); const contact: Contact = { name, emailAddress: email, phones: phone ? [ { phoneNumber: phone, phoneType: Phone.PhoneTypeEnum.MOBILE, }, ] : undefined, }; const response = await xeroClient.accountingApi.createContacts( xeroClient.tenantId, { contacts: [contact], }, //contacts true, //summarizeErrors undefined, //idempotencyKey getClientHeaders(), // options ); return response.body.contacts?.[0]; }
  • Registers all CreateTools (including 'create-contact') with the MCP server via server.tool calls.
    CreateTools.map((tool) => tool()).forEach((tool) => server.tool(tool.name, tool.description, tool.schema, tool.handler),
  • Groups and exports CreateContactTool as part of CreateTools for batch registration.
    export const CreateTools = [ CreateContactTool, CreateCreditNoteTool, CreateManualJournalTool, CreateInvoiceTool, CreateQuoteTool, CreatePaymentTool, CreateItemTool, CreateBankTransactionTool, CreatePayrollTimesheetTool, CreateTrackingCategoryTool, CreateTrackingOptionsTool ];

Other Tools

Related 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/XeroAPI/xero-mcp-server'

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