web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / D365ERP-AI-Forward / Building a Dynamics 365 Age...

Building a Dynamics 365 Agent with MCP - Part 4: Implement&Validate the Service

Anton Tjiptadi Profile Picture Anton Tjiptadi 2,013

In Part 3, I defined the tool contract: accepted inputs, selected fields, business meaning and explicit outcomes.

The next step is to implement that contract and verify its behavior before connecting the conversational agent.

The capability remains bounded: help an authorized dispatcher retrieve recent customer work orders and inspect a selected record without changing service data.

The implementation must preserve the decisions made during design.

Separate the service responsibilities

I would organize the service around a few clear responsibilities:

ComponentResponsibility
AuthenticationAcquire and manage the backend identity’s tokens
Dataverse clientExecute approved queries and handle source responses
Capability logicApply validation, authorization and business definitions
MCP interfaceExpose the tools and their schemas to clients

These responsibilities can be implemented in a small project. They do not require a separate deployed service for each component.

My earlier LinkedIn article, Building the MCP Server: Turning Designed Capabilities into Executable Tools, describes the original implementation structure. Here, I make the capability logic explicit so its controls can be reviewed and tested.

 

Keep queries inside the contract

For the proposed get_recent_work_orders tool, the service should:

  1. Validate the customer identifier and requested limit.

  2. Confirm that the caller may access the requested customer scope.

  3. Build the approved Dataverse query.

  4. Apply the agreed status filters and creation-date ordering.

  5. Map the response into the selected output fields.

The caller should not supply an unrestricted OData query or choose arbitrary tables and fields.

For get_work_order_details, authorization must be checked again for the selected record. Receiving an identifier from an earlier result does not replace that check.

Preserve business meaning in the response

Avoid returning the entire Dataverse response unchanged.

Map the agreed fields into a stable structure, preserving identifiers, status meaning and timestamp context.

An illustrative result might be:

{
  "outcome": "success",
  "records": [
    {
      "work_order_id": "illustrative-record-id",
      "reference": "WO-1048",
      "created_at": "2026-11-03T07:30:00Z",
      "system_status_label": "Unscheduled"
    }
  ],
  "has_more": false,
  "retrieved_at": "2026-11-03T08:00:00Z"
}

This is a proposed business response, not a raw Dataverse payload or a complete MCP protocol message.

Define has_more precisely and implement the retrieval logic needed to support it. A result limit alone does not establish whether additional matching records exist.

Likewise, preserve distinctions between missing fields, unavailable information and confirmed empty values.

Handle failures deliberately

A timeout must not become a successful response containing an empty list.

Distinguish invalid input, authorization restrictions and source failures. Return a safe, actionable explanation while retaining diagnostic details in protected logs.

For example:

“Work-order retrieval could not be completed because the source request timed out. No conclusion about matching records can be made.”

Set explicit timeouts. Apply bounded retries only to appropriate transient failures, respecting service retry guidance.

Authentication failures and invalid queries need investigation rather than repeated execution.

Test the service directly

Validate in stages so failures can be isolated:

An MCP test client such as MCP Inspector can support tool discovery and controlled invocation.

I explored that checkpoint in Validating the MCP Server: Observing Designed Capabilities in Action. The useful discipline is to inspect requests and responses directly before introducing conversational interpretation.

Verify the read-only boundary

A list of read tools is only one part of the boundary.

Review the underlying client code, backend permissions and reachable operations. Confirm that the capability does not invoke transaction-changing APIs.

Test approved reads alongside malformed identifiers, excessive limits, out-of-scope records and unavailable sources.

Record expected behavior and observed results. One successful call establishes that case; broader reliability requires representative coverage.

Make each request traceable

For investigation, capture:

  • A correlation identifier.

  • Tool name and execution time.

  • Target environment.

  • Safe caller or application identity references.

  • Outcome and error category.

Avoid logging tokens, credentials or unnecessary customer data.

The evidence should help distinguish a failed MCP invocation from an authorization decision or a Dataverse query failure.

What this stage should deliver

Before connecting an agent, I would expect:

  • A running service exposing the intended tools.

  • Responses that match the agreed contract.

  • Evidence for successful and restricted requests.

  • Defined timeout and failure behavior.

  • Traceable execution without sensitive logging.

  • A clear record of remaining limitations.

This establishes a service the agent can use predictably. The next stage is to deploy it with appropriate endpoint protection and configuration, then validate the same boundaries in the hosted environment.

In Part 5, I will examine that deployment boundary before connecting the service to Copilot Studio.

Comments