Connect LangChain to QuickBooks Online by pointing LangChain's built-in MCPAdapter at DeepLedger's hosted MCP server, https://mcp.deepledger.ai/mcp, with a DeepLedger API key. The same tools work in LangGraph, because create_agent returns a LangGraph graph. The script below exposes only the company and report tools: it checks the company and pulls one Profit and Loss report without writing to QuickBooks.
This guide is for Python developers building a QuickBooks AI agent with LangChain or LangGraph.
How do I connect LangChain to QuickBooks Online?
- Connect the QuickBooks company. In DeepLedger, open Companies, select the company, open its Connections tab and choose Connect to QuickBooks. Complete Intuit's sign-in.
- Install LangChain with its MCP extra. Install langchain with the mcp extra, version 1.4.0 or newer, plus your model provider's LangChain package.
- Create a DeepLedger API key. In DeepLedger, open Settings → API keys and choose Create key. Pick an Expiration and All my companies or One company, then copy the key; it is shown once.
- Set the environment variables. Export the DeepLedger key, your model provider's key and the company you expect as environment variables.
pip install "langchain[mcp]>=1.4.0" langchain-openai
export DEEPLEDGER_API_KEY="dl_live_..." # DeepLedger: Settings → API keys → Create key
export OPENAI_API_KEY="..."
export LANGCHAIN_MODEL="openai:gpt-5.5" # any model string your provider package supports
export EXPECTED_QB_COMPANY="Demo Company"
- Run the script and compare the report. Save the script below, then run
python quickbooks_langchain.pyand compare the totals with the same report in QuickBooks Online.
# quickbooks_langchain.py
import asyncio
import os
from fastmcp.client import Client
from langchain.agents import create_agent
from langchain.mcp import MCPAdapter
MCP_URL = "https://mcp.deepledger.ai/mcp"
WANTED = {"qbCompanyProfile", "qbReports"}
async def main():
expected = os.environ["EXPECTED_QB_COMPANY"]
client = Client(MCP_URL, auth=os.environ["DEEPLEDGER_API_KEY"])
async with MCPAdapter(client) as adapter:
tools = [t for t in await adapter.list_tools() if t.name in WANTED]
missing = WANTED - {t.name for t in tools}
if missing:
raise RuntimeError(f"DeepLedger tools not found: {sorted(missing)}")
agent = create_agent(os.environ.get("LANGCHAIN_MODEL", "openai:gpt-5.5"), tools)
result = await agent.ainvoke({"messages": [{"role": "user", "content": f"""
Call qbCompanyProfile with operation "current".
The expected QuickBooks company is "{expected}".
If the returned company does not match, stop and explain the mismatch.
If it matches, call qbReports for a ProfitAndLoss report from
2026-09-01 through 2026-09-30 with accountingMethod "Accrual".
Return the company name, home currency, report dates, accounting basis,
net income, and whether totalRows is greater than count. Do not call any
other tool.
""".strip()}]})
print(result["messages"][-1].content)
asyncio.run(main())
In a notebook, use await main() instead of asyncio.run(main()). Use the same dates and basis in QuickBooks when you compare.
The code follows LangChain's MCP overview and MCP authentication pages. FastMCP's auth argument takes the bare token and adds the Bearer prefix itself, so don't include it. The langchain.mcp namespace is beta in LangChain 1.4.0 and prints a LangChainBetaWarning once per process (as of November 2026).
What are you connecting?
There are two separate authorizations:
- An admin connects a QuickBooks Online company to DeepLedger through Intuit's sign-in.
- Your Python process sends a DeepLedger API key to the DeepLedger MCP endpoint,
https://mcp.deepledger.ai/mcp.
The LangChain process never receives an Intuit token. LangChain adapts DeepLedger's MCP tools into tools its agent loop can call. See the QuickBooks MCP server guide for the broader architecture.
You need Python 3.10 or newer, a DeepLedger account with the company connected, and a model-provider key. Use a demo company while you test.
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 company and can't switch. There is no separate read-only switch on a key. Keep it in an environment variable or secret manager, never in source control.
How does the code work?
Packages. langchain[mcp] installs the built-in langchain.mcp namespace. Older examples use langchain-mcp-adapters and MultiServerMCPClient; LangChain documents MCPAdapter as the replacement. Don't mix the two APIs. For another model provider, install its LangChain package and change LANGCHAIN_MODEL.
The tool filter. The script keeps only qbCompanyProfile and qbReports and fails clearly if either is missing. Don't depend on a fixed tool count; catalogs change. qbCompanyProfile reads the company with current, and can also list, switch the active company and send feedback to DeepLedger; none of these writes to QuickBooks. The filter does not narrow the API key: other code with the same key could call any tool.
The context. list_tools() runs inside async with MCPAdapter(...), and the script builds and runs the agent inside the same block.
The report. qbReports takes accountingMethod as Accrual or Cash. Detail reports may be paged: on the first page, totalRows > count means more rows remain, and later pages continue while rowOffset + count < totalRows. A short page is not a complete ledger just because the call succeeded.
langchain.mcp (MCPAdapter) | langchain-mcp-adapters (MultiServerMCPClient) | |
|---|---|---|
| Status | Current, beta in langchain 1.4.0 | Older package |
| Install | pip install "langchain[mcp]>=1.4.0" | Separate package |
| Used in this guide | Yes | No |
How do I connect QuickBooks to LangGraph?
Use the same code. create_agent returns a compiled LangGraph graph, so the example is already a LangGraph application. Use that standard loop until you need to control the topology yourself.
For deterministic steps before or after the model, the tools from MCPAdapter.list_tools() are regular LangChain tools. Place them in a ToolNode, add routing, or embed the created agent as a subgraph. Keep the company check before any branch that can write.
LangGraph also offers human-in-the-loop middleware that pauses selected tool calls for approval. That approval needs a checkpointer and a real reviewer who resumes or rejects the call. Importing the middleware alone does not create a review system.
How does the agent pick the right QuickBooks company?
With an All my companies key, call qbCompanyProfile with operation: "list", switch by the returned organizationId, not a guessed name, and read the profile again before the report.
A switch changes the person's active company across all their AI apps. Two concurrent jobs using keys from the same person share that one active company and can interfere. For parallel or multi-company jobs, give each job a One company key, or send an X-Organization-Id header with the company's ID on every request; DeepLedger checks it against the person's access. The multiple-company guide explains the shared state.
What do you need before adding QuickBooks write tools?
Filtering tools is a model-facing boundary, not a permission on the key. Before exposing recording tools such as qbBill, qbExpense or qbJournalEntry:
- Name the exact write tools the workflow needs. Don't pass the full catalog.
- Add LangGraph human-in-the-loop approval for those tool names and persist the interrupted state.
- Verify the company again immediately before the approved write.
- Make sure every write carries the company in
companyId. - Revoke the key when the job ends or the operator changes.
DeepLedger refuses a write without the right company. If companyId is missing or differs from the active company, the call fails with COMPANY_REQUIRED or COMPANY_MISMATCH and nothing is written. DeepLedger also requires confirmation for voids and deletes, and supported recording paths check for duplicates and open documents. Uncertain items can go to a person through the tasks tool.
If you run the agent from cron, that is your code acting as the key's owner; DeepLedger does not start anything on its own. A prompt such as "ask before writing" is not an access control. Read what AI write access needs to protect before designing a recording workflow.
Next step: verify one company and one report
Start with a demo company. When the script prints its result:
- Check the company name against
EXPECTED_QB_COMPANY. - In QuickBooks Online → Reports → Profit and Loss, run the same company, September 1 through September 30, 2026, accrual basis. Follow the P&L analysis and verification workflow for what to compare.
- Compare net income. If
totalRowsis greater thancount, the result is incomplete.
If figures differ, fix the dates or basis and rerun before relying on the agent. The journal-entry review workflow is a good first real task.
Troubleshooting
ImportError: cannot import name 'MCPAdapter'. Confirm the environment has langchain[mcp]>=1.4.0. The standalone adapter package uses different import paths.
401 Unauthorized. The DeepLedger key may be mistyped, expired or revoked. Create a replacement under Settings → API keys rather than logging the full failing token.
NO_ACTIVE_COMPANY. Call qbCompanyProfile with operation: "list", switch with the returned organization ID, and read the profile again.
COMPANY_REQUIRED or COMPANY_MISMATCH. A write had no companyId, or named a different company from the active one. Nothing was written. Confirm the company, then retry.
QB_NOT_CONNECTED or a token error. An admin reconnects that company on its Connections tab in DeepLedger. Retrying Python code does not repair a disconnected QuickBooks authorization.
The report differs from QuickBooks. Check the company, dates, accounting basis and whether the response was paged.
Beta warnings appear. That is expected for langchain.mcp today. Pin and test the version you deploy.
For client-neutral connection issues, see the QuickBooks MCP troubleshooting hub.
Current primary documentation
- LangChain MCPAdapter overview
- LangChain MCP authentication
- Migrate from langchain-mcp-adapters
- LangChain human-in-the-loop middleware
The LangChain and FastMCP code was checked against their documentation on November 2, 2026; we did not run it against a live company for this revision.
Frequently asked questions
How do I connect LangChain to QuickBooks Online?
Install langchain with its MCP extra, create a DeepLedger API key, build a FastMCP Client for https://mcp.deepledger.ai/mcp with that key, and pass the client to LangChain's MCPAdapter. Call list_tools(), keep only the tools your agent needs, and pass them to create_agent.
How do I connect QuickBooks to LangGraph?
Use the same code. LangChain's create_agent returns a compiled LangGraph graph, and the tools returned by MCPAdapter are standard LangChain tools, so you can run the simple agent loop first or place those tools in a ToolNode inside your own LangGraph workflow. Keep the company check before any branch that can write.
Should a new project still use langchain-mcp-adapters?
No. Current LangChain documentation directs new Python projects to the built-in langchain.mcp namespace in langchain 1.4.0 or newer. It replaces MultiServerMCPClient with MCPAdapter, but the new namespace is still beta and may change.
Do I need an Intuit developer app?
Not for this hosted setup. You connect the QuickBooks company to DeepLedger once through Intuit's sign-in, then the LangChain process authenticates to DeepLedger with a DeepLedger API key. A direct QuickBooks API integration is a different architecture and does require your own Intuit app.
Does filtering the LangChain tool list make the API key read-only?
No. Filtering limits which tools that agent can choose, but a DeepLedger API key carries the access of the person who created it, and there is no separate read-only switch on a key. Keep the key in an environment variable or secret manager, revoke it when it is no longer needed, and add a human approval step before exposing any write tool.
Can one LangChain agent work with several QuickBooks companies?
Yes, with an All my companies key. Use qbCompanyProfile to list and explicitly switch companies, then verify the returned company before each report or write. A switch changes the person's shared active company across their AI apps, so parallel jobs should use One company keys or an X-Organization-Id header.
Related guides
- QuickBooks MCP server guide
- Connect CrewAI to QuickBooks Online
- Build a custom QuickBooks AI agent with an API key
- Run a local model against QuickBooks with Ollama
Browse all AI platforms and integrations.