openai-mcp-agent-dotnet

MCP.Pizza Chef: Azure-Samples

openai-mcp-agent-dotnet is a .NET Blazor-based MCP client application that integrates OpenAI models with remote MCP servers. It demonstrates a secure, containerized architecture running on Azure Container Apps, connecting to a TypeScript-based MCP server. This client app supports authentication and enables developers to build AI agents leveraging OpenAI, Azure OpenAI, and other LLM providers within the MCP ecosystem.

Use This MCP client To

Build AI agents using OpenAI models with any MCP server Connect .NET applications to remote MCP servers securely Deploy MCP clients and servers on Azure Container Apps Implement authentication for MCP client-server communication Develop AI-enhanced workflows in .NET Blazor environments Demonstrate integration of OpenAI models with MCP protocol

README

.NET OpenAI MCP Agent

This is an MCP agent app written in .NET, using Azure OpenAI, with a remote MCP server written in TypeScript.

Features

This app provides features like:

  • The MCP host + MCP client app is written in .NET Blazor.
  • The MCP client app connects to a to-do MCP server written in TypeScript.
  • Both MCP client and server apps are running on Azure Container Apps (ACA).
  • The MCP client app is secured by the built-in auth of ACA.
  • The MCP server app is only accessible from the MCP client app.

Overall architecture diagram

Prerequisites

Getting Started

You can now use GitHub Codespaces to run this sample app (takes several minutes to open it)! 👉 Open in GitHub Codespaces.

Get Azure AI Foundry or GitHub Models

Get the sample app

  1. Clone this repo.

    git clone https://github.com/Azure-Samples/openai-mcp-agent-dotnet.git
  2. Clone the MCP server.

    cd openai-mcp-agent-dotnet
    git clone https://github.com/Azure-Samples/mcp-container-ts.git ./src/McpTodo.ServerApp
  3. Make sure that your deployed model name is gpt-4o. If your deployed model is different, update src/McpTodo.ClientApp/appsettings.json.

    {
      "OpenAI": {
        // Make sure this is the right deployment name.
        "DeploymentName": "gpt-4o"
      }
    }

Run it on Azure

  1. Check that you have the necessary permissions:

  2. Login to Azure.

    azd auth login
  3. Initialize azd.

    azd init

    NOTE: You'll be asked to enter an environment name, which will be the name of your Azure Resource Group.

  4. Deploy apps to Azure.

    azd up

    NOTE:

    1. By default, the MCP client app is protected by the ACA built-in auth feature. You can turn off this feature before running azd up by setting:

      azd env set USE_LOGIN false
    2. During the deployment, you will be asked to enter the Azure Subscription, location and OpenAI connection string. The connection string should be in the format of Endpoint={{AZURE_OPENAI_ENDPOINT}};Key={{AZURE_OPENAI_API_KEY}}.

    3. You can add GitHub PAT in the same format above to use GitHub Models like Endpoint=https://models.inference.ai.azure.com;Key={{GITHUB_PAT}}.

  5. In the terminal, get the client app URL deployed. It might look like:

    https://mcptodo-clientapp.{{some-random-string}}.{{location}}.azurecontainerapps.io/
  6. Navigate to the client app URL, log-in to the app and enter prompts like:

    Give me list of to do.
    Set "meeting at 1pm".
    Give me list of to do.
    Mark #1 as completed.
    Delete #1 from the to-do list.
    

    NOTE: You might not be asked to login, if you've set the USE_LOGIN value to false.

Run it locally

  1. Add Azure OpenAI API Key.

    dotnet user-secrets --project ./src/McpTodo.ClientApp set ConnectionStrings:openai "Endpoint={{AZURE_OPENAI_ENDPOINT}};Key={{AZURE_OPENAI_API_KEY}}"

    NOTE: You can add GitHub PAT in the same format above to use GitHub Models like Endpoint=https://models.inference.ai.azure.com;Key={{GITHUB_PAT}}.

  2. Install npm packages.

    pushd ./src/McpTodo.ServerApp
    npm install
    popd
  3. Install NuGet packages.

    dotnet restore && dotnet build
  4. Run the host app.

    cd ./src/McpTodo.ServerApp
    npm start
  5. Run the client app in another terminal.

    dotnet watch run --project ./src/McpTodo.ClientApp
  6. Navigate to https://localhost:7256 or http://localhost:5011 and enter prompts like:

    Give me list of to do.
    Set "meeting at 1pm".
    Give me list of to do.
    Mark #1 as completed.
    Delete #1 from the to-do list.
    

Run it in local containers

  1. Make sure that you're running either Docker Desktop or Podman Desktop on your local machine.

  2. Export user secrets to .env.

    # bash/zsh
    dotnet user-secrets list --project src/McpTodo.ClientApp \
        | sed 's/ConnectionStrings:openai/ConnectionStrings__openai/' > .env
    # PowerShell
    (dotnet user-secrets list --project src/McpTodo.ClientApp) `
        -replace "ConnectionStrings:openai", "ConnectionStrings__openai" | Out-File ".env" -Force
  3. Run both apps in containers.

    # Docker
    docker compose up --build
    # Podman
    podman compose up --build
  4. Navigate to http://localhost:8080 and enter prompts like:

    Give me list of to do.
    Set "meeting at 1pm".
    Give me list of to do.
    Mark #1 as completed.
    Delete #1 from the to-do list.
    

Resources

openai-mcp-agent-dotnet FAQ

How does openai-mcp-agent-dotnet secure communication with the MCP server?
It uses Azure Container Apps' built-in authentication to restrict access to the MCP server.
What programming languages and frameworks are used in openai-mcp-agent-dotnet?
The client is built with .NET Blazor, and the MCP server is written in TypeScript.
Can openai-mcp-agent-dotnet work with other LLM providers besides OpenAI?
Yes, it supports OpenAI, Azure OpenAI, Claude, Gemini, and other MCP-compatible LLMs.
What are the deployment requirements for openai-mcp-agent-dotnet?
It requires .NET 9 SDK, Visual Studio Code with C# Dev Kit, node.js LTS, and Docker Desktop for local development and containerization.
Is the MCP server accessible publicly in this architecture?
No, the MCP server is only accessible from the MCP client app, ensuring secure communication.
How does openai-mcp-agent-dotnet demonstrate MCP protocol usage?
It shows how to create an AI agent client that interacts with a remote MCP server using the MCP protocol.
Can this client be extended to other MCP servers?
Yes, it is designed to connect with any MCP server implementing the protocol, enabling flexible AI agent development.