← Back to blog

Integrating the Dynamics 365 ERP MCP Server for AI-Driven Operations

Learn how to leverage the Model Context Protocol (MCP) server framework to build autonomous agents that execute D365 F&O business logic without custom APIs.

Integrating the Dynamics 365 ERP MCP Server for AI-Driven Operations

Traditional D365 F&O integrations rely on brittle OData endpoints, custom X++ services, and complex API gateways. By integrating a Model Context Protocol (MCP) server directly with your finance and operations environment, you can expose standard business logic and data entities to AI models securely and without scaffolding extra middle tier endpoints.

Prerequisites & Environment

  • Node.js v18+ and TypeScript 5.x
  • Microsoft Dynamics 365 F&O (Platform Update 56+) with system administrator access
  • Azure AD App Registration configured with permissions for Dynamics 365 ERP
  • Local Ollama instance or Claude Desktop supporting MCP stdio/HTTP transport

Hands-On Implementation

Step 1: Scaffolding the MCP Server

Initialize your TypeScript-based MCP server project and install the core protocol packages alongside the Microsoft Authentication Library (MSAL).

mkdir d365-mcp-server && cd d365-mcp-server
npm init -y
npm install @modelcontextprotocol/sdk @azure/msal-node axios dotenv
npm install -D typescript @types/node ts-node
npx tsc --init

Step 2: Configuring the D365 OData Client

Create a secure client wrapper that handles token acquisition and interfaces directly with the D365 F&O OData and Custom Service endpoints.

import { ConfidentialClientApplication } from '@azure/msal-node';
import axios from 'axios';
import dotenv from 'dotenv';

dotenv.config();

const msalConfig = {
  auth: {
    clientId: process.env.D365_CLIENT_ID || '',
    authority: `https://login.microsoftonline.com/${process.env.D365_TENANT_ID}`,
    clientSecret: process.env.D365_CLIENT_SECRET || '',
  },
};

const cca = new ConfidentialClientApplication(msalConfig);

export async function getD365Token(): Promise<string> {
  const response = await cca.acquireTokenByClientCredential({
    scopes: [`${process.env.D365_RESOURCE_URL}/.default`],
  });
  if (!response || !response.accessToken) {
    throw new Error('Failed to acquire access token for D365 F&O');
  }
  return response.accessToken;
}

Deployment & Infrastructure

Deploy the compiled MCP server as a managed background service using PM2 on an Ubuntu VPS, or configure it as a local stdio plugin inside your AI client configuration file.

{
  "mcpServers": {
    "d365-erp": {
      "command": "node",
      "args": ["/opt/d365-mcp-server/dist/index.js"],
      "env": {
        "D365_RESOURCE_URL": "https://your-env.dynamics.com"
      }
    }
  }
}

War Stories & Debugging

Watch out for Azure AD token scope mismatches and OData batch throttling limits. Ensure your custom X++ services expose proper service operations attributes if bypassing OData standard entities.

By unifying MCP with D365 F&O, developers drastically reduce integration overhead while empowering intelligent systems with native ERP awareness.

#Dynamics 365#MCP#TypeScript#Node.js#AI Agents