mcp-dynamics-365
Enables AI agents to perform CRUD operations, query data, fetch schemas, and execute custom operations on Microsoft Dynamics 365 CRM entities.
README
Dynamics 365 CRM MCP Server
A comprehensive Model Context Protocol (MCP) server for interacting with Microsoft Dynamics 365 CRM. This server provides AI agents with the ability to perform CRUD operations, query data, fetch schemas, and execute custom operations on Dynamics 365 entities.
Remote Server (HTTP Transport)
This connects to a running HTTP server instance. First, start the server:
# Start server on default port (3300) for local access
pnpm run dev:http
# Or start server for remote access (binds to all interfaces)
pnpm run start:http-remote
For VS Code
Add to your mcp.json:
{
"servers": {
"dynamics365-crm-http": {
"url": "http://localhost:3300/mcp"
}
},
"inputs": []
}
Or, if you need to use OAuth authentication (for protected servers):
{
"servers": {
"dynamics365-crm-http": {
"url": "http://localhost:3300/mcp",
"oauth": {
"client_id": "your_github_client_id",
"client_secret": "your_github_client_secret"
}
}
},
"inputs": []
}
For remote servers, replace localhost with the server's IP address or hostname:
{
"servers": {
"dynamics365-crm-http": {
"url": "http://your-server-ip:3300/mcp"
}
},
"inputs": []
}
For Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"dynamics365-crm-http": {
"url": "http://localhost:3300/mcp"
}
}
}
Or, if you need to use OAuth authentication (for protected servers):
{
"mcpServers": {
"dynamics365-crm-http": {
"url": "http://localhost:3300/mcp",
"oauth": {
"client_id": "your_github_client_id",
"client_secret": "your_github_client_secret"
}
}
}
}
Note: When using HTTP transport, the server must be running separately and environment variables must be configured on the server side (not in the client configuration).
Note: Environment variables must be explicitly specified in the MCP configuration. The server does not automatically load .env files when run via MCP clients.
⚠️ Disclaimer: This project was generated with the assistance of AI as a side project. While functional, it may not receive regular maintenance or updates. Use at your own discretion and consider forking if you need ongoing support.
Features
- Generic Entity Operations: Query, create, update, and delete any Dynamics 365 entity
- Schema Discovery: Fetch entity metadata and available entity sets
- Flexible Querying: Support for OData query parameters (select, filter, orderby, top, skip, expand)
- Custom OData Queries: Execute direct OData queries for complex scenarios
- Function Execution: Call Dynamics 365 functions and actions
- Authentication: Secure OAuth 2.0 client credentials flow
- Error Handling: Comprehensive error handling and logging
Prerequisites
- Node.js 18+
- pnpm (recommended package manager)
- Dynamics 365 CRM instance
- Azure AD app registration with appropriate permissions
Package Manager Usage
This project uses pnpm for local development and npm for registry operations:
- Use pnpm:
pnpm install,pnpm run build,pnpm run dev,pnpm run test - Use npm:
npm publish,npm install -g @dav3/mcp-dynamics365-server
Azure AD App Registration
- Go to Azure Portal > Azure Active Directory > App registrations
- Create a new registration or use existing one
- Note down:
- Application (client) ID
- Directory (tenant) ID
- Create a client secret and note it down
- Grant the following API permissions:
- Dynamics CRM > user_impersonation
- Or create custom permissions based on your needs
Installation
- Install dependencies:
pnpm install
- Copy the environment template:
cp .env.example .env
- Configure your environment variables in
.env(see consolidated snippet below):
# Dynamics 365 CRM (Backend API)
D365_BASE_URL=https://your-org.crm.dynamics.com # Your Dynamics 365 organization URL
D365_CLIENT_ID=your-client-id # Azure AD application client ID
D365_CLIENT_SECRET=your-client-secret # Azure AD application client secret
D365_TENANT_ID=your-tenant-id # Azure AD tenant ID
D365_RESOURCE=https://your-org.crm.dynamics.com # Resource URL for Dynamics 365 API
# MCP OAuth Resource & Provider (Authentication)
# Only required for HTTP transport (not needed for stdio transport)
OAUTH_MCP_RESOURCE=http://localhost:3300
OAUTH_AUTH_URL=https://github.com/login/oauth/authorize
OAUTH_TOKEN_URL=https://github.com/login/oauth/access_token
OAUTH_JWKS_URL=https://api.github.com/meta # GitHub does not provide JWKS, so use a placeholder
OAUTH_BASE_URL=https://github.com
OAUTH_FLOW=opaque # Supported values: 'jwt' (for JWT validation), 'opaque' (for API token validation)
OAUTH_OPAQUE_USER_API=https://api.github.com/user # Optional: endpoint for opaque token validation
OAUTH_TOKEN_CACHE_DURATION_MS=86400000 # Optional: token validation cache duration in milliseconds (default: 24 hours)
# HTTP Transport Configuration (Optional)
MCP_HTTP_PORT=3300 # Port for HTTP transport (default: 3300)
MCP_HTTP_HOST=localhost # Host for HTTP transport (default: localhost)
Variable Explanations
Dynamics 365 CRM (Backend API):
D365_BASE_URL: Your Dynamics 365 organization URLD365_CLIENT_ID: Azure AD application client IDD365_CLIENT_SECRET: Azure AD application client secretD365_TENANT_ID: Azure AD tenant IDD365_RESOURCE: Resource URL for Dynamics 365 API
MCP OAuth Resource & Provider (Authentication):
OAUTH_MCP_RESOURCE: The resource identifier exposed to MCP clients (used for OAuth audience)OAUTH_AUTH_URL: OAuth 2.0 authorization endpointOAUTH_TOKEN_URL: OAuth 2.0 token endpointOAUTH_JWKS_URL: JWKS endpoint for public key discovery (required for JWT flow)OAUTH_BASE_URL: OAuth provider base URLOAUTH_FLOW: Selects the token validation flow. Use'jwt'for JWT validation (with JWKS),'opaque'for API token validation (e.g., GitHub, generic OAuth providers)opaquewas tested with githubjwtwas NOT untested yet
OAUTH_OPAQUE_USER_API: (Optional) API endpoint for validating opaque tokens (default: GitHub user API)
HTTP Transport Configuration (Optional):
MCP_HTTP_PORT: Port for HTTP transport (default: 3300)MCP_HTTP_HOST: Host for HTTP transport (default: localhost)
Authentication Modes
- If all OAuth MCP variables are set, the server enforces OAuth authentication for HTTP transport.
- If any are missing, the server runs in unauthenticated mode (no token required).
- The protected resource metadata endpoint (
/mcp/.well-known/oauth-protected-resource) is only available in authenticated mode.
Usage
Development
pnpm dev
Production
pnpm build
pnpm start
Transport Options
The server supports two transport methods:
1. Stdio Transport (Default)
For direct integration with MCP clients:
# Default transport
node dist/index.js
# Explicitly specify stdio
node dist/index.js --transport=stdio
2. HTTP Transport
For remote access and web-based integrations:
# Default HTTP port (3300)
node dist/index.js --transport=http
# Custom port
node dist/index.js --transport=http --port=8080
HTTP transport features:
- Streamable HTTP protocol compatible with MCP SDK
- CORS support for browser-based clients
- Session management with UUID-based session IDs
- Default port: 3300
- Endpoint:
/mcp
Command Line Options
# Show help
node dist/index.js --help
# Available options:
--transport=<stdio|http> Transport type (default: stdio)
--port=<number> Port for HTTP transport (default: 3300, or MCP_HTTP_PORT env var)
--host=<ip-address> Host for HTTP transport (default: localhost, or MCP_HTTP_HOST env var)
--help, -h Show help message
Environment Variables: Default values for --port and --host can be configured using MCP_HTTP_PORT and MCP_HTTP_HOST environment variables in your .env file.
Testing HTTP Transport
Test the HTTP transport using the included test script:
# Start server with HTTP transport
node dist/index.js --transport=http
# In another terminal, run the test
node tests/integration/test-streamable-http.js
MCP Integration
Prerequisites
- Install the MCP server globally:
npm install -g @dav3/mcp-dynamics365-server
Option 1: Manual Configuration (Recommended)
The standard approach is to add the server to your MCP client configuration:
- Add to your MCP client configuration (see examples below)
Option 2: VS Code Extension (Recommended for VS Code Users)
🚀 For the best VS Code experience, use the dedicated extension:
- Install the VS Code extension:
dav3.mcp-dynamics365-extension - Configure credentials: Use the "Configure MCP Dynamics 365 Server" command
- Start HTTP server: Use "Start HTTP Server" command (automatic for production, local dev mode for developers)
📖 Full extension documentation: See vscode-extension/README.md for:
- Development vs Production command modes
- Auto-detection features
- Advanced configuration options
- Troubleshooting guides
Note: The extension uses HTTP transport by default and provides intelligent command visibility based on your environment (development vs production).
Configuration Examples
You can connect to the MCP server in two ways:
Local Server (Stdio Transport)
This runs the server locally and connects via stdio (standard input/output):
For VS Code
Add to your mcp.json or settings.json:
mcp.json (personally tested)
{
"servers": {
"dynamics365-crm": {
"command": "npx",
"args": ["@dav3/mcp-dynamics365-server"],
"env": {
"D365_CLIENT_ID": "your_client_id",
"D365_CLIENT_SECRET": "your_client_secret",
"D365_TENANT_ID": "your_tenant_id",
"D365_BASE_URL": "https://your-org.crm.dynamics.com",
"D365_RESOURCE": "https://your-org.crm.dynamics.com"
}
}
},
"inputs": []
}
settings.json (untested)
{
"mcp.servers": {
"dynamics365": {
"command": "npx",
"args": ["@dav3/mcp-dynamics365-server"],
"env": {
"D365_CLIENT_ID": "your_client_id",
"D365_CLIENT_SECRET": "your_client_secret",
"D365_TENANT_ID": "your_tenant_id",
"D365_BASE_URL": "https://your-org.crm.dynamics.com",
"D365_RESOURCE": "https://your-org.crm.dynamics.com"
}
}
}
}
For Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"dynamics365-crm": {
"command": "npx",
"args": ["@dav3/mcp-dynamics365-server"],
"env": {
"D365_BASE_URL": "https://your-org.crm.dynamics.com",
"D365_CLIENT_ID": "your-client-id",
"D365_CLIENT_SECRET": "your-client-secret",
"D365_TENANT_ID": "your-tenant-id",
"D365_RESOURCE": "https://your-org.crm.dynamics.com"
}
}
}
}
Note: Environment variables must be explicitly specified in the MCP configuration. The server does not automatically load .env files when run via MCP clients.
Available Tools
📋 Naming Convention:
- Metadata operations (
get_entity_schema,get_attribute_schema): Use singular entity logical names (e.g.,"contact","account")- Data operations (
query_entities,get_entity,create_entity, etc.): Use plural entity set names (e.g.,"contacts","accounts")
1. get_entity_schema
Get the schema/metadata for a specific Dynamics 365 entity.
Parameters:
entityName(string): The entity logical name in singular form (e.g., "contact", "account")
Example:
{
"entityName": "contact"
}
2. list_entities
List all available entity sets in Dynamics 365.
Parameters:
includeSystem(boolean, optional): Whether to include system entities
Example:
{
"includeSystem": false
}
3. query_entities
Query entities with flexible filtering, sorting, and selection options.
Parameters:
entitySet(string): The entity set nameselect(array, optional): Fields to selectfilter(string, optional): OData filter expressionorderby(string, optional): OData orderby expressiontop(number, optional): Maximum number of recordsskip(number, optional): Number of records to skipexpand(string, optional): Related entities to expand
Example:
{
"entitySet": "contacts",
"select": ["firstname", "lastname", "emailaddress1"],
"filter": "firstname eq 'John'",
"orderby": "createdon desc",
"top": 10
}
4. get_entity
Get a specific entity record by ID.
Parameters:
entitySet(string): The entity set nameid(string): The entity ID (GUID)select(array, optional): Specific fields to retrieve
Example:
{
"entitySet": "contacts",
"id": "12345678-1234-1234-1234-123456789abc",
"select": ["firstname", "lastname"]
}
5. create_entity
Create a new entity record.
Parameters:
entitySet(string): The entity set namedata(object): The entity data to create
Example:
{
"entitySet": "contacts",
"data": {
"firstname": "John",
"lastname": "Doe",
"emailaddress1": "john.doe@example.com"
}
}
6. update_entity
Update an existing entity record.
Parameters:
entitySet(string): The entity set nameid(string): The entity ID (GUID)data(object): The entity data to update
Example:
{
"entitySet": "contacts",
"id": "12345678-1234-1234-1234-123456789abc",
"data": {
"emailaddress1": "john.doe.updated@example.com"
}
}
7. delete_entity
Delete an entity record.
Parameters:
entitySet(string): The entity set nameid(string): The entity ID (GUID)
Example:
{
"entitySet": "contacts",
"id": "12345678-1234-1234-1234-123456789abc"
}
8. execute_odata_query
Execute a custom OData query directly.
Parameters:
query(string): The OData query string
Example:
{
"query": "contacts?$filter=firstname eq 'John' and lastname eq 'Doe'&$select=contactid,fullname"
}
9. execute_function
Execute a Dynamics 365 function or action.
Parameters:
functionName(string): The function or action nameparameters(object, optional): Function parametersmethod(string, optional): HTTP method (GET, POST, PATCH, DELETE)
Example:
{
"functionName": "WhoAmI",
"method": "GET"
}
Common Entity Sets
accounts- Account recordscontacts- Contact recordsleads- Lead recordsopportunities- Opportunity recordscases- Case recordstasks- Task recordsappointments- Appointment recordsemails- Email recordsphonecalls- Phone call records
OData Query Examples
Basic Filtering
contacts?$filter=firstname eq 'John'
Multiple Conditions
contacts?$filter=firstname eq 'John' and lastname eq 'Doe'
Selecting Specific Fields
contacts?$select=firstname,lastname,emailaddress1
Ordering Results
contacts?$orderby=createdon desc
Limiting Results
contacts?$top=10&$skip=20
Expanding Related Records
contacts?$expand=parentcustomerid
Error Handling
The server provides comprehensive error handling:
- Authentication errors are logged and returned with appropriate messages
- API errors include status codes and detailed error descriptions
- Validation errors for missing required parameters
- Network and timeout errors are handled gracefully
Security Considerations
- Store sensitive credentials in environment variables
- Use least-privilege principle for Azure AD app permissions
- Implement IP restrictions if needed
- Monitor and log access patterns
- Rotate client secrets regularly
Contributing
For detailed development guidelines and conventions, see copilot-instructions.md.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Development Setup
# Install dependencies
pnpm install
# Build the project
pnpm run build
# Run tests
pnpm run test:read-tools
# Type checking
pnpm run typecheck
Support
For issues and questions:
- Check the troubleshooting section below
- Review Dynamics 365 Web API documentation
- Create an issue in the repository
Troubleshooting
Authentication Issues
- Verify client ID, secret, and tenant ID
- Check Azure AD app permissions
- Ensure the app has been granted admin consent
- Verify the resource URL matches your Dynamics 365 instance
Connection Issues
- Check the base URL format
- Verify network connectivity
- Check firewall and proxy settings
- Validate SSL certificates
Query Issues
- Review OData syntax
- Check entity and field names (case sensitive)
- Verify entity permissions
Contributing & Support
This project was generated with AI assistance as a side project. While contributions are welcome, please note:
- Limited Maintenance: This project may not receive regular updates or active maintenance
- Community Driven: The community is encouraged to fork and maintain their own versions
- Best Effort Support: Issues will be addressed on a best-effort basis when time permits
- Pull Requests: Well-documented PRs are welcome, but review times may vary
If you need reliable, maintained software for production use, consider:
- Forking this repository and maintaining your own version
- Contributing to make this project more robust
- Looking for alternative commercial solutions
AI Generation Notice
This project was created with the assistance of AI tools. While the code has been reviewed and tested, users should:
- Thoroughly test in their own environments
- Review code for security implications
- Understand the functionality before production use
License
MIT License - see LICENSE file for details.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。