Dynamics 365 Business Central MCP Server
A governed, read-only-by-default Model Context Protocol (MCP) server for Microsoft Dynamics 365 Business Central OData v4 APIs. Built in Python for finance, ERP operations, and engineering teams that need AI assistants to query ledgers, trial balances, and purchase orders without exposing unredacted PII or granting unapproved write access.
Maintained by Code Ninety Dynamics 365 Engineering.
Architecture Overview
Every tool call passes through a strict governance pipeline before reaching either the zero-credential in-memory sandbox or live Microsoft Dynamics 365 Business Central OData v4 endpoints.
flowchart LR
Client["MCP Client (Claude Desktop / Cursor)"] -->|stdio JSON-RPC| Server["MCPServer (6 Typed Tools)"]
Server --> RBAC["RBAC & Out-of-Band HMAC Gate"]
RBAC -->|Read Allowed / Draft Approved| Mode{"D365_MODE"}
Mode -->|sandbox| Sandbox["In-Memory BC Sandbox Dataset"]
Mode -->|live| OAuth["Entra ID OAuth 2.0 Token Cache"]
OAuth -->|Pooled HTTP + Pagination| OData["BC API v2.0 & Custom AL API"]
Sandbox --> Redactor["Deterministic PII Redactor"]
OData --> Redactor
Redactor --> Audit["SHA-256 JSON Audit Logger"]
Audit --> Client
Governance and Security Controls
- Read-Only Default (
D365_READ_ONLY=true): All mutation paths are disabled out of the box. Writes fail withD365_GOVERNANCE_ERRORunlessD365_READ_ONLY=falseis explicitly configured. InD365_MODE=livewithD365_READ_ONLY=false, startup rejects the default sandbox secret and anyD365_APPROVAL_SECRETshorter than 32 characters. - True Out-of-Band Human Approval & Replay Guard:
bc_request_write_approvalnever mints a signed token; it returns only the canonicalpayload_sha256digest and the exactd365-mcp-approveCLI command for a human operator to run out-of-band withD365_APPROVAL_SECRET. Each token embeds a single-usejtinonce tracked in memory (with expired-entry pruning) so replaying a consumed token raisesAPPROVAL_TOKEN_REPLAYED. - Deterministic Recursive PII Redaction (
D365_REDACT_PII=true): Nested dictionaries, lists, tuples, and strings are scrubbed before leaving the server for IBANs, Pakistani CNICs, US SSNs, email addresses, and phone numbers while preserving invoice numbers and GL account codes. - OData
$filterInjection Protection & Bounded Pagination: Filter inputs pass throughescape_odata_string()('escaped to'', control characters and OData operators rejected), journal batch IDs are GUID-validated,@odata.nextLinkpagination enforces same-host checks andD365_MAX_PAGES, and HTTP connections share a pooledhttpx.AsyncClient. - Entra ID OAuth 2.0 Token Buffering & SHA-256 Audit Trail: Bearer tokens refresh 60 seconds prior to expiry with exponential backoff on HTTP
429/503, and every tool call emits a structured JSON audit record with the canonical SHA-256 parameter hash.
Custom AL Extension for Customer Ledger Entries
Standard Business Central API v2.0 does not expose a built-in customerLedgerEntries endpoint. In live mode, bc_get_customer_ledger routes to the included read-only AL API page at al/CustomerLedgerAPI.al (page 50100 "CN Customer Ledger API", PageType = API, Editable = false):
/api/{D365_AL_API_PUBLISHER}/{D365_AL_API_GROUP}/{D365_AL_API_VERSION}/companies({company_id})/customerLedgerEntries
By default this resolves to /api/codeninety/governance/v1.0/companies({company_id})/customerLedgerEntries. Deploy al/CustomerLedgerAPI.al into your Business Central extension (or adjust D365_AL_API_PUBLISHER, D365_AL_API_GROUP, and D365_AL_API_VERSION to match your AppSource/PTE namespace).
Standard Business Central API v2.0 endpoints handle trialBalances (with dateFilter when period is supplied), purchaseOrders, journals batch lookup, and journals({journalId})/journalLines draft creation.
Exposed MCP Tools and Operator CLI
| Interface | Access Level | Description |
|---|---|---|
bc_get_customer_ledger |
Read | Query customer ledger entries via sandbox or al/CustomerLedgerAPI.al. |
bc_get_gl_trial_balance |
Read | Retrieve trialBalances rows filtered by dateFilter period or account prefix. |
bc_get_purchase_orders |
Read | List purchaseOrders filtered by document status or vendor number. |
bc_validate_tax_invoice |
Read / Validate | Validate PK_FBR_IRIS, SA_ZATCA_P2 (binary TLV Tags 1-8), or AE_UAE_VAT. |
bc_request_write_approval |
Governance | Prepare a pending approval digest and d365-mcp-approve CLI command. |
bc_create_draft_journal |
Controlled Write | Create unposted journalLines using a single-use out-of-band HMAC token. |
d365-mcp-approve |
Operator CLI | Out-of-band CLI run by a human approver to mint a single-use HMAC token. |
Microsoft Native Business Central MCP Server vs. Governed Middleware
Microsoft provides a hosted Business Central MCP server (mcp.businesscentral.dynamics.com) for SaaS environments. Choose the right layer based on your security boundary and compliance scope:
- Use Microsoft's native Business Central MCP server when your workflow stays inside Business Central SaaS with interactive delegated Entra user permissions, standard out-of-the-box API surfaces, and zero custom pre-response filtering or regional tax validation.
- Deploy this governed Python MCP server when your architecture requires:
- Fail-closed write governance: Default
D365_READ_ONLY=trueplus out-of-band human HMAC approval (d365-mcp-approve) with single-usejtireplay protection so an LLM cannot self-approve ledger mutations. - Pre-LLM PII redaction & audit logging: Deterministic scrubbing of IBANs, CNICs, SSNs, emails, and phones before payloads enter model context, paired with SHA-256 parameter audit logs.
- Custom AL read-only surfaces & local sandbox: Included read-only AL page for
Cust. Ledger Entryand a zero-credential sandbox for deterministic CI/CD and agent evaluation. - Regional fiscal validation: Pre-submission schema and ZATCA Phase 2 binary Base64 TLV verification (
PK_FBR_IRIS,SA_ZATCA_P2,AE_UAE_VAT).
- Fail-closed write governance: Default
Quickstart (Sandbox Mode)
Sandbox mode runs immediately with zero Azure or Dynamics 365 credentials.
pip install dynamics365-mcp-server
dynamics365-mcp-server
Or install from source in an isolated virtual environment:
git clone https://github.com/Code-Ninety/dynamics-365-mcp-server.git
cd dynamics-365-mcp-server
python3 -m venv .venv
.venv/bin/pip install -e ".[dev]"
.venv/bin/pytest -v
Out-of-Band Write Approval Workflow
When D365_READ_ONLY=false, the MCP client calls bc_request_write_approval to obtain a canonical payload_sha256 and operator command. A human operator reviews the payload and mints a single-use token out-of-band:
export D365_APPROVAL_SECRET="replace-with-32-byte-or-longer-production-secret"
d365-mcp-approve \
--action bc_create_draft_journal \
--payload-sha256 <64-char-hex-digest> \
--requester finance-lead@example.com
Claude Desktop and Cursor Configuration
Add the server to your claude_desktop_config.json or .cursor/mcp.json:
{
"mcpServers": {
"dynamics365-business-central": {
"command": "dynamics365-mcp-server",
"env": {
"D365_MODE": "sandbox",
"D365_READ_ONLY": "true",
"D365_REDACT_PII": "true"
}
}
}
}
To connect to a live Microsoft Dynamics 365 Business Central tenant, copy .env.example, set D365_MODE=live, and supply D365_TENANT_ID, D365_CLIENT_ID, D365_CLIENT_SECRET, D365_ENVIRONMENT_NAME, and D365_COMPANY_ID.
Architecture Decision Records
- ADR-001: Read-Only Default RBAC and HMAC Write Approvals
- ADR-002: Deterministic Recursive PII Redaction
- ADR-003: Dual-Mode OData v4 Client and In-Memory Sandbox
Enterprise Dynamics 365 Services
This repository is published as an open-source reference architecture by Code Ninety. For production Business Central deployments, custom AL extensions, ZATCA Phase 2 / FBR IRIS integrations, or managed Entra ID governance, visit Code Ninety Microsoft Dynamics 365 Services.
License
MIT License. Copyright (c) 2026 Code Ninety (Private) Limited. See LICENSE.
Metadata
Release files for dynamics365-mcp-server 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dynamics365_mcp_server-1.1.0.tar.gz | 41.5 kB | With provenance | Details for dynamics365_mcp_server-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dynamics365_mcp_server-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for dynamics365_mcp_server-1.1.0-py3-none-any.whl |
Total release size: 80.4 kB
Release files / dynamics365_mcp_server-1.1.0.tar.gz
| Download URL | dynamics365_mcp_server-1.1.0.tar.gz |
|---|---|
| Size | 41.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6ed97e56a062caf027cdfe35232ac402eefc93de76c0e95ec36b282dbfe2fe57
|
|
BLAKE2b-256 checksum How to use checksums |
5a77981af83bb03e79eccf29a3ad1ca21b2b827465c665ab17d51ced52146b9f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logRelease files / dynamics365_mcp_server-1.1.0-py3-none-any.whl
| Download URL | dynamics365_mcp_server-1.1.0-py3-none-any.whl |
|---|---|
| Size | 38.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5f69245655c315bb4b72b4176d80e0b18965df54c53fc0b129f1aa9328e905e6
|
|
BLAKE2b-256 checksum How to use checksums |
963ae381fcf027bed893af75e4544736148c47307efc1218731248853fa03695
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logSecurity for dynamics365-mcp-server 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for dynamics365_mcp_server-1.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.