Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

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

For this sample, you'll also need to install node.js in order to use the MCP Inspector tool.

Configuration

Update your local.settings.json with your Azure OpenAI credentials:

{
  "Values": {
    "AZURE_OPENAI_ENDPOINT": "https://your-resource.openai.azure.com/",
    "AZURE_OPENAI_DEPLOYMENT_NAME": "your-deployment-name",
    "AZURE_OPENAI_API_KEY": "your-api-key-if-not-using-rbac"
  }
}

Running the Sample

  1. Start the Function App:

    cd dotnet/samples/04-hosting/DurableAgents/AzureFunctions/07_AgentAsMcpTool
    func start
  2. 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

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.

Using MCP Inspector

  1. Run the MCP Inspector from the command line:

    npx @modelcontextprotocol/inspector
  2. Connect using the MCP server endpoint from your terminal output

    • For Transport Type, select "Streamable HTTP"
    • For URL, enter the MCP server endpoint http://localhost:7071/runtime/webhooks/mcp
    • Click the Connect button
  3. Click the List Tools button to see the available MCP tools. You should see the StockAdvisor and PlantAdvisor tools.

  4. Test the available MCP tools:

    • StockAdvisor - Set "MSFT ATH" (ATH is "all time high") as the query and click the Run Tool button.
    • PlantAdvisor - Set "Low light in Seattle" as the query and click the Run Tool button.

You'll see the results of the tool calls in the MCP Inspector interface under the Tool Results section. You should also see the results in the terminal where you ran the func start command.