Skip to content

MCP server for Microsoft Dynamics 365 Business Central via reverse-engineered WebUI protocol. Enables AI assistants like Claude to interact with BC through the native WebSocket interface.

License

Notifications You must be signed in to change notification settings

SShadowS/bc-webclient-mcp-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ BC WebClient MCP

Model Context Protocol server for Microsoft Dynamics 365 Business Central via WebUI protocol

npm version npm downloads License: MIT TypeScript Node.js MCP

Features β€’ Quick Start β€’ Tools β€’ Documentation β€’ Architecture


πŸ“– Overview

BC WebClient MCP is a Model Context Protocol (MCP) server that enables AI assistants like Claude to interact with Microsoft Dynamics 365 Business Central through a clean, intuitive interface. Built by reverse-engineering BC's WebUI WebSocket protocol, it provides real-time access to ERP data, business logic, and operations.

What is MCP?

The Model Context Protocol is an open standard that enables AI assistants to securely connect with external data sources and tools. This server implements MCP to bridge Claude with Business Central's internal APIs.

Why This Matters

Business Central's web client uses an undocumented WebSocket protocol for all UI operations. This project reverse-engineers the WebUI protocol (not official APIs) to:

  • βœ… Enable AI-driven ERP automation - Let Claude interact with BC data naturally
  • βœ… No custom extensions required - Works with vanilla BC installations
  • βœ… Real-time operations - Leverage BC's live WebSocket connection
  • βœ… Production-ready - Built on BC's actual internal protocol (the same one the web UI uses)

✨ Features

Version 2.5 Highlights

  • Workflow Tracking - Track multi-step business processes with start_workflow, get_workflow_state, end_workflow
  • Dialog Handling - Full handle_dialog tool for template selection, confirmations, and prompts
  • Document Line Items - Write to subpages/repeaters with subpage, lineBookmark, lineNo parameters
  • Document Pages - Full support for Sales Orders, Purchase Orders with header + line items
  • MCP Resources - Access BC schema, workflows, and session state
  • MCP Prompts - Guided workflows for common operations
  • Multi-Page Support - Card, List, and Document pages all work reliably

πŸ” Discovery & Search

  • Tell Me search integration (Alt+Q)
  • Page metadata extraction
  • Field and action discovery
  • Dynamic form inspection

πŸ“Š Data Operations

  • Read page data in real-time
  • Filter and query list pages
  • Create and update records
  • Execute page actions
  • NEW: Document pages with line items

πŸ” Authentication

  • Session-based web authentication
  • Support for all BC auth types
  • CSRF token management
  • Automatic session handling

⚑ Performance

  • Event-driven architecture
  • Gzip compression support
  • Connection pooling ready
  • Efficient state management

πŸš€ Quick Start

Get up and running with BC WebClient MCP in 5 minutes.

Prerequisites

  • Node.js 18 or higher (Download)
  • Business Central v27.0 (other versions may work but are not tested - protocol specifics are BC 27)
  • Valid BC credentials with web client access
  • Claude Desktop (Download) or any MCP-compatible client

Step 1: No Installation Required!

The MCP server runs directly via npx - no installation needed. Just configure Claude Desktop in the next step.

Step 2: Configure Claude Desktop

Find your Claude Desktop config file:

  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

Edit the config file and add the MCP server (replace with your BC credentials):

{
  "mcpServers": {
    "business-central": {
      "command": "cmd",
      "args": [
        "/c",
        "npx",
        "bc-webclient-mcp@latest"
      ],
      "env": {
        "BC_BASE_URL": "http://your-bc-server/BC/",
        "BC_USERNAME": "your-username",
        "BC_PASSWORD": "your-password",
        "BC_TENANT_ID": "default"
      }
    }
  }
}

Note: On macOS/Linux, use "command": "sh" and "args": ["-c", "npx bc-webclient-mcp@latest"] instead.

Why npx?

  • βœ… No installation required - runs directly from npm
  • βœ… Always uses the latest version automatically
  • βœ… No need to manage global packages

