
While getting ready to present my session on ‘Mining D365 F&SC Data with AI for Administration Wins’ at the upcoming Convergence conference, I had the opportunity to take a second look at two previous AI focused projects / blog posts I made earlier this year. As I started going through them both I quickly realized how much had changed in the 10+ months since I had written them. I thought it would be useful to make a post update on the changes I encountered and why those changes were necessary.
Revisiting AI Data Analysis in D365FSC: Opus 5.5, the Official C# SDK, and Lessons from a $5 Mistake
Back in January I wrote about automating AI data analysis in D365FSC: a .NET console app that pulls user and security role data out of D365 through OData, drops it into an Excel file, and hands that file to Claude to look for cleanup opportunities. It worked well, and at roughly $0.40 to $0.50 per run it was cheap enough to play with.
A lot has changed in the AI world since January (which in AI years is roughly a decade). I’m using this project as the example in my upcoming session at Microsoft Convergence, so I wanted to bring it up to date before showing it to a room full of people. That meant moving to the current Claude model, Opus 5.5, switching from hand-rolled HTTP calls to Anthropic’s official C# SDK, and, as it turned out, learning a $5 lesson about context windows.
Let’s look at what changed.
What Changed
The D365 side of the app (authentication, the OData queries, the Excel export) mostly stayed the same. The Claude side got rebuilt:
| Area | January version | Updated version |
|---|---|---|
| Claude connection | Hand-built HttpClient calls and JSON payloads |
Official Anthropic C# SDK (Anthropic on NuGet) |
| Model | Claude Sonnet 4 | Claude Opus 5.5 |
| Beta features | Files API and code execution behind beta headers | Both generally available, no beta headers |
| Response handling | One blocking request, results at the end | Streaming, with Claude’s reasoning and each sandbox step shown live |
| Files Claude creates | Only visible in the Claude Console | Downloaded to a local output folder |
| Uploaded D365 data | Left in the Files API | Expires automatically and is deleted after the run |
| API key | Stored in App.config | ANTHROPIC_API_KEY environment variable, with App.config as a fallback |
| .NET version | .NET 8 | .NET 10 (.NET 8 reached end of support in November 2026) |
Moving to the Official C# SDK
The original version talked to the Claude API with a hand-rolled HttpClient, Newtonsoft JSON classes, and a couple of beta headers. It worked, but it meant I owned the request format, the retries, and every breaking change.
Anthropic now publishes an official C# SDK on NuGet, simply called Anthropic. Swapping to it removed most of that plumbing. The SDK handles authentication, retries with backoff, timeouts, and typed request and response models. It also reads your API key from the ANTHROPIC_API_KEY environment variable by default, so the key no longer has to live in a config file.
The heart of the request now looks like this:
var parameters = new MessageCreateParams
{
Model = "claude-opus-5-5",
MaxTokens = 32000,
System = systemPrompt,
Messages = [.. messages],
Thinking = new ThinkingConfigAdaptive { Display = Display.Summarized },
OutputConfig = new OutputConfig { Effort = Effort.Medium },
Tools = [new CodeExecutionTool20260521()],
};
The D365 export still gets uploaded through the Files API, and it’s attached to the message as a ContainerUploadBlockParam. That mounts the file inside Claude’s code execution sandbox, where Claude opens it with Python and pandas instead of converting it to text first.
Opus 5.5: Thinking and Effort
A few things to know if you’re moving an older project to Opus 5.5:
- Raise max tokens. Thinking counts against the output limit, so the 4,096 I used in January is far too small. A value of 32,000 is fairly standard now.
- Always remember to correctly use effort. Opus 5.5 always thinks before it answers, a feature Anthropic calls adaptive thinking. You can’t turn it off; instead you set an
effortlevel (low, medium, high, xhigh or max) that controls how hard Claude works on the problem. I made effort a setting in App.config, which turned out to be handy: I uselowwhile tweaking prompts andmediumfor the real run. - Read responses by block type. A response can start with thinking blocks, so grabbing “the first block” as the answer no longer works.
The bigger max token value had a side effect I didn’t expect. The SDK refuses non-streaming requests that could run longer than 10 minutes, so I had to switch to streaming. That ended up having a subtle change that I ended up liking a lot. With the thinking display set to summarized, Claude’s reasoning now scrolls by in the console as it works, along with each command it runs in its sandbox. For a live demo, watching Claude reason through your security data beats staring at a spinner.
File Output (Finally Done Right)
In the first version, the Excel workbooks Claude created only showed up in the Claude Console, so I had to go download them by hand. Now the app brings them home automatically.
The trick is a folder in Claude’s sandbox exposed as $OUTPUT_DIR. Files Claude saves there come back in the response as file IDs, and the app downloads each one through the Files API. Every prompt now ends with a short instruction telling Claude to save its deliverables there.
Each run gets its own folder, so the output looks like this:
D365_Data_Export.xlsx: the raw data pulled from D365Claude_<timestamp>\: Claude’s written summary as Markdown, plus every file it created (workbooks, HTML pages, charts)
Since this is security data, I also tightened up cleanup. The uploaded export now has an expiration set when it’s uploaded (24 hours by default), so it disappears from Anthropic’s side even if the app crashes. When a run finishes, the app deletes the upload and the generated files from the Files API too.
The $5 Mistake
With everything working, I got ambitious. I updated the prompt to ask Claude for an interactive web page with modern charts presenting a waved remediation plan. A few minutes later the run died with this:
prompt is too long: 1044290 tokens > 1000000 maximum
My export is 38 KB: 134 users, 288 roles and 536 role assignments. There is no way that data adds up to a million tokens. So what happened?
Everything Claude does in its sandbox becomes part of the conversation: every line a command prints, and the full text of every file it writes or reads back. Because I didn’t have great logging (see the top safety net I added below) my best guess is that Claude, with no internet in its sandbox, pasted an entire charting library into the HTML page, then looked at the file to check its work. And because each sandbox step re-reads the whole conversation, a bloated context gets expensive fast. That one failed run cost about $5, roughly ten times a normal January run, and produced nothing.
Lesson learned. I added two safety nets:
- Step-by-step logging. The console now shows each command Claude runs (
bash: python analyze.py) and how much each step returned. Any step over about 100 KB gets a yellow warning, so the culprit is obvious. - A spending guard. The app estimates the context size as the response streams in. If it passes a budget (200K tokens by default, set in App.config), it stops the run and tells you which step blew up. That’s a few cents wasted instead of a few dollars.
Splitting the Work in Two
The other frustration was that a failed run can’t be resumed. Claude never finished its turn, so there was nothing to pick back up, and I had to pay for the whole analysis again.
So I split prompts into two steps:
- Analysis. Claude crunches the D365 data and saves its results as a small
findings.jsonfile: every count, list and recommendation the final report needs. - Presentation. A separate request builds the dashboard from
findings.jsonalone, without the source data.
The analysis is the cheap, reliable part. The dashboard is where things go sideways, and now it’s isolated. A new R option in the prompt menu re-runs only the presentation step from the latest saved findings. If the page comes out wrong, or I just want to tweak the design before a presentation, I only pay for that small step.
Writing Token-Aware Prompts
The biggest savings came from the prompt itself. When I looked at my export closely, I found three things sending Claude off exploring:
- Column names didn’t match. My prompt said
USERID, but the sheets useUserIDin one place andUserIdin another. The app now builds a description of the workbook automatically (each sheet’s row count, exact column names, and the OData filter behind it) and puts it at the top of the prompt. - Noise columns. Every sheet had an
@odata.etagcolumn, which is useless for analysis. The export now drops it. - Undefined terms. I asked for “enabled users” without saying my OData query already filters to enabled users, so Claude went hunting for an Enabled column that doesn’t exist.
A few other habits that keep runs small:
- Tell Claude how to work, not just what to find. “Compute everything in a single script and print only a short summary” turns a dozen exploratory steps into one.
- Make the design decisions yourself. Name the KPIs, the chart, and the library (Chart.js from a CDN). Every open choice costs thinking tokens and extra steps.
- Say how to check the work. “Check the result with
ls -laonly” keeps Claude from reading a large file back into the conversation. - Tune cheaply. Iterate with effort set to
lowor a smaller model, then switch back to Opus 5.5 for the real run.
GitHub Project
The updated code is on GitHub: https://github.com/ameyer505/ClaudeD365Analyzer
Same warnings as last time: the project is provided as-is, without support, and please don’t commit your App.config file, since it holds your D365 client secret (and your Claude API key, if you put it there). Better yet, set the key in the ANTHROPIC_API_KEY environment variable and leave it out of config files entirely.
Seeing It In Action
Executing the application now gathers the necessary data from D365 and waits for the prompt (note: currently the data being gathered is specific to the User Role Analysis prompt but could be expanded to other prompts by adding additional data entities):

