Files
Ren Finlayson 539852f81c
Some checks are pending
CodeQL / Analyze (csharp) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
dotnet-build-and-test / paths-filter (push) Waiting to run
dotnet-build-and-test / dotnet-build-and-test (Debug, windows-latest, net9.0) (push) Blocked by required conditions
dotnet-build-and-test / dotnet-build-and-test (Release, integration, true, ubuntu-latest, net10.0) (push) Blocked by required conditions
dotnet-build-and-test / dotnet-build-and-test (Release, integration, true, windows-latest, net472) (push) Blocked by required conditions
dotnet-build-and-test / dotnet-build-and-test (Release, ubuntu-latest, net8.0) (push) Blocked by required conditions
dotnet-build-and-test / dotnet-build-and-test-check (push) Blocked by required conditions
test
2026-01-24 03:05:12 +11:00
..
2026-01-24 03:05:12 +11:00
2026-01-24 03:05:12 +11:00
2026-01-24 03:05:12 +11:00

This sample demonstrates how to expose an existing AI agent as an MCP tool.

Run the sample

To run the sample, please use one of the following MCP clients: https://modelcontextprotocol.io/clients

Alternatively, use the QuickstartClient sample from this repository: https://github.com/modelcontextprotocol/csharp-sdk/tree/main/samples/QuickstartClient

Run the sample using MCP Inspector

To use the MCP Inspector, follow these steps:

  1. Open a terminal in the Agent_Step10_AsMcpTool project directory.
  2. Run the npx @modelcontextprotocol/inspector dotnet run command to start the MCP Inspector. Make sure you have node.js and npm installed.
    npx @modelcontextprotocol/inspector dotnet run
    
  3. When the inspector is running, it will display a URL in the terminal, like this:
    MCP Inspector is up and running at http://127.0.0.1:6274
    
  4. Open a web browser and navigate to the URL displayed in the terminal. If not opened automatically, this will open the MCP Inspector interface.
  5. In the MCP Inspector interface, add the following environment variables to allow your MCP server to access Azure AI Foundry Project to create and run the agent:
    • AZURE_FOUNDRY_PROJECT_ENDPOINT = https://your-resource.openai.azure.com/ # Replace with your Azure AI Foundry Project endpoint
    • AZURE_FOUNDRY_PROJECT_DEPLOYMENT_NAME = gpt-4o-mini # Replace with your model deployment name
  6. Find and click the Connect button in the MCP Inspector interface to connect to the MCP server.
  7. As soon as the connection is established, open the Tools tab in the MCP Inspector interface and select the Joker tool from the list.
  8. Specify your prompt as a value for the query argument, for example: Tell me a joke about a pirate and click the Run Tool button to run the tool.
  9. The agent will process the request and return a response in accordance with the provided instructions that instruct it to always start each joke with 'Aye aye, captain!'.