Protect Azure Data Lake Storage with Vaulted Backups
May 19, 2025Building an Enterprise RAG Pipeline in Azure with NVIDIA AI Blueprint for RAG and Azure NetApp Files
May 19, 2025In the ever-evolving world of Generative AI, the pace of innovation is nothing short of breathtaking. Just a few short months ago, Large Language Models (LLMs) and their smaller counterparts, Small Language Models (SLMs), were the talk of the town. Then came Retrieval Augmented Generation (RAG), offering a powerful way to ground these models to specific knowledge bases. The emergence of Agents and Agentic AI further opened doors for new possibilities by using the GenAI Model capabilities. Now, as the next step in this exciting journey, we’re witnessing the arrival of a new open protocol – one that standardizes how applications provide crucial context to LLMs. This new protocol is MCP.
Model Context Protocol:
Currently there is a Challenge while integrating LLMs with specific tools (like databases, APIs, calendars, or custom user context). It often requires very specific type of adapters or prompt engineering for each use case.
MCP proposes a standardized protocol where different sources of context (like user preferences, app state, or external data) can be exposed to the model in a consistent format — making AI systems modular, interoperable, and easier to maintain or scale. With a protocol like MCP, developers don’t need to reinvent the wheel every time they want to plug an LLM into a new application — much like how USB-C lets any charger or device work across multiple brands and devices.
MCP in short is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a USB-C port for AI applications. Just as USB-C provides a standardized way to connect your devices to various peripherals and accessories, MCP provides a standardized way to connect AI models to different data sources and tools. If your new to MCP Microsoft has just released a new MCP for Beginners course this a perfect starting point for your MCP learning.
Why MCP?
MCP makes it easier to build agents and complex workflows using LLMs. Since LLMs often need access to external data and tools, MCP offers:
- A growing collection of ready-to-use integrations your LLM can connect to directly
- The flexibility to switch between different LLM providers or platforms
- Built-in best practices for securely handling your data within your own infrastructure.
MCP Architecture:
MCP Architecture
- MCP Hosts: This is the application that utilizes the MCP client to access data. Examples include chat applications, code assistants in IDEs, and other AI tools. An MCP host can include multiple clients.
- MCP Clients: The MCP client resides within the host and manages the connection to MCP servers. It establishes and maintains a one-to-one connection with these servers.
- MCP Servers: Lightweight programs that expose specific capabilities or tools through the standardized MCP. An MCP host can connect to multiple MCP servers.
How MCP Works:
- When a MCP host requires a tool or data, it communicates with an MCP server.
- The MCP host and server communicate using the MCP protocol, which acts as a transport layer.
- The MCP server then interacts with the relevant data source, such as a relational or NoSQL database, an API, or a local file. The API standard doesn’t matter.
- The MCP server retrieves the requested information and sends it back to the MCP host.
Example Scenario
Consider a chat application (the MCP host) where a user asks about the weather in a specific location.
- The chat application, through its MCP client, requests the necessary weather tool from an MCP server.
- The MCP server identifies the appropriate tool and makes it available.
- The chat application then sends the user’s query and the available tools to a large language model (LLM).
- The LLM determines which tool to use.
- The chat application calls the MCP server to execute the weather tool.
- The MCP server retrieves the weather data and sends it back to the LLM.
- Finally, the chat application presents the weather information to the user.
AI Toolkit’s Agent Builder for MCP:
The AI Toolkit now features Agent Builder, earlier known as Prompt Builder, designed for seamless intelligent app development. This powerful tool integrates prompt engineering and tool integration into a single workflow, allowing you to effortlessly create, iterate, and optimize your AI agents. It also provides with MCP capabilities as well.
Agent Builder is crafted to help developers and prompt engineers:
🚀 Create initial prompts using natural language
🔁 Continuously improve prompts and evaluate by analysing model feedback
🧩 Decompose complex tasks with prompt chaining and structured output
🧪 Experiment with real-time executions and tool integrations like MCP servers
💻 Produce production-ready code to accelerate application development
With the help of the Agent Builder, Agents can now interface with external tools via MCP (Model Control Protocol) servers, allowing them to carry out real-world tasks such as querying databases, calling APIs, or executing custom logic.
For a quick demonstration of MCP, let’s use the readily available example in the agent builder.
Select “Web Developer (With MCP Server)” From the examples. This example creates one page website based on user specifications and store website on the local drive.
In the current version the MCP is available with Selected GitHub Models. In this tutorial we are using GPT4o mini from GitHub Models.
Once we select this, it automatically fills up the fields like
- System Prompt
- User Prompt
- Tools
Once it has completed the execution, we can see the response in the “Model Response”.
Upon clicking the “>View Code</EM>”, we can also view the code after choosing the SDK of choice.
Following is the code that is generated after choosing the “Azure AI Inference SDK”.
“””Connect model with mcp tools in Python
# Run this python script
> pip install mcp azure-ai-inference
> python .py
“””
import asyncio
import json
import os
from typing import Dict, Optional
from contextlib import AsyncExitStack
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
from mcp.client.sse import sse_client
from azure.ai.inference import ChatCompletionsClient
from azure.ai.inference.models import AssistantMessage, SystemMessage, UserMessage, ToolMessage
from azure.ai.inference.models import ImageContentItem, ImageUrl, TextContentItem
from azure.core.credentials import AzureKeyCredential
class MCPClient:
def __init__(self):
# Initialize session and client objects
self._servers = {}
self._tool_to_server_map = {}
self.exit_stack = AsyncExitStack()
# To authenticate with the model you will need to generate a personal access token (PAT) in your GitHub settings.
# Create your PAT token by following instructions here: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens
self.azureai = ChatCompletionsClient(
endpoint = “https://models.inference.ai.azure.com”,
credential = AzureKeyCredential(os.environ[“GITHUB_TOKEN”]),
api_version = “2024-08-01-preview”,
)
async def connect_stdio_server(self, server_id: str, command: str, args: list[str], env: Dict[str, str]):
“””Connect to an MCP server using STDIO transport
Args:
server_id: Unique identifier for this server connection
command: Command to run the MCP server
args: Arguments for the command
env: Optional environment variables
“””
server_params = StdioServerParameters(
command=command,
args=args,
env=env
)
stdio_transport = await self.exit_stack.enter_async_context(stdio_client(server_params))
stdio, write = stdio_transport
session = await self.exit_stack.enter_async_context(ClientSession(stdio, write))
await session.initialize()
# Register the server
await self._register_server(server_id, session)
async def connect_sse_server(self, server_id: str, url: str, headers: Dict[str, str]):
“””Connect to an MCP server using SSE transport
Args:
server_id: Unique identifier for this server connection
url: URL of the SSE server
headers: Optional HTTP headers
“””
sse_context = await self.exit_stack.enter_async_context(sse_client(url=url, headers=headers))
read, write = sse_context
session = await self.exit_stack.enter_async_context(ClientSession(read, write))
await session.initialize()
# Register the server
await self._register_server(server_id, session)
async def _register_server(self, server_id: str, session: ClientSession):
“””Register a server and its tools in the client
Args:
server_id: Unique identifier for this server
session: Connected ClientSession
“””
# List available tools
response = await session.list_tools()
tools = response.tools
# Store server connection info
self._servers[server_id] = {
“session”: session,
“tools”: tools
}
# Update tool-to-server mapping
for tool in tools:
self._tool_to_server_map[tool.name] = server_id
print(f”nConnected to server ‘{server_id}’ with tools:”, [tool.name for tool in tools])
async def chatWithTools(self, messages: list[any]) -> str:
“””Chat with model and using tools
Args:
messages: Messages to send to the model
“””
if not self._servers:
raise ValueError(“No MCP servers connected. Connect to at least one server first.”)
# Collect tools from all connected servers
available_tools = []
for server_id, server_info in self._servers.items():
for tool in server_info[“tools”]:
available_tools.append({
“type”: “function”,
“function”: {
“name”: tool.name,
“description”: tool.description,
“parameters”: tool.inputSchema
},
})
while True:
# Call model
response = self.azureai.complete(
messages = messages,
model = “gpt-4o”,
tools=available_tools,
response_format = “text”,
temperature = 1,
top_p = 1,
)
hasToolCall = False
if response.choices[0].message.tool_calls:
for tool in response.choices[0].message.tool_calls:
hasToolCall = True
tool_name = tool.function.name
tool_args = json.loads(tool.function.arguments)
messages.append(
AssistantMessage(
tool_calls = [{
“id”: tool.id,
“type”: “function”,
“function”: {
“name”: tool.function.name,
“arguments”: tool.function.arguments,
}
}]
)
)
# Find the appropriate server for this tool
if tool_name in self._tool_to_server_map:
server_id = self._tool_to_server_map[tool_name]
server_session = self._servers[server_id][“session”]
# Execute tool call on the appropriate server
result = await server_session.call_tool(tool_name, tool_args)
print(f”[Server ‘{server_id}’ call tool ‘{tool_name}’ with args {tool_args}]: {result.content}”)
messages.append(
ToolMessage(
tool_call_id = tool.id,
content = str(result.content)
)
)
else:
messages.append(
AssistantMessage(
content = response.choices[0].message.content
)
)
print(f”[Model Response]: {response.choices[0].message.content}”)
if not hasToolCall:
break
async def cleanup(self):
“””Clean up resources”””
await self.exit_stack.aclose()
await asyncio.sleep(1)
async def main():
client = MCPClient()
messages = [
SystemMessage(content = “Your task is to create a one-page website based on the given specifications, delivered as an HTML file with embedded JavaScript and CSS.”),
UserMessage(content = [
TextContentItem(text = “Create a one-page website for an online learning platform called “EduQuest” with the following features and sections:nn1. A fixed navigation bar with links to course categories (Math, Science, Languages, Arts) and a search bar.nn2. An interactive “Learning Paths” section with a short quiz to determine learning styles and interests, and a button to start the quiz.nnSave the code in a html file under ‘${USER_HOME}/.aitk/examples’, then provide Windows & macOS command to open it in default browser.”),
]),
]
try:
await client.connect_stdio_server(
“aitk-filesystem-example”,
“npx”,
[
“-y”,
“@modelcontextprotocol/server-filesystem”,
“C:Users\.aitkexamples”,
],
{
}
)
await client.chatWithTools(messages)
except Exception as e:
print(f”nError: {str(e)}”)
finally:
await client.cleanup()
if __name__ == “__main__”:
asyncio.run(main())
The aim of this example is to create website using the tools, as we can notice there are 11 tools that have been used in this example.
With processing finished, the Agent Builder example website is now ready to be explored,
Following are the commands that can be used in Windows/MacOS to view the webpage,
For Windows,
start C:Users.aitkexampleseduquest.html
For macOS
open /Users/shrey/.aitk/examples/eduquest.html
This basic demonstration of MCP using Agent Builder shows a big change in how websites can be designed with AI. What used to be a complicated setup with coding as a prerequisite is now simpler, almost like there’s no coding prerequisite at all. The quickness achieved with how MCP helps in developing makes it much easier to think about and enables faster implementation to get things running. But this is just the beginning. Agent Builder lets us do many different things. In our next detailed blogs, we will look closely at these advanced things, understanding how its parts are put together and how to innovate new and interesting applications with MCP.
Get started with MCP at Microsoft MCP for Beginners