Building a Custom MCP Server with .NET SDK, Azure Container, and Copilot Studio Integration
Building a Custom MCP Server with .NET SDK, Azure Container, and Copilot Studio Integration
Date: 2026-03-17
Step into building a custom Model Context Protocol server with the .NET MCP SDK, hosting it securely on Azure Container Apps, and connecting it seamlessly to Copilot Studio.
Tags: ["Microsoft 365", "MCP", "Azure", "Copilot Studio", "Containers"]
Microsoft 365 Copilot and Model Context Protocol (MCP) are transforming how developers build intelligent, integrated AI experiences across enterprise applications. However, the real power arises when you build your own MCP Server that connects custom logic or data to AI Agents built with Copilot Studio.
In this post, we dive into the practical journey of building a custom MCP Server using the .NET MCP SDK, packaging it as a container, deploying it to Azure App Service, and finally linking it with Copilot Studio Agents. This approach unlocks the ability to extend AI assistants deeply with your tailored capabilities while leveraging the secure, scalable Azure environment.
I’ll walk you through the core technical steps, key challenges such as port and SSL handling, deployment automation, and how to publish a custom connector to consume the MCP Server in Copilot Studio Agents. Whether you want to learn about MCP itself or architect cloud-hosted AI connectors, this tutorial exposes the full workflow and critical insights.
Architecture Overview
┌────────────────────────────────────────────┐
│Architecture │
├────────────────────────────────────────────┤
│• Enterprise data sources │
│• Foundry platform │
│• AI applications │
└────────────────────────────────────────────┘
Key Technical Observations
-
Containerized .NET MCP Server Enables Local and Cloud Parity
Leveraging the SDK’s container support lets you run and debug your MCP Server locally with exact parity to the cloud container, speeding development iterations. -
Port Configuration is Critical for Azure Containers
Default ports cause conflicts with Azure Container Instances, requiring workaround environment variables (ASPNETCORE_URLS,ASPNETCORE_HTTP_PORTS) to expose ports like 8080 and 5000 correctly. -
Choosing Azure App Service for SSL Simplifies Security
While Azure Container Instances complicate SSL termination due to certificate management overhead, switching to Azure App Service hosting for containers provides built-in HTTPS support and eases secure deployment. -
OAuth Authentication Intersection with MCP Protocol Needs Attention
MCP Servers protected by Microsoft Entra ID OAuth encounter protocol mismatches that complicate testing with MCP Inspector tools; this requires careful resource and scopes alignment. -
Updating Containers via Visual Studio is Helpful but Can Be Unreliable
Authentication glitches when pushing containers to Azure Container Registry often necessitate Azure DevOps Pipelines to automate build and deployment with greater reliability. -
Copilot Studio Integrates through OpenAPI Schema Custom Connectors
Publishing your MCP Server involves importing a carefully crafted OpenAPI spec into Power Platform as a Custom Connector, enabling seamless inclusion in Copilot Studio agents.
How It Works
Building Your MCP Server
Begin with Visual Studio 2022 creating a new console project (e.g., i365.LinkedInMcpServer). Add essential NuGet packages:
Microsoft.AspNetCore.Authentication.JwtBearer v9.0.11
Microsoft.Extensions.Hosting v9.0.11
Microsoft.Identity.Web v4.1.1
ModelContextProtocol v0.5.0-preview.1
ModelContextProtocol.AspNetCore v0.5.0-preview.1
Configure your Program.cs to build the WebApplication hosting your MCP Server. Define MCP Server Tool classes decorated with [McpServerToolType] and each callable tool method with [McpServerTool] and descriptive attributes for the operations and parameters.
This pattern exposes your custom business operations as MCP tools consumable by clients.
Debugging and Port Configuration
Running locally requires opening ports and redirecting them properly. Modify your project file to include environment variables:
This ensures container HTTP listeners bind correctly inside Azure environments. Use npx @modelcontextprotocol/inspector dotnet run from PowerShell to launch MCP Inspector connected to your local MCP Server endpoint for interactive testing.
Deploying to Azure
Set up Azure infrastructure:
- Resource Group
- Azure Container Registry (ACR)
- Azure App Service configured for container hosting
- Storage Account
Publish your container from Visual Studio by configuring a publish profile targeting ACR:
- Right-click project → Publish → New Profile → Azure → Azure Container Registry
- Select subscription and registry
- Use .NET SDK publishing option (no Dockerfile needed)
- Publish the container
Then, create an Azure App Service pointing to this container image, set port 8080, and apply deployment settings. This approach lets Azure App Service handle SSL termination with automated certificate management, making it a smoother hosting choice than Azure Container Instances.
Updating and Automating
For updates, the Azure App Service Deployment Center allows manual sync, but this can be slow. Building Azure DevOps Pipelines automates continuous integration and delivery, pushing new containers to ACR and triggering app service refreshes seamlessly.
Connecting to Copilot Studio
To expose your MCP Server tools in Copilot Studio:
-
Download the MCP OpenAPI schema from Microsoft documentation.
-
Customize schema for your server host and name.
-
In Power Platform Custom Connectors, import the OpenAPI JSON file.
-
Configure host URL, security (preferably OAuth 2.0 via Entra ID), and operation details.
-
Create the connector and add it to your Copilot Studio Agent by selecting it in the agent’s Tools section.
-
Enable the MCP tools you want the agent to use, then publish the agent.
The integration is surprisingly straightforward and opens powerful extensibility scenarios for your AI agents.
Quick Tips & Tricks
-
Enable Container Support Early
Addtruein your project file to streamline container builds. -
Use Azure App Service Instead of Container Instances for SSL
Avoid complex certificate updates by hosting containers in App Service, which manages SSL termination gracefully. -
Automate Deployment with Azure DevOps Pipelines
Manual publishing can be flaky; automate builds and releases to ACR and app services for reliable updates. -
Test Secured MCP Servers with MCP Inspector Carefully
Protocol mismatches with Microsoft Entra ID OAuth may cause test frustrations—verify OAuth resource configurations. -
Use Environmental Variables to Fix Port Conflicts
MCP servers default ports may clash with Azure settings; setASPNETCORE_URLSandASPNETCORE_HTTP_PORTSaccordingly. -
Leverage OpenAPI Schema for Seamless Custom Connector Creation
Use Microsoft's example MCP Server OpenAPI spec as a starting point; update it to precisely match your MCP Server endpoints.
Conclusion
Building and deploying a custom MCP Server with the .NET SDK hosted in an Azure container unlocks extensible AI agent capabilities with Microsoft's Copilot platform. By focusing on containerization, port configurations, and seamless integration with Azure App Service, you ensure secure, scalable hosting while minimizing operational overhead.
Linking your MCP Server to Copilot Studio via Custom Connectors enables effortless addition of your custom tools to AI agents, bridging your business logic to intelligent assistants. Automating deployment through pipelines further enhances reliability for continuous iteration.
As this technology evolves, expect Azure Functions support and deeper authentication integrations to mature, enabling even more robust and agile MCP Server deployments. Watch this space for the next steps in securing and streamlining your MCP infrastructure.
References
- How to: Build a Custom MCP Server with the .NET MCP SDK, host as an Azure Container and connect to Copilot Studio | Doy's Microsoft 365 and Azure Dev Blog
- Microsoft Model Context Protocol (MCP) OpenAPI Schema Example
- Azure Container Registry Documentation
- Azure App Service Container Deployment
- Copilot Studio Documentation
- Microsoft Entra ID OAuth overview

Profile image courtesy Simon Doy’s blog