DeepLedger
Menu

For developers

Connect CrewAI to Xero: Python MCP Setup

Connect CrewAI to Xero with CrewAI's MCPServerHTTP, DeepLedger's hosted endpoint, a revocable API key and a read-only first profit and loss.

Published by DeepLedger9 min read

Connect Xero to CrewAI by giving a CrewAI agent an MCPServerHTTP entry in its mcps field, pointed at DeepLedger's hosted MCP server with a DeepLedger API key. DeepLedger holds the Xero connection, so the crew needs no Xero app. The code below allows only the organisation and report tools: it checks the organisation and runs one profit and loss without writing to Xero.

This guide is for Python developers and finance teams building a CrewAI crew for Xero reporting or bookkeeping.

How do I connect Xero to CrewAI?

  1. Connect the Xero organisation. In DeepLedger, open Companies, select the company, open its Connections tab and choose Connect to Xero. Approve DeepLedger on Xero's sign-in page.
  2. Add CrewAI's MCP dependency. Inside your CrewAI project, run uv add mcp.
  3. Create a DeepLedger API key. In DeepLedger, open Settings → API keys and choose Create key. Choose an Expiration and All my companies or One company, then copy the key; it is shown once.
  4. Export the key. Export the key as DEEPLEDGER_API_KEY in the shell or secret store that runs the crew.
uv add mcp
export DEEPLEDGER_API_KEY="dl_live_..."

Set up your model-provider credential as CrewAI's LLM documentation describes, then save this file:

# xero_crew.py
import os

from crewai import Agent, Crew, Task
from crewai.mcp import MCPServerHTTP
from crewai.mcp.filters import create_static_tool_filter

deepledger = MCPServerHTTP(
    url="https://mcp.deepledger.ai/mcp",
    headers={
        "Authorization": f"Bearer {os.environ['DEEPLEDGER_API_KEY']}"
    },
    streamable=True,
    tool_filter=create_static_tool_filter(
        allowed_tool_names=["xeroOrganisation", "xeroReports"]
    ),
)

analyst = Agent(
    role="Xero report analyst",
    goal="Return a dated profit and loss from the right Xero organisation without changing the books.",
    backstory=(
        "You confirm the organisation, base currency, dates and basis "
        "before you explain any total. You never guess missing figures."
    ),
    mcps=[deepledger],
    verbose=True,
)

check_report = Task(
    description=(
        "First call xeroOrganisation with operation profile. Then call "
        "xeroReports with reportType profitAndLoss, fromDate 2026-10-01 "
        "and toDate 2026-10-31, leaving paymentsOnly unset for the accrual "
        "basis. State the organisation, base currency, dates and basis. "
        "Do not call any other tool."
    ),
    expected_output=(
        "A short check naming the organisation, currency, dates, basis, "
        "total income, total operating expenses and net profit."
    ),
    agent=analyst,
)

result = Crew(agents=[analyst], tasks=[check_report]).kickoff()
print(result)
  1. Run the crew and compare the report. Run uv run python xero_crew.py and compare the totals with the same profit and loss in Xero.

The configuration follows CrewAI's MCP documentation: MCPServerHTTP with url, headers, streamable and tool_filter, passed through the agent's mcps field.

What are you connecting?

Two authorisations sit behind the crew:

  1. Xero to DeepLedger. An admin connects the organisation once through Xero's sign-in, and DeepLedger keeps that connection.
  2. CrewAI to DeepLedger. Your Python process sends a DeepLedger API key to the hosted Xero MCP server and gets accounting tools back.

The crew never sees a Xero password or token. You need:

  • Python 3.10 through 3.13. CrewAI's installation guide asks for Python 3.10 or newer and below 3.14 (as of November 2026).
  • A CrewAI project with the mcp dependency.
  • A DeepLedger account with the Xero organisation connected.
  • A model-provider credential set up as CrewAI's LLM documentation describes.

A DeepLedger API key acts as the person who created it, with that person's access. Any team member can create one. A One company key works only in that organisation and cannot switch. A key has no read-only switch, so keep it in an environment variable or secret store, never in source code.

Which CrewAI MCP option should you use?

mcps field with MCPServerHTTPMCPServerAdapter
Status in CrewAI's docsRecommended for agent integrationsOlder, for manual lifecycle control
Packagemcpcrewai-tools[mcp]
Transport settingstreamable=True (the default)"transport": "streamable-http"
Tool filteringtool_filter with create_static_tool_filterFilter the returned tool list yourself
Used in this guideYesNo

Pick one API and follow it. Mixing examples from both is the usual cause of import errors.

How does the crew pick the right Xero organisation?

An All my companies key follows its creator's active company, which is shared across that person's connected AI apps, so another session can move it. For one organisation, the profile call in the sample is the check. For several:

  1. Call xeroOrganisation with operation: "list".
  2. Take the exact organizationId from the result.
  3. Call xeroOrganisation with operation: "switch" and that id.
  4. Read the company named in the switch result.
  5. Run the report and check the company named in the report result too.

Do not switch by a guessed name when two clients look alike. Two crews running on keys from the same person share one active company. For parallel crews, give each a One company key, or add an X-Organization-Id header with the company id to headers; DeepLedger checks it against the person's access. The multiple-company guide explains the shared state.

Which Xero tools should the agent see?

The filter in the example is small on purpose:

allowed_tool_names=["xeroOrganisation", "xeroReports"]

That is enough for a reporting crew. xeroReports covers the profit and loss, balance sheet, trial balance and aged receivables and payables. Xero runs the aged reports one contact at a time, so a crew that needs everyone's open items adds xeroFetchTransactions and searches open invoices or bills. Other additions follow the task: xeroMasterData for accounts, contacts and tracking categories; agentMemory for the client's AI Brain; tasks to hand uncertain items to a person.

The filter keeps the model's tool list short. It does not narrow the key: anyone holding the key can call any tool its creator can. Revoke a key under Settings → API keys when a job or host is retired.

Before you add a write tool, know how Xero writes behave. New invoices, bills, credit notes and manual journals are saved as drafts unless the request asks to approve them. Payments, spend and receive money and transfers post straight away. With an All my companies key, every write must carry the company it is meant for (companyId), or it fails with COMPANY_REQUIRED. A One company key or an X-Organization-Id header fixes the company, so the field is optional there. A write that names a different company fails with COMPANY_MISMATCH. Either way, nothing is written. Nothing dated on or before the lock date can change, and voids need confirmation.

Next step: verify one organisation and one report

Start with a demo organisation. When the crew prints its result:

  1. Check that the organisation name matches the books you meant to open.
  2. In Xero, open Reporting → All reports → Profit and Loss for the same organisation, October 1 to 31, 2026, accrual basis.
  3. Compare total income, operating expenses and net profit.

A plausible total is not proof. If figures differ, fix the dates, basis or report layout and rerun. The Xero profit and loss walkthrough lists what to compare.

Can I run the crew on a schedule?

Yes, from your own job runner. A scheduled crew is your code acting as the key's owner; DeepLedger does not start anything on its own and only answers the requests the crew sends.

Keep the DeepLedger and model-provider keys in the runner's secret store, use an expiring key where you can, use fixed report dates, keep the output, and alert when a run fails or names the wrong organisation.

Adding write-tool names does not make a scheduled crew safe for recording. CrewAI's filter is a client-side control, and a generated report is not a person's approval. A recording crew needs a short list of write tools, the right companyId on every write, drafts left for review, and testing against Xero's demo company first.

Troubleshooting

ModuleNotFoundError: No module named 'mcp'

Run uv add mcp in the CrewAI project, then sync the environment.

ImportError: cannot import name 'MCPServerAdapter'

You are following an older adapter example without crewai-tools[mcp]. For the current approach, import MCPServerHTTP from crewai.mcp and pass it through mcps.

401 Unauthorized

Check that the header starts with Bearer , the key was copied in full, and it has not expired or been revoked under Settings → API keys. Log a short prefix only, never the whole key.

The report names the wrong organisation

Another app or job moved the shared active company. List, switch by exact id and rerun the profile check. Treat a mismatch as a stop.

Aged receivables asks for a contact

Xero runs the aged reports one contact at a time. Allow xeroFetchTransactions and search open invoices instead.

Reports fail after a successful switch

That organisation's Xero authorisation has lapsed. An admin reconnects it from the company's Connections tab in DeepLedger. More fixes are in Xero MCP troubleshooting.

Frequently asked questions

How do I connect Xero to CrewAI?

Give a CrewAI agent an MCPServerHTTP entry in its mcps field. Point it at DeepLedger's hosted MCP server, https://mcp.deepledger.ai/mcp, and send a DeepLedger API key in the Authorization header as a bearer token. The example in this guide allows only the organisation and report tools for the first run.

Do I need a Xero developer account to connect CrewAI?

No. An admin connects the Xero organisation to DeepLedger once through Xero's own sign-in, then CrewAI connects to DeepLedger with a DeepLedger API key. A direct Xero API integration is a different design and needs your own Xero app and OAuth code.

Which Xero organisation will the crew use?

An All my companies key follows its creator's active company, which is shared across that person's AI apps. Call xeroOrganisation with list, switch by organizationId and confirm the company in each result. A One company key works only in that organisation.

Can the crew create invoices or bills in Xero?

Yes, if you allow those tools and the key's owner can write. DeepLedger saves new Xero invoices, bills, credit notes and manual journals as drafts unless the request asks to approve them. Payments, spend and receive money and transfers post straight away.

Which CrewAI MCP option should I use?

Use MCPServerHTTP in the agent's mcps field for a remote Streamable HTTP endpoint such as DeepLedger. Its streamable option defaults to true. The older MCPServerAdapter API still works, but CrewAI's documentation recommends the mcps field for agent integrations.

Can I run the Xero crew on a schedule?

Yes, from your own job runner. The scheduled crew is your code acting as the key's owner; DeepLedger does not start anything on its own. Keep both keys in the runner's secret store, use fixed report dates, and alert when a run fails or names the wrong organisation.

Sources

The CrewAI configuration matches our QuickBooks Online guide, which was checked against CrewAI's documentation on November 2, 2026. The Xero tool names and fields were checked against DeepLedger's Xero tools in November 2026. We did not run the crew against a live organisation.

Browse all AI platforms and integrations.

Ready to get started?

Connect QuickBooks and try your first task with an AI agent.

Start free trial

With your permission, Google Analytics measures visits to our public website and blog. Essential cookies work either way. Change your choice in Cookie settings. Privacy policy