Skip to main content
Glama

Xero MCP Server

Contacts.ts2.19 kB
import { XeroClientSession } from "../../XeroApiClient.js"; import { IMcpServerTool } from "../IMcpServerTool.js"; import { z } from "zod"; import { Contacts } from "xero-node"; import { XeroAccountingApiSchema } from "../../Resources/xero_accounting.js"; import { parseArrayValues } from "../../Utils/parseArrayValues.js"; import { convertToCamelCase } from "../../Utils/convertToCamelCase.js"; import { sanitizeObject } from "../../Utils/sanitizeValues.js"; export const ListContactsTool: IMcpServerTool = { requestSchema: { name: "list_contacts", description: "Retrieves all contacts in a Xero organisation", inputSchema: { type: "object", properties: {} }, output: { content: [{ type: "text", text: z.string() }] }, }, requestHandler: async () => { const response = await XeroClientSession.xeroClient.accountingApi.getContacts( XeroClientSession.activeTenantId()!! ); const contacts = response.body.contacts || []; return { content: [ { type: "text", text: JSON.stringify(contacts), }, ], }; }, }; export const CreateContactsTool: IMcpServerTool = { requestSchema: { name: "create_contacts", description: "Creates one or multiple contacts in a Xero organisation. Only use this tool when user has directly and explicitly ask you to create contact.", inputSchema: { type: "object", description: "Contacts with an array of Contact objects to create", properties: XeroAccountingApiSchema.components.schemas.Contacts.properties, example: '{ contacts: [{ name: "John Doe" }]}', }, output: { content: [{ type: "text", text: z.string() }] }, }, requestHandler: async (request) => { const rawInputData = request.params.arguments; const parsedData = parseArrayValues(rawInputData); const contacts: Contacts = convertToCamelCase(parsedData); const response = await XeroClientSession.xeroClient.accountingApi.createContacts( XeroClientSession.activeTenantId()!!, sanitizeObject(contacts) ); return { content: [{ type: "text", text: JSON.stringify(response.body) }] }; }, };

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/john-zhang-dev/xero-mcp'

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