* restructure: Python samples into progressive 01-05 layout - 01-get-started/: 6 numbered steps (hello agent → hosting) - 02-agents/: all agent concept samples (tools, middleware, providers, etc.) - 03-workflows/: ALL existing workflow samples preserved as-is - 04-hosting/: azure-functions, durabletask, a2a - 05-end-to-end/: demos, evaluation, hosted agents - Old files moved to _to_delete/ for review - Added AGENTS.md with structure documentation - autogen-migration/ and semantic-kernel-migration/ preserved at root * fix: switch to AzureOpenAI Foundry, fix CI failures - Switch all 01-get-started samples to AzureOpenAIResponsesClient with Azure AI Foundry project endpoint (AZURE_AI_PROJECT_ENDPOINT + AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME + AzureCliCredential) - Add _to_delete/ and 05-end-to-end/ to pyrightconfig.samples.json excludes - Fix test paths in packages/ that referenced old getting_started/ dirs: durabletask conftest + streaming test, azurefunctions conftest, devui conftest + capture_messages + openai_sdk_integration - Fix workflow_as_agent_human_in_the_loop.py import (sibling import) - Update hosting READMEs and tool comment paths - Replace root README.md with new structure overview - Update AGENTS.md to document Azure OpenAI Foundry as default provider * cleanup: remove _to_delete folder, copy resource files to active dirs All files in _to_delete/ were either: - Exact duplicates of files in the new structure (240 files) - Same file with only comment path updates (100 files) - One import-fix diff (workflow_as_agent_human_in_the_loop.py) - One superseded minimal_sample.py Resource files (sample.pdf, countries.json, employees.pdf, weather.json) copied to 02-agents/sample_assets/ and 02-agents/resources/ since active samples reference them. * fix: address PR review comments, centralize resources, remove root duplicates - Fix type annotation in 04_memory.py (string union -> proper types) - Fix old sample paths in observability files - Fix grammar/spelling in observability samples - Move sample_assets/ and resources/ to shared/ folder - Remove 8 duplicate observability files from 02-agents root - Update resource path references in multimodal_input and provider samples * fix: update broken links from old getting_started paths to new structure - Update relative paths in READMEs: getting_started/ → 01-get-started/, 02-agents/, 03-workflows/, 04-hosting/, 05-end-to-end/ - Fix absolute GitHub URLs in package READMEs - Fix broken link in ollama package README * fix: convert absolute GitHub URLs to relative paths for link checker Absolute URLs to python/samples/ on main branch 404 until PR merges. Converted to relative paths that linkspector can verify locally. * fix: update link for handoff sample moved to orchestrations/ * fix: update chatkit-integration README path from demos/ to 05-end-to-end/ * fix: update broken links in orchestrations README to match flat directory structure
Agent as MCP Tool Sample
This sample demonstrates how to configure AI agents to be accessible as both HTTP endpoints and Model Context Protocol (MCP) tools, enabling flexible integration patterns for AI agent consumption.
Key Concepts Demonstrated
- Multi-trigger Agent Configuration: Configure agents to support HTTP triggers, MCP tool triggers, or both
- Microsoft Agent Framework Integration: Use the framework to define AI agents with specific roles and capabilities
- Flexible Agent Registration: Register agents with customizable trigger configurations
- MCP Server Hosting: Expose agents as MCP tools for consumption by MCP-compatible clients
Sample Architecture
This sample creates three agents with different trigger configurations:
| Agent | Role | HTTP Trigger | MCP Tool Trigger | Description |
|---|---|---|---|---|
| Joker | Comedy specialist | ✅ Enabled | ❌ Disabled | Accessible only via HTTP requests |
| StockAdvisor | Financial data | ❌ Disabled | ✅ Enabled | Accessible only as MCP tool |
| PlantAdvisor | Indoor plant recommendations | ✅ Enabled | ✅ Enabled | Accessible via both HTTP and MCP |
Environment Setup
See the README.md file in the parent directory for complete setup instructions, including:
- Prerequisites installation
- Azure OpenAI configuration
- Durable Task Scheduler setup
- Storage emulator configuration
Configuration
Update your local.settings.json with your Azure OpenAI credentials:
{
"Values": {
"AZURE_OPENAI_ENDPOINT": "https://your-resource.openai.azure.com/",
"AZURE_OPENAI_CHAT_DEPLOYMENT_NAME": "your-deployment-name",
"AZURE_OPENAI_KEY": "your-api-key-if-not-using-rbac"
}
}
Running the Sample
-
Start the Function App:
cd python/samples/04-hosting/azure_functions/08_mcp_server func start -
Note the MCP Server Endpoint: When the app starts, you'll see the MCP server endpoint in the terminal output. It will look like:
MCP server endpoint: http://localhost:7071/runtime/webhooks/mcp
Testing MCP Tool Integration
Using MCP Inspector
- Install the MCP Inspector
- Connect using the MCP server endpoint from your terminal output
- Select "Streamable HTTP" as the transport method
- Test the available MCP tools:
StockAdvisor- Available only as MCP toolPlantAdvisor- Available as both HTTP and MCP tool
Using Other MCP Clients
Any MCP-compatible client can connect to the server endpoint and utilize the exposed agent tools. The agents will appear as callable tools within the MCP protocol.
Testing HTTP Endpoints
For agents with HTTP triggers enabled (Joker and PlantAdvisor), you can test them using curl:
# Test Joker agent (HTTP only)
curl -X POST http://localhost:7071/api/agents/Joker/run \
-H "Content-Type: application/json" \
-d '{"message": "Tell me a joke"}'
# Test PlantAdvisor agent (HTTP and MCP)
curl -X POST http://localhost:7071/api/agents/PlantAdvisor/run \
-H "Content-Type: application/json" \
-d '{"message": "Recommend an indoor plant"}'
Note: StockAdvisor does not have HTTP endpoints and is only accessible via MCP tool triggers.
Expected Output
HTTP Responses will be returned directly to your HTTP client.
MCP Tool Responses will be visible in:
- The terminal where
func startis running - Your MCP client interface
- The DTS dashboard at
http://localhost:8080(if using Durable Task Scheduler)
Health Check
Check the health endpoint to see which agents have which triggers enabled:
curl http://localhost:7071/api/health
Expected response:
{
"status": "healthy",
"agents": [
{
"name": "Joker",
"type": "Agent",
"http_endpoint_enabled": true,
"mcp_tool_enabled": false
},
{
"name": "StockAdvisor",
"type": "Agent",
"http_endpoint_enabled": false,
"mcp_tool_enabled": true
},
{
"name": "PlantAdvisor",
"type": "Agent",
"http_endpoint_enabled": true,
"mcp_tool_enabled": true
}
],
"agent_count": 3
}
Code Structure
The sample shows how to enable MCP tool triggers with flexible agent configuration:
from agent_framework.azure import AgentFunctionApp, AzureOpenAIChatClient
# Create Azure OpenAI Chat Client
client = AzureOpenAIChatClient()
# Define agents with different roles
joker_agent = client.as_agent(
name="Joker",
instructions="You are good at telling jokes.",
)
stock_agent = client.as_agent(
name="StockAdvisor",
instructions="Check stock prices.",
)
plant_agent = client.as_agent(
name="PlantAdvisor",
instructions="Recommend plants.",
description="Get plant recommendations.",
)
# Create the AgentFunctionApp
app = AgentFunctionApp(enable_health_check=True)
# Configure agents with different trigger combinations:
# HTTP trigger only (default)
app.add_agent(joker_agent)
# MCP tool trigger only (HTTP disabled)
app.add_agent(stock_agent, enable_http_endpoint=False, enable_mcp_tool_trigger=True)
# Both HTTP and MCP tool triggers enabled
app.add_agent(plant_agent, enable_http_endpoint=True, enable_mcp_tool_trigger=True)
This automatically creates the following endpoints based on agent configuration:
POST /api/agents/{AgentName}/run- HTTP endpoint (whenenable_http_endpoint=True)- MCP tool triggers for agents with
enable_mcp_tool_trigger=True GET /api/health- Health check endpoint showing agent configurations