How to add the Microsoft Learn MCP server for .NET in Claude Code
.NET 11 is out, but Claude Code might not know how to use new C# features such as union types. To help it, you can add the Microsoft Learn MCP server, which lets Claude Code search the official documentation while it writes code.
I added it to a new .NET 11 app, asked Claude Code to create a Minimal API endpoint using C# 15 union types, and then tried the same thing without it.
Why AI models miss new .NET features
Every AI model has a training cutoff date. It doesn't know about anything after that date unless it searches the internet.
When .NET 10 was released last year, Claude still thought that .NET 9 was the latest version, and it wouldn't use any of the new features. I covered this in more detail when Claude added a vulnerable NuGet package to a .NET app.
Newer AI models such as Opus 5.5 are better at searching the .NET SDK to see which features are there. But they still don't always know how to use them properly unless they search the documentation online.
An MCP server can guide Claude Code towards that documentation.
Adding the Microsoft Learn MCP server to Claude Code
I created a new .NET 11 app called RoundTheCode.OrdersApi. Then, in a terminal in the project folder, I ran this command.
claude mcp add --transport http --scope project microsoft_docs_mcp https://learn.microsoft.com/api/mcpThis is run in your terminal, not inside Claude Code. The --scope project option stores the server with the project, so anyone who clones it gets the same setup.
The .mcp.json file
Running the command adds a .mcp.json file to the project. It only stores where the MCP server is.
{
"mcpServers": {
"microsoft_docs_mcp": {
"type": "http",
"url": "https://learn.microsoft.com/api/mcp"
}
}
}What the Microsoft Learn MCP server does
The Learn MCP server gives Claude Code up to date information from Microsoft's official documentation. It has three tools.
microsoft_docs_search- Searches the documentationmicrosoft_docs_fetch- Reads a full articlemicrosoft_code_sample_search- Finds code examples
It's free and doesn't need an account or an API key. Its content is refreshed as the documentation changes, with a full refresh once a day. That means it knows about releases and updates that your AI model doesn't.
Get notified of new content
Join other .NET developers improving their skills and knowledge.
Telling Claude Code to use it
Adding the MCP server doesn't mean Claude Code will use it. To make sure it does, I added this line to the CLAUDE.md file.
Before writing or changing .NET code, search Microsoft Learn with the
microsoft_docs_searchtool to check the current API. Where a skill or this file sets a convention, follow that over the docs.
The second sentence matters if you have your own conventions. Without it, the documentation could take priority over how you want your code written.
A skill for Minimal API endpoints
I also added a skill that sets out how I want Minimal API endpoints structured in this project. Each group of endpoints goes in its own static class in the Endpoints folder, with an extension method that maps the routes and is registered in Program.cs.
Because of the line in CLAUDE.md, Claude Code follows this skill over the Microsoft documentation. It also keeps the code structure the same when I run it again without the MCP server.
Approving the MCP server
When I opened Claude Code in the project, it asked for approval to use the MCP server. You only have to do this once. After approving it, it's stored in .claude/settings.local.json.
{
"enabledMcpjsonServers": [
"microsoft_docs_mcp"
]
}You can run /mcp inside Claude Code to check the server is connected.
Creating an endpoint with union types
I then asked Claude Code to add a Minimal API endpoint that uses C# 15 union types.
Add a POST endpoint that creates an order in Minimal APIs. The result can be an order created, a validation failure, or out of stock using C# 15 union types.
While it was working, Claude Code called the Learn MCP server to search the documentation.
It added the endpoint into a separate static class, as set out in the skill. The result is a union type of the three outcomes, and the endpoint returns a different response for each one.
Which Learn pages did it use?
To check it had used the MCP server, I asked Claude Code this question.
Which learn page did you use?
It confirmed it had. The main page it read in full was Union types (C# reference). It used this for the union syntax, implicit conversions, how the switch checks every case, and how null is handled.
It also read search excerpts from What's new in C# 15 and Tutorial: Explore C# union types. These confirmed that C# 15 is the default for .NET 11 projects, so union types don't need the language version set to preview.
For the endpoint, it looked up how to create responses in Minimal API apps and the TypedResults methods it needed.
One thing worth noting is that the ASP.NET Core pages it read were for .NET 10, not .NET 11. It confirmed the code worked by building it and sending test requests against the .NET 11 release candidate SDK.
Trying it without the MCP server
Can Claude Code add the new features without the MCP server? To find out, I did it again from another project without the Learn MCP server, and started a new Claude Code session.
To stop it looking things up online, I added this line to CLAUDE.md.
Do not search the internet to find information.
Adding async validation
I used the same prompt, but this time I added that it must use async validation. This is a new feature for Minimal APIs in .NET 11.
Add a POST endpoint that creates an order in Minimal APIs. The result can be an order created, a validation failure, or out of stock using C# 15 union types. It must use async validation.
It worked. Claude Code created a ProductExists attribute that uses IsValidAsync, and added it to the product ID on the create order request.
How did it know about async validation?
Without the internet or the Learn MCP server, how did it know async validation existed? I asked it.
How did you find out about async validation?
It said it started from memory and confirmed it against the .NET 11 RC2 SDK installed on my machine. It remembered that .NET 11 might have added async validation, along with the names AsyncValidationAttribute, IAsyncValidatableObject and TryValidateObjectAsync. But it wasn't sure they had shipped.
To check, it searched the SDK's reference assemblies and found all three in System.ComponentModel.Annotations.dll. It then used reflection to print their exact signatures, built the code, and ran test requests to confirm that IsValidAsync was being called.
It also admitted that some of its choices came from memory alone and weren't tested.
That shows how much AI models have improved in the last year. When I tried this with .NET 10, Claude had no idea about the new version. Newer models can inspect the SDK to work out which features are there, even without the internet.
Watch the video
Watch the video where I add the Microsoft Learn MCP server to Claude Code, use it to create an endpoint with C# 15 union types, and find out whether Claude Code can add new .NET 11 features without it.
Related tutorials
C# 13 has been launched as part of the .NET 9 release and we'll take a look at the new features and how you can start using them today.
.NET 8 allows for a faster way to validate the option values in appsettings.json in an ASP.NET Core Web API using data annotations.