Exposing A Custom Class to Dynamics 365 MCP Server
Breaking the Forms: Direct Code Invocation for Agents in
Finance & Operations Apps
Most AI agents interacting with enterprise ERPs—like
Microsoft Dynamics 365 Finance & Operations—operate like super-fast human
users. They navigate forms, click buttons, and fill in fields. This "form
interaction" pattern is powerful because it instantly makes millions of
existing UI-based actions available to your AI.
But what if the business logic you need isn't on a form? Or
what if navigating a complex wizard is too slow and fragile for a critical
backend process?
This is where the find_actions and invoke_action
tools shine. They allow developers to bypass the UI layer entirely and expose
direct code execution to the Model Context Protocol (MCP) server.
The "Escape Hatch": Direct Code Access
While standard MCP tools rely on form metadata, find_actions
and invoke_action are special. They act as a bridge directly to your
application's X++ classes.
- find_actions:
Allows the agent to query the system and discover which custom code
classes are available for it to use.
- invoke_action:
Allows the agent to trigger a specific class and pass parameters directly
to it.
This capability is essential for scenarios where complex
calculation engines, heavy data processing, or headless business logic need to
be triggered by an AI agent without a user interface.
How it Works: The Architecture
To make a piece of code accessible to an agent, you don't
just "open up" the codebase. You follow a structured framework to
ensure security and discoverability.
The Workflow:
- Developer
Action: A developer writes a class in the Finance & Operations app
that implements the ICustomAPI interface.
- Security:
The class is associated with a Menu Item. The security roles assigned to
that Menu Item determine who (and which agents) can call it.
- Registration:
The class is registered as an AI Tool in the Synchronize Dataverse
Custom APIs form.
- Discovery:
The MCP Server uses find_actions to see this registered class.
- Execution:
The Agent uses invoke_action to run the code.
Developer Guide: Exposing Your Logic
If you are a developer looking to build these tools, here is
the high-level checklist:
1. Implement ICustomAPI
Your X++ class must implement this specific interface. This
standardizes the input/output structure so the AI agent knows exactly how to
talk to your code.
2. Security is Key
Just because it's code doesn't mean it bypasses security.
You must link your class to a Menu Action Item.
- If the
agent's user account doesn't have access to that Menu Item, find_actions
will return nothing, and invoke_action will fail.
- This
leverages the standard Role-Based Security (RBS) of Finance &
Operations.
3. Sync to Dataverse
Once your code is ready and secured, it needs to be
"advertised." You do this via the Synchronize Dataverse Custom
APIs (CustomApiTable) form.
- Classes
that are correctly configured will appear in this list.
- Syncing
them makes them visible to the outside world (the MCP Server).
Summary
|
Feature |
Standard MCP Tools |
invoke_action Tools |
|
Interaction Type |
UI / Form-based |
Direct Code Execution |
|
Best For |
Data entry, standard workflows |
Complex logic, calculations, headless processes |
|
Setup |
Zero-code (uses existing forms) |
Pro-code (requires X++ development) |
|
Security |
Form permissions |
Menu Item permissions |
By using invoke_action, you move beyond "simulating a
user" to "integrating with the core," giving your agents the
ability to perform complex, high-speed operations that go far beyond what a
human could do on a screen.

Comments
Post a Comment