Skip to content

Commit 365e438

Browse files
authored
Python: AzureAI Local MCP Sample (#2616)
* added azure ai local mcp sample * small fix * handling for local mcp * remove redundant local mcp handling
1 parent 01a04a3 commit 365e438

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

python/samples/getting_started/agents/azure_ai/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This folder contains examples demonstrating different ways to create and use age
2020
| [`azure_ai_with_explicit_settings.py`](azure_ai_with_explicit_settings.py) | Shows how to create an agent with explicitly configured `AzureAIClient` settings, including project endpoint, model deployment, and credentials rather than relying on environment variable defaults. |
2121
| [`azure_ai_with_file_search.py`](azure_ai_with_file_search.py) | Shows how to use the `HostedFileSearchTool` with Azure AI agents to upload files, create vector stores, and enable agents to search through uploaded documents to answer user questions. |
2222
| [`azure_ai_with_hosted_mcp.py`](azure_ai_with_hosted_mcp.py) | Shows how to integrate hosted Model Context Protocol (MCP) tools with Azure AI Agent. |
23+
| [`azure_ai_with_local_mcp.py`](azure_ai_with_local_mcp.py) | Shows how to integrate local Model Context Protocol (MCP) tools with Azure AI agents. |
2324
| [`azure_ai_with_response_format.py`](azure_ai_with_response_format.py) | Shows how to use structured outputs (response format) with Azure AI agents using Pydantic models to enforce specific response schemas. |
2425
| [`azure_ai_with_runtime_json_schema.py`](azure_ai_with_runtime_json_schema.py) | Shows how to use structured outputs (response format) with Azure AI agents using a JSON schema to enforce specific response schemas. |
2526
| [`azure_ai_with_search_context_agentic.py`](../../context_providers/azure_ai_search/azure_ai_with_search_context_agentic.py) | Shows how to use AzureAISearchContextProvider with agentic mode. Uses Knowledge Bases for multi-hop reasoning across documents with query planning. Recommended for most scenarios - slightly slower with more token consumption for query planning, but more accurate results. |
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright (c) Microsoft. All rights reserved.
2+
3+
import asyncio
4+
5+
from agent_framework import MCPStreamableHTTPTool
6+
from agent_framework.azure import AzureAIClient
7+
from azure.identity.aio import AzureCliCredential
8+
9+
"""
10+
Azure AI Agent with Local MCP Example
11+
12+
This sample demonstrates integration of Azure AI Agents with local Model Context Protocol (MCP)
13+
servers.
14+
15+
Pre-requisites:
16+
- Make sure to set up the AZURE_AI_PROJECT_ENDPOINT and AZURE_AI_MODEL_DEPLOYMENT_NAME
17+
environment variables before running this sample.
18+
"""
19+
20+
21+
async def main() -> None:
22+
"""Example showing use of Local MCP Tool with AzureAIClient."""
23+
print("=== Azure AI Agent with Local MCP Tools Example ===\n")
24+
25+
async with (
26+
AzureCliCredential() as credential,
27+
AzureAIClient(async_credential=credential).create_agent(
28+
name="DocsAgent",
29+
instructions="You are a helpful assistant that can help with Microsoft documentation questions.",
30+
tools=MCPStreamableHTTPTool(
31+
name="Microsoft Learn MCP",
32+
url="https://learn.microsoft.com/api/mcp",
33+
),
34+
) as agent,
35+
):
36+
# First query
37+
first_query = "How to create an Azure storage account using az cli?"
38+
print(f"User: {first_query}")
39+
first_result = await agent.run(first_query)
40+
print(f"Agent: {first_result}")
41+
print("\n=======================================\n")
42+
# Second query
43+
second_query = "What is Microsoft Agent Framework?"
44+
print(f"User: {second_query}")
45+
second_result = await agent.run(second_query)
46+
print(f"Agent: {second_result}")
47+
48+
49+
if __name__ == "__main__":
50+
asyncio.run(main())

0 commit comments

Comments
 (0)