Short answer: Learn how to build an MCP server in .NET with the official SDK, choose a transport and host it, and lock down your APIs before AI agents call them
A teammate asks if the AI agent can just call your internal orders API. The short answer is yes, but not by pointing it at a Swagger file and hoping for the best.
Building an MCP server in .NET is the cleaner route. Model Context Protocol (MCP) is an open standard for connecting AI apps to tools and data, and the official C# SDK keeps the plumbing small.
The plumbing isn’t the hard part. The hard part is deciding which operations an agent may call, and who it calls them as.
By the end you’ll know which transport to pick, three ways to host the thing, and what I’d lock down before any agent connects.
Why an MCP Server in .NET Is Worth Your Time
Most of us already have APIs that hold the business logic: orders, customers, invoices. Without a standard, every AI tool needs its own custom connector to reach them.
MCP reduces that to one pattern. Microsoft’s overview describes it as a way to standardize how AI apps connect to external tools and data sources, including web APIs that expose business data or logic.
The official MCP C# SDK is on NuGet, and the docs say it’s maintained together by Microsoft, Anthropic and the MCP open protocol organization. That matters to me, because I don’t want to bet a service on a side project.
How MCP Works in Plain Words
There are three roles. The host is the AI tool, such as GitHub Copilot in Visual Studio Code. The client lives inside the host and talks to servers. The server is your code, which exposes capabilities.
For an existing API, the server is basically a thin layer in front of it. Each action you want an agent to take becomes a tool, with a name, a description and typed inputs.
The SDK builds on the Microsoft.Extensions.AI libraries, so you code against general AI abstractions instead of one provider.
MCP C# SDK Options for Getting Started
The docs’ quickstart uses the dotnet new mcpserver template. When I read it (the page was updated in July 2026), the template package was still in preview and needed the .NET 10 SDK or later. Check that before you plan a rollout.
- Local stdio server: The default template option. The server runs on the developer’s machine and the host starts it as a process. Good for personal tooling, poor for anything shared.
- Remote HTTP server: The other template option. Program.cs registers an HTTP transport and maps the MCP endpoint, so the server behaves like any ASP.NET Core service you can put behind your normal auth.
- Azure API Management in front of your REST API: It can expose operations of a managed REST API as MCP tools through its AI gateway. You pick the operations, so you aren’t forced to publish all of them. Today it supports tools only, not MCP resources or prompts.
- Azure Functions hosting: Functions can host remote MCP servers and offers built-in authentication for the endpoint. The docs flag hosting servers built with the official SDKs as preview.
Where It Goes Wrong
The first mistake with any MCP server in .NET is exposing everything. An API with forty endpoints doesn’t need forty tools. Every extra tool is more surface area for an agent to misuse, and more descriptions it has to choose between.
The second is treating a local stdio server as a safe default. It’s fine on a laptop, but it’s one developer’s machine, with whatever credentials that developer has.
The third is logging. The API Management guidance warns that if you enable payload logging at the global scope, you should set the frontend response payload bytes to 0. Otherwise you may log response bodies you never meant to keep.
It also says not to touch context.Response.Body in MCP policies, because that buffers the response and can break streaming.
What I’d Do Instead: MCP Server Authentication First
My rule of thumb is to start from the question, not the API. What are the three or four things an agent should be able to do? Build tools for those and nothing else.
I’d prefer read-only tools first. Add write operations later, one at a time, once you’ve seen how agents behave with the reads.
For anything shared, I’d go remote over HTTP, put real MCP server authentication in front of it, and avoid sharing secrets with the agent at all. The Functions tutorial itself recommends managed identity for the function app’s access to Azure resources, and I’d follow the same idea for whatever your tools call.
Tool descriptions deserve real effort too. An agent picks a tool largely from its name and description, so I’d write them like short notes for a new teammate: what it does, what the inputs look like, and what it won’t do.
Finally, add throttling. The API Management example limits tool calls to 5 per 30 seconds per IP address, and it also traces the agent ID of the caller. Both are sensible defaults to copy in spirit.
A Practical Example
Say you have an orders API with endpoints to list orders, get one order, create an order and cancel an order. You want a support assistant to answer questions about order status.
- Decide the scope. The assistant needs to look up an order and list recent orders for a customer. It doesn’t need to create or cancel.
- Create the MCP server in .NET from the template and choose the HTTP transport, since several people will use it.
- Add two tools that call your existing service layer, with clear descriptions such as what the order ID looks like.
- Put authentication in front of the endpoint and decide which identity the tools call the API as.
- Test with an MCP client such as Copilot in agent mode, and watch which tools it picks.
- Add throttling and make sure payloads aren’t logged where they shouldn’t be.
Only after that would I think about a cancel tool, and probably with a human confirmation step.
Quick Checklist
- Is each tool tied to a real task, not just an endpoint?
- Are write operations separated from read operations?
- Who is the caller, and how does the server know?
- Is there a rate limit?
- Do the logs avoid sensitive payloads?
Final Thoughts
An MCP server in .NET is easy to start and easy to get wrong. The template gets you a working server in minutes, but the safety comes from the choices around it: a small tool list, real authentication, throttling and careful logging.
Treat it like any other public-facing API, because to an agent, it is one.
Which operation in your own API would you be most nervous about handing to an agent?
#MCPServerInDotNet #DotNet #CSharp #AzureFunctions #APIManagement #AIAgents #SoftwareArchitecture
Key takeaways
- Most of us already have APIs that hold the business logic: orders, customers, invoices.
- There are three roles. The host is the AI tool, such as GitHub Copilot in Visual Studio Code.
- The docs’ quickstart uses the dotnet new mcpserver template.
- The first mistake with any MCP server in .NET is exposing everything.
- My rule of thumb is to start from the question, not the API.
Related reading and services: our .NET development team, recent case studies, and our Claude and MCP development services. Official reference: Model Context Protocol documentation.
Planning something like this?
Talk to our engineers. Contact Prilixor or see our US team for a conversation about your project.
Originally published on LinkedIn.