update-contact
Modify contact details in Xero and receive a direct link to view the updated contact record.
Instructions
Update a contact in Xero. When a contact is updated, 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.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contactId | Yes | ||
| name | Yes | ||
| firstName | No | ||
| lastName | No | ||
| No | |||
| phone | No | ||
| address | No |
Implementation Reference
- The MCP tool handler function for 'update-contact'. It invokes the underlying updateXeroContact handler, handles success/error responses, generates a deep link to the contact, and returns formatted content.async ({ contactId, name, firstName, lastName, email, phone, address, }: { contactId: string; name: string; email?: string; phone?: string; address?: { addressLine1: string; addressLine2?: string; city?: string; region?: string; postalCode?: string; country?: string; }; firstName?: string; lastName?: string; }) => { try { const response = await updateXeroContact( contactId, name, firstName, lastName, email, phone, address, ); if (response.isError) { return { content: [ { type: "text" as const, text: `Error updating 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 updated: ${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}`, }, ], }; } },
- Zod input schema defining parameters for the update-contact tool: contactId, name, firstName, lastName, email, phone, address.{ contactId: z.string(), name: z.string(), firstName: z.string().optional(), lastName: z.string().optional(), email: z.string().email().optional(), phone: z.string().optional(), address: z .object({ addressLine1: z.string(), addressLine2: z.string().optional(), city: z.string().optional(), region: z.string().optional(), postalCode: z.string().optional(), country: z.string().optional(), }) .optional(), },
- src/tools/update/index.ts:16-30 (registration)Includes UpdateContactTool in the UpdateTools export array for batch registration.export const UpdateTools = [ UpdateContactTool, UpdateCreditNoteTool, UpdateInvoiceTool, UpdateManualJournalTool, UpdateQuoteTool, UpdateItemTool, UpdateBankTransactionTool, ApprovePayrollTimesheetTool, AddTimesheetLineTool, UpdatePayrollTimesheetLineTool, RevertPayrollTimesheetTool, UpdateTrackingCategoryTool, UpdateTrackingOptionsTool ];
- src/tools/tool-factory.ts:23-25 (registration)Batch registers all tools from UpdateTools (including update-contact) with the MCP server via server.tool().UpdateTools.map((tool) => tool()).forEach((tool) => server.tool(tool.name, tool.description, tool.schema, tool.handler), );
- Core implementation of contact update logic using Xero API: constructs Contact object and calls xeroClient.accountingApi.updateContact.export async function updateXeroContact( contactId: string, name: string, firstName?: string, lastName?: string, email?: string, phone?: string, address?: Address, ): Promise<XeroClientResponse<Contact>> { try { const updatedContact = await updateContact( name, firstName, lastName, email, phone, address, contactId, ); if (!updatedContact) { throw new Error("Contact update failed."); } return { result: updatedContact, isError: false, error: null, }; } catch (error) { return { result: null, isError: true, error: formatError(error), }; } }