Building an MCP Server with Azure Functions and Consuming it from Microsoft Foundry Agent
Contents
Introduction
Model Context Protocol (MCP) is quickly becoming the standard mechanism for enabling AI agents to discover and invoke external tools. Instead of hardcoding APIs into agents, MCP provides a standardized interface where tools can be dynamically discovered and executed. Microsoft has integrated MCP support into Azure Functions, allowing developers to expose serverless functions as MCP tools that can be consumed by Azure AI Foundry Agents.
In this article, we’ll walk through:
- Creating a .NET MCP Server using Azure Functions and Visual Studio IDE.
- Deploying the MCP Server to an Azure Function App using Visual Studio.
- Registering and consuming the MCP Server via Microsoft Foundry Agent.
The implementation is based on the Calculator MCP repository:
GitHub Repository:
daddycloudarchitect/CalculatorMCP: A Calculator MCP Server exposing Azure Functions as MCP tools for consumption by Azure AI Foundry Agents
Architecture
The solution follows a lightweight and scalable architecture where the Azure Function App acts as the Remote MCP Server, exposing enterprise capabilities as MCP tools through the Azure Functions MCP Extension. Each calculator operation is implemented as an individual MCP tool and made available through a standardized MCP endpoint.
Microsoft Foundry Agent connect to the MCP server endpoint, automatically discover the available tools, and invoke them as needed based on the user’s natural language requests. The agent uses its reasoning capabilities to determine which tool best matches the user’s intent, execute the operation, and return the result without requiring explicit tool selection.
This architecture enables a clear separation of concerns, where:
- Azure Functions hosts and exposes MCP tools.
- Business Services contain the core calculation logic.
- MCP Tools act as wrappers that expose business capabilities to AI agents.
- Microsoft Foundry Agents consume and orchestrate the tools through the MCP protocol.
The result is a serverless, scalable, and reusable pattern for exposing enterprise functionality as AI-accessible tools, allowing agents to seamlessly integrate external capabilities into conversational experiences.
Solution Structure
The solution is organized using a clean and modular architecture to promote maintainability, extensibility, and separation of concerns.
CalculatorMCP
│
├── Program.cs
├── ICalculatorService.cs
├── CalculatorService.cs
├── CalculatorTools.cs
│
├── Models
│ ├── SingleNumberRequest.cs
│ ├── TwoNumberRequest.cs
│ ├── PowerRequest.cs
│ └── PercentageRequest.cs
│
└── host.json
Running the Solution Locally
Follow the steps below to run and test the Calculator MCP Server on your local machine.
1. Start the Azure Storage Emulator (Azurite)
azurite
2. Run the Azure Function App
Using Azure Functions Core Tools:
func start
Or directly from the .NET project:
dotnet run
3. Test the MCP Endpoint
Once the application is running, the MCP endpoint will be exposed at:
http://localhost:{Port}/runtime/webhooks/mcp
Replace {Port} with the port displayed in the Function App startup logs.

Deploying the Calculator MCP Server to Azure Functions
Azure Functions automatically exposes the MCP endpoint through the Azure Functions MCP Extension, making it easy to host and consume MCP tools from Azure AI Foundry Agents.
1. Create a Resource Group
Create a dedicated Resource Group to host all resources related to the Calculator MCP Server.
2. Create a Storage Account
Azure Functions requires a Storage Account for runtime operations and application state management.
3. Create a Function App
Create a Function App using the .NET Isolated Worker runtime.
4. Publish the Application
Once the Azure resources have been provisioned, publish the application directly from Visual Studio.
Using Visual Studio 2026
- Right-click the project.
- Select Publish.
- Choose Azure.
- Select Azure Function App (Windows/Linux).
- Choose the target Function App (CalculatorMCPPOC).
- Click Publish.
Visual Studio will build, package, and deploy the Calculator MCP Server to Azure Functions.
5.Verify the Deployment
After a successful deployment:
- Navigate to the Azure Portal.
- Open the CalculatorMCPPOC Function App.
- Confirm that the application is running successfully.
You should see all Calculator MCP tools available for consumption, as shown below

6.Obtain the MCP Endpoint
https://{calculator-mcp-poc}.azurewebsites.net/runtime/webhooks/mcp
7.Obtain the MCP Extension Key

Configure the Microsoft Foundry Agent
After deploying the Calculator MCP Server to Azure Function App, the next step is to configure an Azure AI Foundry Agent to consume the MCP tools.
- Deploy a Foundation Model
Deploy a model in Azure AI Foundry. In this example, GPT-5.4-nano is used.
2. Create an Agent
- Navigate to the Agents section in Microsoft Foundry.
- Create a new agent.
- Configure the agent with an appropriate system prompt that guides how it should use the Calculator MCP tools.
3.Add the MCP Tool
- Within the agent configuration, navigate to Tools.
- Select Add → Add Tools.
- Choose Custom → Model Context Protocol (MCP).
4.Configure the Remote MCP Server
- Provide a meaningful Name for the MCP tool.
- Enter the Remote MCP Server Endpoint exposed by the Azure Function App.
5.Configure Authentication
- Select Key-based Authentication.
- Add the following key-value pair:
- Key:
x-functions-key - Value:
mcp_extensionapplication key from the Azure Function App
6. Verify Tool Registration
- Once the MCP tool is successfully added, it will appear in the agent’s tool list.
- Microsoft Foundry will automatically discover and display all MCP tools exposed by the remote MCP server, making them available for agent invocation.


Example Interaction






As shown, the agent leverages natural language understanding to translate user conversations into tool actions, seamlessly calling the appropriate Calculator MCP tool to perform the requested calculation without requiring explicit tool selection by the user.
Conclusion
Azure Functions provides one of the most straightforward and scalable ways to build and host remote MCP servers. By combining the Azure Functions MCP Extension, the .NET Isolated Worker model, and Azure AI Foundry Agents, organizations can rapidly expose enterprise capabilities as reusable AI-powered tools. The Calculator MCP sample showcases a clean architecture approach where business logic is encapsulated within dedicated services and decoupled from MCP tool implementations. Hosted serverless on Azure Functions, these tools are exposed through a standard MCP endpoint and can be seamlessly discovered and invoked by Azure AI Foundry Agents. As demonstrated, the agent can interpret calculation requests expressed in natural language, automatically select the appropriate Calculator MCP tool, execute the operation, and return the result without requiring explicit tool invocation from the user.
About the author
Kunal Saha
K, Saha (08/09/2026) Building an MCP Server with Azure Functions and Consuming it from Microsoft Foundry Agent | by Kunal Saha | Aug, 2026 | Medium