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 |
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
Defining MCP Tools
Tools are defined as C# methods decorated with MCP attributes. The SDK automatically discovers and registers them:
Configuring HTTP Transport and update program.csnamespace 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); } } }
.AddMcpServer()
.WithHttpTransport(options =>
{
options.Stateless = true;
})
.WithToolsFromAssembly();
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
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
No comments:
Post a Comment