With the user role analysis selected, you now get to see the individual steps the LLM is performing:

You can also review the findings of the analysis:
And because I broke out the analysis portion, you get to see how its generated as well:
Here is the finished dashboard that was generated based on results:
Refreshing my D365 F&SC Security MCP Server
Back in April, I wrote about connecting Claude to D365 F&SC with MCP. The short version: we built a small .NET MCP server, pointed it at the D365 OData endpoint, and gave Claude the keys. It had four tools (GetUsers, GetSecurityRoles, GetUserRoleAssignments and a generic RunODataQuery fallback) and it worked well enough to ask Claude real questions about users and roles.
Eight months is a long time in MCP land. The protocol has moved on, the C# SDK has moved on, and I’ve spent a good chunk of the year refining a set of native security data entities in a separate D365 Security Expert project (which I plan on releasing soon so stay tuned!). So I sat down to give the server a refresh.
What started as “bump a few NuGet packages” turned into a near rewrite. The April version could tell you what roles a user has. The new version can tell you what that actually means: who can pay vendors, which roles and users are potentially over assigned, and which SoD rules are being violated right now. This post walks through what changed, what I learned along the way (a few of those lessons were humbling), and what it looks like against a real environment.
What changed under the hood
The server now targets the July 2026 MCP specification (2026-07-28) through version 2.4.0 of the official C# SDK, running on .NET 10. Here’s the before and after at a glance:
| Area | April version | Now |
|---|---|---|
| MCP spec / SDK | ModelContextProtocol 1.1.0 | 2.4.0, spec 2026-07-28 |
| Runtime | .NET 9 | .NET 10 (LTS) |
| Tools | 4 thin wrappers | 15 task-shaped tools, plus 4 prompts and a reference resource |
| Data | Users, roles, role assignments | The 9 native security entities |
| Auth | MSAL client secret in appsettings.json | Azure.Identity: secret, certificate, Azure CLI, managed identity |
| OData | Single request, no retries | Paging, row caps, 429 retry with Retry-After |
A few of these deserve more than a table row.
Tools now describe themselves properly. Every tool is annotated as read-only, idempotent and non-destructive, and gets a human-readable title. That tells Claude (and any other MCP client) up front that nothing here will change data. For a security tool pointed at a production ERP, that’s not a nice-to-have.
Structured output. Tools now return typed results with a published output schema, instead of a blob of JSON text and a hope. Clients can validate what comes back, and as you’ll see in the lessons-learned section, they absolutely do.
Prompts and resources. MCP servers can ship reusable prompts, not just tools. The server now includes four review workflows (user access review, SoD review, license optimization and role design review) that tell Claude which tools to use and in what order. The result is a review that comes out the same shape every time, instead of depending on how the question was worded that day.
Secrets out of the config file. In April the client secret lived in appsettings.json. That works right up until someone runs git commit -a. The server now uses Azure.Identity, so the secret can live in .NET user-secrets or an environment variable. For anything long-lived, you can switch to a certificate or a managed identity and skip secrets entirely.
Reliability. D365 throttles busy integrations with a 429 and a Retry-After header. The new OData client respects that, follows server-driven paging, caps how many rows a single question can pull, and caches the access token instead of requesting a new one on every call. The April version, it turns out, was quietly creating a brand-new authentication client per request. Not a strategy.
Going native: the security data entities
The biggest upgrade isn’t the protocol, it’s the data. D365 F&SC ships a set of System* security data entities that expose the whole security model: users, roles, sub-roles, duties, privileges, object-level permissions and segregation of duties. I’d been using them in a data management export project for the Security Expert work, and they turned out to be exactly what the MCP server was missing.
| Data entity | OData entity set | What it gives Claude |
|---|---|---|
| SystemUserEntity | SystemUsers | User accounts, enabled flag, company |
| SystemSecurityUserRoleAssociationEntity | SecurityUserRoleAssociations | Who has which role, manual or automatic, enabled or disabled |
| SystemSecurityRoleEntity | SecurityRoles | The role catalog, including the license type each role declares |
| SystemSecuritySubRoleEntityV2 | SecuritySubRolesV2 | Roles nested inside other roles |
| SystemSecurityRoleDutyEntity | SecurityRoleDuties | Duties per role, which is where SoD lives |
| SystemSecurityPrivilegeEntity | SecurityPrivileges | Privileges per role |
| SystemSecurityPermissionEntity | SecurityPermissions | Object-level access: Read, Update, Create, Delete, Correct, Invoke |
| SystemSegregationOfDutiesConflictEntity | SegregationOfDutiesConflicts | SoD conflicts D365 has logged |
| SystemSegregationOfDutiesRuleEntity | Not published to OData | The SoD rules themselves (more on this later) |
Notice the two middle columns don’t match. The name you see in Data management is not the name you use over OData. I learned this the fun way: I put the data entity names in the config file, every call returned a 404, and the old code happily reported all nine entities as “ok” because it never actually checked.
So the server no longer trusts names, including mine. On first use it reads the OData service document, tries the known entity set names, falls back to a keyword search, and then probes each candidate for the fields it needs. A look-alike entity with the wrong shape gets rejected. It even learns field casing from the live response, because SystemUsers uses UserID while every other entity uses UserId. D365 keeps us humble.
One more practical detail: the small, slow-changing entities (users, roles, assignments, duties) are cached for 15 minutes. The privilege and permission entities can run to hundreds of thousands of rows, so those are always filtered by role or object on the D365 side and never pulled whole.
From table wrappers to security questions
The April tools mapped one-to-one to OData tables. That works, but it leaves Claude doing the joins in its head: fetch the user, fetch their roles, fetch the sub-roles, fetch the duties, then reason about all of it. Every step costs tokens and is another chance to get something wrong.
The new tools are shaped around the questions a security reviewer actually asks:
| Tool | The question it answers |
|---|---|
get_user_access_profile |
What can this user actually do, and is it risky? |
find_access |
Who can do X? (a role, duty, privilege, or a specific table or menu item) |
evaluate_sod |
Which SoD rules are being violated right now, by whom, and through which roles? |
get_license_summary |
Which roles are pushing users onto Enterprise licenses? |
compare_roles |
How far has our copied role drifted from the standard one? |
get_role_details, get_role_privileges, get_role_permissions |
What does this role really contain, including nested sub-roles? |
search_users, list_security_roles, list_sod_rules, list_sod_conflicts |
Lookups and catalogs |
get_server_status, discover_entity_sets, run_odata_query |
Connectivity checks, discovery and a read-only escape hatch |
My favorite is find_access. Ask it who can maintain vendor payments and it finds every role that grants the duty, adds every role that contains one of those as a sub-role, and returns every user holding any of them. It lists System administrators separately, because “everyone with SysAdmin” is technically correct and practically useless as an answer.
The RunODataQuery escape hatch from April is still there as run_odata_query, with guardrails. It only issues GET requests, it only talks to the configured environment, and it refuses $batch and $metadata. If you’ve ever downloaded the D365 $metadata document, you know why that last one is a kindness.
Seeing the MCP in Action
I first had to add the custom MCP to Claude itself, which lists the new tools that are available:
Once configured, I gave Claude the same input that I gave the automated AI data analysis above:
Just like in the automated AI analysis solution above, Claude Desktop automatically does show its thinking so we get to see how its actually analyzing data via the MCP:
The output from the MCP is fairly similar to the automated AI analysis from above but does seem to be able to give more details because of the additional data entities it has access to:
A few highlights:
- 18 System administrators. 13 are people; the rest are Microsoft-provisioned service apps that legitimately need it.
- 49 role assignments pointing at 16 users who no longer exist. If one of those user IDs is ever re-created, it quietly inherits the old roles.
- A “read-only” role that isn’t. A custom role named
Read_Only_Sys_Configurationgrants Read onSysSecConfiguration, and nothing else. If you read my earlier post on the Security configuration form, you know Read on that object lets the holder edit and publish security. The name says read-only. The access says otherwise. - 27 enabled users with no roles, 14 of them named people, which is usually a leaver nobody disabled.
None of these needed a new tool. They came from Claude combining the building blocks it already had.
Wrapping up
This updated version of the MCP makes the conversation worth having: native security data, tools shaped around real review questions, and output a client can trust and validate. It’s still read-only by design. Claude can find the problems, but a person still makes the changes.
If you’re running the April version, the upgrade path is straightforward:
- Pull the latest code and rebuild on .NET 10.
- Move your client secret into user-secrets, or switch to a certificate.
- Leave the entity set overrides blank and let discovery do its job.
- Run
get_server_statuswithvalidate=truebefore anything else.
On my list for next time:
- A small extension to publish the SoD rules entity to OData, so the SoD tools get severity, risk and mitigation.
- Remote hosting over HTTP with proper authentication, which is a whole post (and a conference session) on its own.
The code is on GitHub: https://github.com/ameyer505/D365FSC-Security-MCP
As always, I’d love to hear what you build with it, and which security question you’d want answered next.
Conclusion
If you’re attending the Microsoft Convergence conference, feel free to come check out my session, where I’ll walk through these projects live!