Important notes:

  • Use BC_USERNAME=username, NOT domain\username
  • The tenant is handled automatically in the URL parameter
  • For BC Online, use your full BC URL (e.g., https://businesscentral.dynamics.com/...)

Step 3: Restart Claude Desktop

Restart Claude Desktop completely to load the MCP server.

Step 4: Verify It's Working

Open a new chat in Claude Desktop and try:

Search for customer pages

You should see Claude using the search_pages tool and returning BC pages. If the MCP server appears in the tools list (πŸ”§ icon), you're all set!

πŸŽ‰ What You Can Do Now

Try these commands to explore v2 capabilities:

Document Pages with Line Items:

Read Sales Order 101001 with all line items

Smart Search:

Find all pages related to inventory management

Resources (Schema Discovery):

What BC pages are available?

(Uses the bc://schema/pages resource)

Guided Workflows (Prompts):

Create a new customer named Acme Corporation

(Uses the create_bc_customer prompt for step-by-step guidance)

Data Operations:

Show me customers where balance is over 10000

Field Updates:

Update customer 10000's credit limit to 50000

πŸ”§ Quick Troubleshooting

MCP server not showing up in Claude Desktop?

  • Check the config file syntax is valid JSON
  • Restart Claude Desktop completely (close all windows)
  • Verify Node.js is installed: node --version (requires 18+)
  • Check Claude Desktop logs: View β†’ Developer β†’ Toggle Developer Tools β†’ Console

Connection failed?

  • Verify BC is accessible: Open http://your-bc-server/BC/ in a browser
  • Check BC_BASE_URL includes the /BC/ path
  • Ensure firewall allows WebSocket connections

Authentication error?

  • Test login in browser first
  • Use username WITHOUT domain prefix (just username)
  • Verify tenant ID matches your BC installation (default for on-prem)

"TypeScript errors" when building?

  • Run npx tsc --noEmit to see detailed errors
  • Ensure Node.js version is 18 or higher: node --version

For more troubleshooting, see CLAUDE.md

πŸ“¦ Alternative: Install from Source

For development, testing unreleased features, or contributing to the project:

# Clone the repository
git clone https://github.com/SShadowS/bc-webclient-mcp-server.git
cd bc-webclient-mcp-server

# Install dependencies
npm install

# Build the TypeScript project
npm run build

Then in Claude Desktop config, use the local path:

{
  "mcpServers": {
    "business-central": {
      "command": "node",
      "args": ["C:\\path\\to\\bc-webclient-mcp-server\\dist\\index.js"],
      "env": {
        "BC_BASE_URL": "http://your-bc-server/BC/",
        "BC_USERNAME": "your-username",
        "BC_PASSWORD": "your-password",
        "BC_TENANT_ID": "default"
      }
    }
  }
}

Note: Use full absolute paths with double backslashes on Windows.


Available Tools

The MCP server provides 10 tools for AI interaction:

Core Tools (7)

Tool Description Level
search_pages Search for pages using Tell Me (Alt+Q) Discovery
get_page_metadata Get page structure, fields, and actions Discovery
read_page_data Read data from a page (with server-side filtering) Read
write_page_data Write field values with validation, supports subpage/line operations Write
execute_action Execute page actions (New, Edit, Post, etc.) Action
select_and_drill_down Navigate between pages via drill-down Navigation
handle_dialog Handle BC dialogs (template selection, confirmations) Dialog

Workflow Tools (3)

Tool Description
start_workflow Begin tracking a multi-step business process
get_workflow_state Query workflow state, history, and unsaved changes
end_workflow Complete workflow with final status

Optional/Advanced Tools

Tool Description
create_record_by_field_name Create records using field names (convenience wrapper)

Tool Architecture

The MCP server provides tools at multiple levels:

Core Tools - Essential primitives for BC interaction:

  • write_page_data - Write fields with immediate validation, subpage/line support
  • execute_action - Execute any page action with auto-resolved controlPath
  • handle_dialog - Handle dialogs with row selection and button clicks

Workflow Tools - Track multi-step business processes:

  • start_workflow β†’ perform operations with workflowId β†’ end_workflow
  • Tracks unsaved changes, operation history, and errors

Convenience Tools - Higher-level wrappers:

  • create_record_by_field_name - Simplified record creation using field names

Example Usage

Once connected, you can interact with Business Central through Claude:

You: "Search for customer-related pages"
Claude: [Uses search_pages tool]
Found 21 customer pages:
- Page 21: Customer Card
- Page 22: Customer List
...

You: "Show me customers where balance is over 10000"
Claude: [Uses read_page_data with filters]
Found 5 customers with balance > 10000:
1. Contoso Ltd - Balance: 15,234.50
2. Fabrikam Inc - Balance: 12,890.00
...

You: "Update customer 10000's credit limit to 50000"
Claude: [Uses get_page_metadata, execute_action("Edit"), write_page_data, execute_action("Save")]
Updated customer successfully:
- Opened Customer Card for customer 10000
- Switched to Edit mode
- Updated Credit Limit: 50,000.00
- Saved changes

You: "Add a line to Sales Order 101001"
Claude: [Uses write_page_data with subpage parameter]
Added line to Sales Order:
- Item No.: 1000
- Quantity: 5
- Line created successfully

πŸ” Security & User Consent

User Consent Flow

This MCP server implements the MCP 2025 user consent requirement to ensure users maintain control over all data-modifying operations.

How It Works

  1. Tool Classification: Each tool is classified by risk level:

    • 🟒 Low Risk (read-only) - No consent required
    • 🟑 Medium Risk (writes) - User approval required
    • πŸ”΄ High Risk (irreversible) - User approval + warning
  2. Consent Enforcement: Claude Desktop shows approval dialog before executing write operations:

    ⚠️  Tool Execution Request
    
    Claude wants to execute: create_record
    
    Create a new record in Business Central?
    This will add data to your Business Central database.
    
    [Deny]  [Allow]
    
  3. Audit Trail: All approved operations are logged with:

    • Timestamp
    • Tool name
    • Input summary (sanitized)
    • Execution result

Tool Consent Requirements

Tool Requires Consent Risk Level Reason
search_pages No Low Read-only discovery
get_page_metadata No Low Read metadata only
read_page_data No Low Read-only data access
start_workflow No Low Creates tracking state only
get_workflow_state No Low Read workflow state
end_workflow No Low Marks workflow complete
write_page_data Yes Medium Direct field writes
select_and_drill_down Yes Medium Navigation with selection
handle_dialog Yes Medium Can bypass safety prompts
create_record_by_field_name Yes Medium Creates new data
execute_action Yes High Can trigger Post/Delete

Audit Log Access

Audit logs are available via structured logging (Pino). Example log entry:

{
  "level": "info",
  "msg": "Tool execution audit",
  "toolName": "create_record",
  "userApproved": true,
  "result": "success",
  "timestamp": "2025-11-08T10:30:45.123Z",
  "inputSummary": {
    "pageId": "21",
    "fields": "[Object]"
  }
}

Sensitive Data Protection: The audit logger automatically redacts passwords, tokens, API keys, secrets, and other credential fields.

For more details, see docs/TOOL-CONSENT-CLASSIFICATION.md and docs/USER-CONSENT-GUIDE.md.


πŸ—οΈ Architecture

Protocol Stack

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     Claude Desktop (AI Client)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚ MCP Protocol
               β”‚ (JSON-RPC over stdio)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         MCP Server (Node.js)        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚   Tool Registry            β”‚    β”‚
β”‚  β”‚   - search_pages           β”‚    β”‚
β”‚  β”‚   - filter_list            β”‚    β”‚
β”‚  β”‚   - get_page_metadata      β”‚    β”‚
β”‚  β”‚   - ...                    β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚               β”‚                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚  BCRawWebSocketClient      β”‚    β”‚
β”‚  β”‚  - Session management      β”‚    β”‚
β”‚  β”‚  - Event-driven handlers   β”‚    β”‚
β”‚  β”‚  - Gzip compression        β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚ WebSocket + JSON-RPC
                β”‚ (BC Internal Protocol)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Business Central Web Service       β”‚
β”‚  /BC/csh endpoint (WebSocket)       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Components

  • BCRawWebSocketClient - Core WebSocket client that mimics browser behavior
  • MCPServer - MCP protocol implementation (JSON-RPC over stdio)
  • BaseMCPTool - Base class for all MCP tools with error handling
  • Protocol Parsers - Decode BC's internal handler arrays
  • Event Emitters - Handle asynchronous BC responses

How It Works

  1. Authentication: Web login flow β†’ Session cookies + CSRF token
  2. WebSocket Connection: Connect to /csh with session credentials
  3. Session Opening: OpenSession request β†’ Extract session identifiers
  4. Event-Driven Operations: Send Invoke requests β†’ Wait for handler arrays
  5. Response Parsing: Decompress gzip β†’ Parse handler structures β†’ Extract data

For deep technical details, see:


πŸ“š Documentation

Quick Reference

  • CLAUDE.md - Essential guide for development and troubleshooting
  • SETUP.md - Step-by-step setup instructions
  • ARCHITECTURE.md - System architecture and design decisions

Deep Dives

External Resources


πŸ§ͺ Development

Project Structure

bc-poc/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ core/                    # Core infrastructure
β”‚   β”‚   β”œβ”€β”€ errors.ts            # Error types and handling
β”‚   β”‚   β”œβ”€β”€ result.ts            # Result monad for error handling
β”‚   β”‚   └── interfaces.ts        # TypeScript interfaces
β”‚   β”œβ”€β”€ services/                # Business logic
β”‚   β”‚   β”œβ”€β”€ BCRawWebSocketClient.ts   # ⭐ Main WebSocket client
β”‚   β”‚   β”œβ”€β”€ mcp-server.ts        # MCP protocol server
β”‚   β”‚   └── stdio-transport.ts   # stdin/stdout JSON-RPC transport
β”‚   β”œβ”€β”€ tools/                   # MCP tool implementations
β”‚   β”‚   β”œβ”€β”€ search-pages-tool.ts
β”‚   β”‚   β”œβ”€β”€ filter-list-tool.ts
β”‚   β”‚   β”œβ”€β”€ get-page-metadata-tool.ts
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ protocol/                # BC protocol parsers
β”‚   β”‚   β”œβ”€β”€ logical-form-parser.ts
β”‚   β”‚   └── handler-types.ts
β”‚   └── types/                   # TypeScript type definitions
β”œβ”€β”€ test/                        # Test scripts
β”œβ”€β”€ docs/                        # Detailed documentation
└── dist/                        # Compiled JavaScript (generated)

Development Commands

# Type checking (run frequently!)
npx tsc --noEmit

# Build the project
npm run build

# Run in development mode
npm run dev

# Run tests
npm test
npm run test:coverage

# Test specific functionality
npm run test:invoke        # Test Invoke method
npm run test:mcp          # Test MCP server

Code Quality Standards

⚠️ NO STUBS POLICY: This is a production codebase. Do NOT create:

  • Stub implementations
  • Mock functions that don't actually work
  • Placeholder code with "not yet implemented" errors
  • Tools that are registered but non-functional

Every feature MUST be fully implemented and functional before being committed.

Testing

# Run all tests
npm test

# Run specific test suites
npm run test:mcp:client          # MCP client integration tests
npm run test:mcp:real           # Real BC integration tests

# Test Tell Me search
npx tsx test-tellme-search.ts "customer"

# Test MCP server with real BC connection
npm run test:mcp:real:client

🀝 Contributing

Contributions are welcome! Please:

  1. Read the architecture documentation first
  2. Follow the existing code style and patterns
  3. Ensure TypeScript compilation passes (npx tsc --noEmit)
  4. Add tests for new functionality
  5. Update documentation as needed

Key Guidelines

  • Use Windows paths when working on Windows
  • Run type checking regularly with npx tsc --noEmit
  • No stubs or mocks - all implementations must be fully functional
  • Read CLAUDE.md for development guidelines
  • Check existing docs before implementing new features

πŸ“‹ Requirements

Supported Business Central Versions

  • βœ… Business Central v27.0 (fully tested and supported)
  • ⚠️ Other versions (v24-v26, v28+) may work but are not tested
    • Protocol specifics are hardcoded for BC 27
    • Older/newer versions may have different WebSocket protocol implementations
    • Use at your own risk - contributions for other versions welcome!
  • βœ… On-Premises installations (BC 27)
  • βœ… Business Central Online (BC 27)

Authentication Support

  • βœ… NavUserPassword (username/password)
  • βœ… Windows Authentication
  • βœ… Azure AD (via web login)

No special BC configuration required! The server mimics browser login behavior.


πŸ› Troubleshooting

Connection Issues

# Test BC connectivity
curl http://your-server/BC/

# Check BC service status (on-prem)
docker exec Cronus27 powershell "Get-Service 'MicrosoftDynamicsNavServer*'"

# Verify WebSocket endpoint
wscat -c ws://your-server/BC/csh

Common Issues

"WebSocket connection failed"

  • Verify BC_BASE_URL is correct and includes /BC/ path
  • Ensure BC web client is accessible in browser first
  • Check firewall rules

"Authentication failed"

  • Test login in browser: http://your-server/BC/
  • Use username WITHOUT domain prefix (just username, not domain\username)
  • Verify tenant ID is correct

"CSRF token not found"

  • Ensure BC web client is accessible
  • Check if BC requires different authentication
  • Clear BC cache and restart services

"OpenSession timeout"

  • Verify tenant ID matches your BC installation
  • Check BC server logs for errors
  • Increase timeout in BCRawWebSocketClient

For more troubleshooting tips, see CLAUDE.md.


πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments

  • Built on Microsoft Dynamics 365 Business Central
  • Implements the Model Context Protocol by Anthropic
  • Inspired by BC's internal Copilot implementation

πŸ“ž Support


⬆ back to top

Made with ❀️ for the Business Central community

About

MCP server for Microsoft Dynamics 365 Business Central via reverse-engineered WebUI protocol. Enables AI assistants like Claude to interact with BC through the native WebSocket interface.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published