Skip to main content
Glama
Dynamics 365 Business Central MCP Server

Dynamics 365 Business Central MCP Server

by Code-Ninety
README.md
# Dynamics 365 Business Central MCP Server

A governed, read-only-by-default [Model Context Protocol (MCP)](https://modelcontextprotocol.io) 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 unrestricted write access.

Maintained by [Code Ninety Dynamics 365 Engineering](https://codeninety.com/services/microsoft-dynamics-365-partner).

## 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.

```mermaid
flowchart LR
    Client["MCP Client (Claude Desktop / Cursor)"] -->|stdio JSON-RPC| Server["MCPServer (6 Typed Tools)"]
    Server --> RBAC["RBAC & HMAC Approval 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 -->|Bearer Token + Retry| OData["Business Central OData v4 API"]
    Sandbox --> Redactor["Deterministic PII Redactor"]
    OData --> Redactor
    Redactor --> Audit["SHA-256 JSON Audit Logger"]
    Audit --> Client
```

## Governance and Security Controls

1. **Read-Only Default (`D365_READ_ONLY=true`)**: All mutation paths are disabled out of the box. Even if an approval token is supplied, writes fail with `D365_GOVERNANCE_ERROR` unless `D365_READ_ONLY=false` is explicitly configured by the operator.
2. **Scoped HMAC-SHA256 Write Approvals**: When controlled draft writes are enabled, `bc_create_draft_journal` requires a short-lived HMAC-SHA256 token issued by `bc_request_write_approval`. Each token is cryptographically bound to the action name, canonical SHA-256 payload digest, and expiration epoch.
3. **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.
4. **Entra ID OAuth 2.0 Token Buffering**: Client-credentials bearer tokens are cached per process and proactively refreshed 60 seconds prior to expiration, with exponential backoff on HTTP `429` (`Retry-After` honored) and `503`.
5. **SHA-256 Parameter Audit Trail**: Every tool invocation emits a structured JSON audit record containing the UTC timestamp, tool name, mode, outcome, and canonical SHA-256 parameter hash—never raw PII or secrets.

## Exposed MCP Tools

| Tool Name | Access Level | Description |
| :--- | :--- | :--- |
| `bc_get_customer_ledger` | Read | Query customer ledger entries filtered by customer number or open status. |
| `bc_get_gl_trial_balance` | Read | Retrieve general ledger trial balance rows by period or account prefix. |
| `bc_get_purchase_orders` | Read | List purchase orders filtered by document status or vendor number. |
| `bc_validate_tax_invoice` | Read / Validate | Validate invoice payloads for `PK_FBR_IRIS`, `SA_ZATCA_P2`, or `AE_UAE_VAT`. |
| `bc_request_write_approval` | Governance | Issue an HMAC-SHA256 approval token bound to a write action and payload. |
| `bc_create_draft_journal` | Controlled Write | Create an unposted, balanced draft general journal batch (`D365_READ_ONLY=false`). |

## Quickstart (Sandbox Mode)

Sandbox mode runs immediately with zero Azure or Dynamics 365 credentials.

```bash
pip install dynamics365-mcp-server
dynamics365-mcp-server
```

Or install from source in an isolated virtual environment:

```bash
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
```

## Claude Desktop and Cursor Configuration

Add the server to your `claude_desktop_config.json` or `.cursor/mcp.json`:

```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](docs/adr/ADR-001-readonly-default-rbac.md)
- [ADR-002: Deterministic Recursive PII Redaction](docs/adr/ADR-002-deterministic-pii-redaction.md)
- [ADR-003: Dual-Mode OData v4 Client and In-Memory Sandbox](docs/adr/ADR-003-dual-mode-odata-sandbox.md)

## 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](https://codeninety.com/services/microsoft-dynamics-365-partner).

## License

MIT License. Copyright (c) 2026 Code Ninety (Private) Limited. See [LICENSE](LICENSE).

TDQS

B3.2/5.0

Scored across 6 tools

Disambiguation5/5

Each tool targets a distinct resource or action: three different read surfaces, one tax validation, one approval-token issuance, and one draft-journal creation. The approval-token tool and draft-journal tool are related but clearly differentiated by their descriptions.

Naming Consistency5/5

All tools use a consistent `bc_` prefix followed by a snake_case verb_noun pattern, such as `bc_get_customer_ledger`, `bc_validate_tax_invoice`, and `bc_create_draft_journal`. The convention is predictable throughout the set.

Tool Count4/5

Six tools is a reasonable, well-scoped size for a focused finance and compliance subset, and each tool has a clear role. It is slightly thin for a broad Dynamics 365 Business Central server, but not unreasonably so.

Completeness3/5

The set covers several read scenarios plus a controlled draft-write workflow, but lifecycle coverage is notably incomplete: there is no way to read, update, post, or delete the created draft journal. Broader Business Central operations such as vendor, item, sales-order, or posting workflows are also absent.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues