Skip to main content
Glama
XeroAPI

Xero MCP Server

Official

create-contact

Add a new contact to Xero accounting software, returning a direct link to view the created contact record in Xero.

Instructions

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
emailNo
phoneNo

Implementation Reference

  • Primary handler for the 'create-contact' tool: defines the tool name, description, Zod input schema, and the async execution function that handles contact creation, error cases, deep link generation, and response formatting.
    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}`,
              },
            ],
          };
        }
      },
    );
  • Registers 'create-contact' tool by importing CreateContactTool and including it in the CreateTools array, which is exported and later used for MCP server tool registration.
    export const CreateTools = [
      CreateContactTool,
      CreateCreditNoteTool,
      CreateManualJournalTool,
      CreateInvoiceTool,
      CreateQuoteTool,
      CreatePaymentTool,
      CreateItemTool,
      CreateBankTransactionTool,
      CreatePayrollTimesheetTool,
      CreateTrackingCategoryTool,
      CreateTrackingOptionsTool
    ];
  • Top-level registration: iterates over CreateTools (including create-contact), instantiates each tool factory, and registers them on the MCP server using server.tool(name, description, schema, handler).
    CreateTools.map((tool) => tool()).forEach((tool) =>
      server.tool(tool.name, tool.description, tool.schema, tool.handler),
    );
  • Core helper function that orchestrates contact creation: calls internal createContact API wrapper, handles success/error responses in XeroClientResponse format.
    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),
        };
      }
    }
  • Low-level helper that constructs Contact object and calls Xero API to create contacts.
    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];
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses that a deep link is returned and should be displayed to the user, which adds useful behavioral context beyond the basic creation action. However, it doesn't cover critical aspects like authentication requirements, error handling, rate limits, or whether the operation is idempotent, leaving gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized with three sentences that are front-loaded: the first states the core action, and the following two explain the return value and its usage. There's minimal waste, though the third sentence could be integrated more tightly. Overall, it's efficient and structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (a mutation tool with no annotations and no output schema), the description is partially complete. It covers the action and return behavior but lacks details on parameters, error cases, and broader context like authentication. For a tool creating resources in an external system, more guidance on prerequisites and outcomes would improve completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It adds no information about the three parameters (name, email, phone), their semantics, formats, or constraints beyond what the schema provides (e.g., name is required, email has format). This leaves parameters largely unexplained, failing to address the coverage gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Create a contact') and resource ('in Xero'), making the purpose immediately understandable. It distinguishes from sibling tools like 'list-contacts' and 'update-contact' by specifying creation rather than listing or updating. However, it doesn't explicitly differentiate from other creation tools (e.g., 'create-invoice'), though the resource type makes this distinction clear.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., required permissions), when not to use it (e.g., for updating existing contacts), or direct alternatives like 'update-contact' for modifications. The context is implied through the action and resource but lacks explicit usage instructions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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