Friday, 10 April 2026

Azure MCP - Building AI-Powered Tools with Model Context Protocol

 Introduction to Model Context Protocol (MCP)

Artificial Intelligence is rapidly transforming how we build software. As LLMs (Large Language Models) become more capable, developers need a standardized way to connect AI models to real-world tools, APIs, and data sources. This is exactly the problem that the Model Context Protocol (MCP) solves. 


MCP is an open protocol introduced by Anthropic that defines a standard interface between AI models and external tools. Think of it as a USB standard, just as USB allows any device to connect to any computer, MCP allows any AI model to connect to any tool or data source that implements the protocol.


Why MCP Matters

Before MCP, integrating AI with external tools required custom, one-off implementations for every combination of model and tool. This created a fragmented ecosystem where:
        Each AI provider had its own proprietary function-calling format
        Tool implementations couldn't be reused across different AI models
        There was no standardized way to discover, authenticate, or invoke tools
        Developers had to rebuild integrations every time they switched AI providers
 
MCP solves all of this by providing a universal, open standard that any AI model and any tool can implement.


MCP Core Concepts


Concept

Description

Example

MCP Server

Exposes tools and resources via the MCP protocol

Weather API, Math Engine, Database

MCP Client

Connects to MCP servers and invokes tools

Azure OpenAI integration, Claude Desktop

Tool

A callable function exposed by the server

GetWeather(), Add(), SearchDB()

Transport

Communication channel between client and server

stdio, HTTP/SSE, WebSocket

Resource

Data exposed by the server for the AI context

Files, database records, API responses



Azure and MCP: The Perfect Combination

Microsoft Azure provides an ideal cloud platform for hosting and scaling MCP servers. With services like Azure Container Apps, Azure API Management, and Azure OpenAI, you can build enterprise-grade AI tool ecosystems that are secure, scalable, and manageable


Building an MCP Server in .NET

The MCP SDK for .NET makes it straightforward to build a production-ready MCP server. In this section, we walk through a complete implementation with math and weather tools.

Project Setup

Create a new ASP.NET Core Web API project and add the required NuGet packages:





Defining MCP Tools

Tools are defined as C# methods decorated with MCP attributes. The SDK automatically discovers and registers them:

namespace AzureMcpServerPOC
{
    [McpServerToolType]
    public static class MathTools
    {
        [McpServerTool, Description("Adds two numbers together")]
        public static double Add(
            [Description("First number")] double a,
            [Description("Second number")] double b)
        {
            return a + b;
        }

        [McpServerTool, Description("Multiplies two numbers")]
        public static double Multiply(
            [Description("First number")] double a,
            [Description("Second number")] double b)
        {
            return a * b;
        }


        [McpServerTool, Description("Calculates the square root of a number")]
        public static double SquareRoot(
            [Description("The number to find square root of")] double number)
        {
            if (number < 0)
                throw new ArgumentException("Cannot calculate square root");
            return Math.Sqrt(number);
        }
    }
}
Configuring HTTP Transport and update program.cs

builder.Services
    .AddMcpServer()
    .WithHttpTransport(options =>
    {
        options.Stateless = true; 
    })
    .WithToolsFromAssembly();

// Instead of WithToolsFromAssembly() you can also use .WithTools<MathTools>();

app.MapMcp("/mcp");

 Run MCPServer Locally in Postman

Run your project locally and check the port number. Use the same in Postman
























Multiply was a method name; you can run Add too. method name should be in lower case while calling.

{ "jsonrpc": "2.0", "id": 2, "method": "tools/call", "params":
{ "name": "multiply", "arguments": { "a": 4, "b":3 } } }

Choosing the Right Azure Hosting Option

Option

Best Scenario

Cost

Complexity

Scale

Azure Container Apps

Production, scalable MCP server

Pay-per-use

Low

Auto

Azure App Service

Simple hosting, familiar PaaS

Fixed tier

Very Low

Manual

Container Apps + APIM

Enterprise, multi-tenant, public API

Medium

Medium

Auto

AKS

Very large-scale, custom networking

Higher

High

Full control


Why is Azure OpenAI needed to call an MCP Server?

The short answer is: Azure OpenAI is the "brain",
MCP Server is the "hands".

The Core Problem MCP Solves

An MCP Server is just a collection of tools (functions).

It sits there waiting to be called.
It has no intelligence of its own. It cannot:

  • Understand natural language ("What's 144 squared?")
  • Decide which tool to call
  • Interpret what arguments to pass
  • Know when it has enough information to stop calling tools
This is where Azure OpenAI (GPT-4o) comes in.

You (natural language) ──► Azure OpenAI ──► "I need to call Add(a:10, b:20)" │ MCP Server executes it │ Returns result: 30 │ Azure OpenAI ◄── "The answer is 30" │ "10 plus 20 equals 30" ──► You




The Three Roles Explained

Azure OpenAI (The Decision Maker)

  • Reads the user's natural language prompt
  • Reviews the list of available MCP tools and their descriptions
  • Decides which tool(s) to call and with what arguments
  • Interprets the tool results and forms a natural language response

MCP Server (The Executor)

  • Holds the actual business logic (math, weather, database, etc.)
  • Executes tools when called with specific inputs
  • Returns raw results — no interpretation, no language, just data

MCP Client (The Coordinator)

  • Sits between Azure OpenAI and the MCP Server
  • Fetches the tool list and converts it to OpenAI's format
  • Passes tool calls from OpenAI to the MCP Server
  • Returns results back to OpenAI to continue the conversation

Without Azure OpenAI, you'd have to manually figure out which tool to call, format the exact JSON arguments yourself, and know when to stop, essentially doing the AI's job yourself. 


Summary

MCP represents a significant shift in how AI models interact with the world. Standardizing the interface between models and tools, it enables a new generation of AI applications that are modular, reusable, and interoperable.

 

In this article, we covered:
        The core concepts of MCP and why it matters for enterprise AI development
        Building a .NET MCP Server with math and weather tools
        Exposing the server via HTTP transport with API key authentication


Next, we will learn:
        Connecting Azure OpenAI to your hosted MCP server

No comments:

Post a Comment

Azure MCP - Building AI-Powered Tools with Model Context Protocol

  Introduction to Model Context Protocol (MCP) Artificial Intelligence is rapidly transforming how we build software. As LLMs (Large Languag...