Back to Writing

Complete Guide: D365 F&O MCP Authentication with User Credentials

Setting up authentication between Microsoft Dynamics 365 Finance & Operations (D365FO) and AI tools like Claude Desktop can unlock powerful business intelligence capabilities. In this comprehensive guide, I'll walk you through the complete process of configuring user-based authentication to connect your D365FO environment with Claude Desktop using Model Context Protocol (MCP) servers.

Contents

Understanding the Authentication Flow

Before diving into the configuration, it's important to understand how the authentication flow works between D365FO, Azure, and Claude Desktop:

  1. Azure Portal: Manages user permissions and application access
  2. Azure CLI: Handles OAuth2 authentication and token management
  3. MCP Server: Acts as a bridge between Claude and D365FO APIs
  4. Claude Desktop: Provides the AI interface for querying business data

This setup enables secure, user-based access to D365FO data through AI-powered queries while maintaining enterprise security standards.

Prerequisites and Requirements

Before starting, ensure you have:

  • Administrative access to Azure Portal for your organization
  • D365FO environment with proper licensing and access
  • Windows PowerShell or Command Prompt access
  • Claude Desktop application installed
  • Basic understanding of Azure Active Directory concepts

Step 1: Azure Portal User Access Configuration

Start by accessing the Azure Portal and configuring the necessary permissions:

  1. Open your web browser and navigate to https://portal.azure.com
  2. Sign in with your Azure administrator credentials
  3. Click on Microsoft Entra ID (formerly Azure Active Directory) in the main menu

Finding the Dynamics ERP Application

In the Microsoft Entra ID dashboard:

  1. Click Enterprise applications in the left navigation menu
  2. If you see a filter showing "Application type == Enterprise Applications", click the X to remove it
  3. Use the search box to find "Microsoft Dynamics ERP"
  4. Click on the Microsoft Dynamics ERP application from the results

Pro Tip: Removing the default filter ensures you can see all available applications, including the Dynamics ERP entry you need.

Assigning User Permissions

Once you've opened the Microsoft Dynamics ERP application:

  1. Click Users and groups in the left navigation panel
  2. Select + Add user/group at the top of the page
  3. In the Add Assignment panel:
    • Click Users and groups
    • Search for and select the target user(s)
    • Click Select
  4. If roles are available, click Select a role and choose the appropriate permissions
  5. Click Assign to finalize the user assignment

Verification

After assignment, verify that:

  • The user appears in the Users and groups list
  • The assigned role is displayed correctly
  • You've noted the user's email address for the next steps

Step 2: Azure CLI Installation and Setup

Installing Azure CLI

If Azure CLI isn't already installed on your system:

  1. Open PowerShell as Administrator
  2. Install using Windows Package Manager:
winget install --exact --id Microsoft.AzureCLI
  1. Wait for the installation to complete
  2. Close and reopen PowerShell to refresh the environment

Verifying the Installation

Test that Azure CLI is properly installed:

az --version

You should see version information for Azure CLI and its components.

Authenticating with D365FO

The key to successful authentication is using the correct scope for your D365FO environment:

az login --scope https://your-fno-env/.default --allow-no-subscriptions

Replace your-fno-env with your actual D365FO environment URL.

This command will:

  1. Open a browser window for OAuth2 authentication
  2. Prompt you to sign in with the user credentials configured in Step 1
  3. Return a JSON response confirming successful authentication

Alternative: Device Code Authentication

For environments where browser-based authentication isn't possible:

az login --scope https://your-fno-env/.default --allow-no-subscriptions --use-device-code

This method provides:

  • A device code and URL for authentication
  • Ability to authenticate from any device with internet access
  • Secure token exchange without requiring a local browser

Verifying Authentication Status

Confirm your authentication is working:

az account show

Ensure the tenant ID matches your organization's Azure tenant.

Step 3: Claude Desktop MCP Configuration

Locating the Configuration File

Claude Desktop stores its configuration in a specific location:

  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Full Path: C:\Users\<username>\AppData\Roaming\Claude\claude_desktop_config.json

Creating the MCP Configuration

If the configuration file doesn't exist, create it. Otherwise, edit the existing file to include the D365FO MCP server:

