Add #pragma warning disable directives to suppress experimental API diagnostics that cause build errors in Docker isolation (where repo-level Directory.Build.props is not inherited): - AgentWithHostedMCP: suppress MEAI001 (HostedMcpServerTool) and OPENAI001 (GetResponsesClient) - FoundrySingleAgent: suppress CA2252 (AIProjectClient preview features) - FoundryMultiAgent: suppress CA2252 (AIProjectClient preview features) Fixes #4365
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
For common prerequisites and setup instructions, see the Hosted Agent Samples README.
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 DefaultAzureCredential for authentication, which probes multiple sources automatically. For local development, 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.