mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
406a8560c6
* add AgentWithHostedMCP sample * Update dotnet/samples/HostedAgents/AgentWithHostedMCP/README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update dotnet/samples/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update dotnet/samples/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update dotnet/samples/HostedAgents/AgentWithHostedMCP/AgentWithHostedMCP.csproj Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Use explicit type for mcpTool --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1.8 KiB
1.8 KiB
What this sample demonstrates
This sample demonstrates how to use a Hosted Model Context Protocol (MCP) server with an AI agent. The agent connects to the Microsoft Learn MCP server to search documentation and answer questions using official Microsoft content.
Key features:
- Configuring MCP tools with automatic approval (no user confirmation required)
- Filtering available tools from an MCP server
- Using Azure OpenAI Responses with MCP tools
Prerequisites
Before running this sample, ensure you have:
- An Azure OpenAI endpoint configured
- A deployment of a chat model (e.g., gpt-4o-mini)
- Azure CLI installed and authenticated
Note: This sample uses Azure CLI credentials for authentication. Make sure you're logged in with az login and have access to the Azure OpenAI resource.
Environment Variables
Set the following environment variables:
# Replace with your Azure OpenAI endpoint
$env:AZURE_OPENAI_ENDPOINT="https://your-openai-resource.openai.azure.com/"
# Optional, defaults to gpt-4o-mini
$env:AZURE_OPENAI_DEPLOYMENT_NAME="gpt-4o-mini"
How It Works
The sample connects to the Microsoft Learn MCP server and uses its documentation search capabilities:
- The agent is configured with a HostedMcpServerTool pointing to
https://learn.microsoft.com/api/mcp - Only the
microsoft_docs_searchtool is enabled from the available MCP tools - Approval mode is set to
NeverRequire, allowing automatic tool execution - When you ask questions, Azure OpenAI Responses automatically invokes the MCP tool to search documentation
- The agent returns answers based on the Microsoft Learn content
In this configuration, the OpenAI Responses service manages tool invocation directly - the Agent Framework does not handle MCP tool calls.