|
| 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