{
	"mcpServers": {
		"d365fo": {
			"command": "uvx",
			"args": ["--from", "d365fo-client", "d365fo-mcp-server"],
			"env": {
				"D365FO_LOG_LEVEL": "DEBUG"
			}
		}
	}
}

Understanding the Configuration

This configuration tells Claude Desktop:

  • d365fo: The name of the MCP server instance
  • uvx: The Python package runner for executing the MCP server
  • d365fo-client: The Python package containing the D365FO MCP implementation
  • D365FO_LOG_LEVEL: Environment variable for debugging (set to INFO for production)

Activating the Configuration

After saving the configuration file:

  1. Close Claude Desktop completely (check system tray)
  2. Restart the application
  3. The D365FO MCP server should now be available for AI queries

Testing and Verification

Azure CLI Connection Test

Verify your Azure CLI connection is working:

az rest --method GET --url "https://your-fno-env/api/services"

A successful response indicates proper authentication and API access.

Claude Desktop Integration Test

In Claude Desktop, test the MCP integration:

  1. Start a new conversation
  2. Ask Claude to test the D365FO connection
  3. Try a simple query like: "Can you list the available D365FO entities?"

If configured correctly, Claude should respond with D365FO-specific information.

Sample Queries to Try

Once everything is working, try these sample queries:

  • "Show me the top 10 customers by revenue"
  • "What are the current inventory levels for product X?"
  • "Generate a sales report for the last quarter"

Troubleshooting Common Issues

Azure CLI Issues

Problem: 'az' is not recognized as a command Solution: Restart PowerShell or add Azure CLI to your PATH environment variable

Problem: Authentication failures Solution: Verify user permissions in Azure Portal and check the D365FO environment URL

Problem: Scope-related errors Solution: Ensure the scope URL matches your exact D365FO environment

Claude Desktop Issues

Problem: MCP server not loading Solution: Check JSON syntax in the configuration file and verify file location

Problem: uvx command not found Solution: Install the uv package manager: pip install uv

Problem: Permission errors Solution: Try running Claude Desktop as administrator

D365FO Access Issues

Problem: 403 Forbidden errors Solution: Verify role assignments and D365FO permissions for the user

Problem: 404 Not Found errors Solution: Confirm the D365FO environment URL is correct and accessible

Problem: Token expiration Solution: Re-run the az login command to refresh authentication tokens

Security Best Practices

Credential Management

  • Never share Azure credentials or store them in plain text
  • Use managed identities for production environments when possible
  • Implement principle of least privilege for D365FO access roles
  • Monitor access logs in Azure Portal for unusual activity

Token Security

  • Understand token lifetime and refresh requirements
  • Use secure storage for any configuration files
  • Implement proper logout procedures when work is complete

Monitoring and Auditing

  • Enable Azure AD sign-in logs for authentication monitoring
  • Review D365FO access patterns regularly
  • Set up alerts for suspicious access attempts

Next Steps and Use Cases

Powerful AI-Driven Analytics

With this setup, you can now:

  • Generate automated reports from D365FO data
  • Perform natural language queries on business information
  • Create data visualizations and insights
  • Build custom workflows combining AI and ERP data

Advanced Integration Patterns

Consider exploring:

  • Scheduled data analysis using automation tools
  • Integration with Power BI for enhanced reporting
  • Custom MCP server development for specific business needs
  • Multi-environment setups for development and production

Learning Resources

To maximize your investment in this setup:

If you're interested in D365 F&O development and AI integration, check out these related posts:

Conclusion

Setting up D365FO MCP authentication with user credentials opens up powerful possibilities for AI-driven business intelligence. By following this guide, you've created a secure, scalable foundation for integrating enterprise data with modern AI tools.

The combination of Azure's enterprise security, D365FO's comprehensive business data, and Claude's AI capabilities provides a powerful platform for data-driven decision making. Whether you're generating reports, analyzing trends, or exploring business insights, this setup gives you the tools to leverage AI for enterprise success.

Remember to follow security best practices, monitor your usage, and explore the advanced capabilities that this integration makes possible. The future of business intelligence is here, and it's powered by the combination of enterprise data and artificial intelligence.