Skip to content

Merge main into live #46016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions .openpublishing.redirection.csharp.json
Original file line number Diff line number Diff line change
Expand Up @@ -4042,12 +4042,12 @@
},
{
"source_path_from_root": "/docs/csharp/quick-starts/interpolated-strings-local.md",
"redirect_url": "/dotnet/csharp/tutorials/exploration/interpolated-strings-local",
"redirect_document_id": true
"redirect_url": "/dotnet/csharp/tutorials/string-interpolation"
},
{
"source_path_from_root": "/docs/csharp/quick-starts/interpolated-strings.md",
"redirect_url": "/dotnet/csharp/tutorials/exploration/interpolated-strings"
"source_path_from_root": "/docs/csharp/quick-starts/interpolated-strings.yml",
"redirect_url": "/dotnet/csharp/tutorials/string-interpolation",
"redirect_document_id": true
},
{
"source_path_from_root": "/docs/csharp/quick-starts/introduction-to-classes.md",
Expand All @@ -4060,7 +4060,7 @@
},
{
"source_path_from_root": "/docs/csharp/quick-starts/local-environment.md",
"redirect_url": "/dotnet/csharp/tour-of-csharp/tutorials",
"redirect_url": "/dotnet/csharp/tour-of-csharp/tutorials/",
"redirect_document_id": true
},
{
Expand Down Expand Up @@ -4208,6 +4208,14 @@
"source_path_from_root": "/docs/csharp/tutorials/exploration/top-level-statements.md",
"redirect_url": "/dotnet/csharp/tutorials/top-level-statements"
},
{
"source_path_from_root": "/docs/csharp/tutorials/exploration/interpolated-strings-local.md",
"redirect_url": "/dotnet/csharp/tutorials/string-interpolation"
},
{
"source_path_from_root": "/docs/csharp/tutorials/exploration/interpolated-strings.yml",
"redirect_url": "/dotnet/csharp/tutorials/string-interpolation"
},
{
"source_path_from_root": "/docs/csharp/tutorials/generate-consume-asynchronous-stream.md",
"redirect_url": "/dotnet/csharp/asynchronous-programming/generate-consume-asynchronous-stream"
Expand Down Expand Up @@ -4242,11 +4250,11 @@
},
{
"source_path_from_root": "/docs/csharp/tutorials/intro-to-csharp/interpolated-strings-local.md",
"redirect_url": "/dotnet/csharp/tutorials/exploration/interpolated-strings-local"
"redirect_url": "/dotnet/csharp/tutorials/interpolated-strings"
},
{
"source_path_from_root": "/docs/csharp/tutorials/intro-to-csharp/interpolated-strings.yml",
"redirect_url": "/dotnet/csharp/tutorials/exploration/interpolated-strings"
"redirect_url": "/dotnet/csharp/tutorials/interpolated-strings"
},
{
"source_path_from_root": "/docs/csharp/tutorials/intro-to-csharp/introduction-to-classes.md",
Expand Down
100 changes: 100 additions & 0 deletions docs/ai/get-started-mcp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
title: Get started with .NET AI and MCP
description: Learn about .NET AI and MCP key concepts and development resources to get started building MCP clients and servers
ms.date: 04/29/2025
ms.topic: overview
ms.custom: devx-track-dotnet, devx-track-dotnet-ai
author: alexwolfmsft
ms.author: alexwolf
# CustomerIntent: As a .NET developer new to OpenAI, I want deploy and use sample code to interact to learn from the sample code to summarize text.
---

# Get started with .NET AI and the Model Context Protocol

The Model Context Protocol (MCP) is an open protocol designed to standardize integrations between AI apps and external tools and data sources. By using MCP, developers can enhance the capabilities of AI models, enabling them to produce more accurate, relevant, and context-aware responses.

For example, using MCP, you can connect your LLM to resources such as:

- Document databases or storage services.
- Web APIs that expose business data or logic.
- Tools that manage files or performing local tasks on a user's device.

Many Microsoft products already support MCP, including:

- [Copilot Studio](https://www.microsoft.com/microsoft-copilot/blog/copilot-studio/introducing-model-context-protocol-mcp-in-copilot-studio-simplified-integration-with-ai-apps-and-agents/)
- [Visual Studio Code GitHub Copilot agent mode](https://code.visualstudio.com/blogs/2025/02/24/introducing-copilot-agent-mode)
- [Semantic Kernel](https://devblogs.microsoft.com/semantic-kernel/integrating-model-context-protocol-tools-with-semantic-kernel-a-step-by-step-guide/).

You can use the [MCP C# SDK](#develop-with-the-mcp-c-sdk) to quickly create your own MCP integrations and switch between different AI models without significant code changes.

### MCP client-server architecture

MCP uses a client-server architecture that enables an AI-powered app (the host) to connect to multiple MCP servers through MCP clients:

- **MCP Hosts**: AI tools, code editors, or other software that enhance their AI models using contextual resources through MCP. For example, GitHub Copilot in Visual Studio Code can act as an MCP host and use MCP clients and servers to expand its capabilities.
- **MCP Clients**: Clients used by the host application to connect to MCP servers to retrieve contextual data.
- **MCP Servers**: Services that expose capabilities to clients through MCP. For example, an MCP server might provide an abstraction over a REST API or local data source to provide business data to the AI model.

The following diagram illustrates this architecture:

:::image type="content" source="media/mcp/model-context-protocol-architecture-diagram.png" alt-text="A diagram showing the architecture pattern of MCP, including hosts, clients, and servers.":::

MCP client and server can exchange a set of standard messages:

| Message | Description |
|---------------------|-------------|
| `InitializeRequest` | This request is sent by the client to the server when it first connects, asking it to begin initialization. |
|`ListToolsRequest` | Sent by the client to request a list of tools the server has. |
|`CallToolRequest` | Used by the client to invoke a tool provided by the server. |
|`ListResourcesRequest` | Sent by the client to request a list of available server resources. |
|`ReadResourceRequest` | Sent by the client to the server to read a specific resource URI. |
|`ListPromptsRequest` | Sent by the client to request a list of available prompts and prompt templates from the server. |
|`GetPromptRequest` | Used by the client to get a prompt provided by the server. |
|`PingRequest` | A ping, issued by either the server or the client, to check that the other party is still alive. |
|`CreateMessageRequest` | A request by the server to sample an LLM via the client. The client has full discretion over which model to select. The client should also inform the user before beginning sampling, to allow them to inspect the request (human in the loop) and decide whether to approve it. |
|`SetLevelRequest` | A request by the client to the server, to enable or adjust logging. |

## Develop with the MCP C# SDK

As a .NET developer, you can use MCP by creating MCP clients and servers to enhance your apps with custom integrations. MCP reduces the complexity involved in connecting an AI model to various tools, services, and data sources.

The official [MCP C# SDK](https://github.com/modelcontextprotocol/csharp-sdk) is available through NuGet and enables you to build MCP clients and servers for .NET apps and libraries. The SDK is maintained through collaboration between Microsoft, Anthropic, and the MCP open protocol organization.

To get started, add the MCP C# SDK to your project:

```dotnetcli
dotnet add package ModelContextProtocol --prerelease
```

Instead of building unique connectors for each integration point, you can often leverage or reference prebuilt integrations from various providers such as GitHub and Docker:

- [Available MPC clients](https://modelcontextprotocol.io/clients)
- [Available MCP servers](https://modelcontextprotocol.io/examples)

### Integration with Microsoft.Extensions.AI

The MCP C# SDK depends on the [Microsoft.Extensions.AI libraries](/dotnet/ai/ai-extensions) to handle various AI interactions and tasks. These extension libraries provides core types and abstractions for working with AI services, so developers can focus on coding against conceptual AI capabilities rather than specific platforms or provider implementations.

View the MCP C# SDK dependencies on the [NuGet package page](https://www.nuget.org/packages/ModelContextProtocol/0.1.0-preview.11).

## More .NET MCP development resources

Various tools, services, and learning resources are available in the .NET and Azure ecosystems to help you build MCP clients and servers or integrate with existing MCP servers.

Get started with the following development tools:

- [Semantic Kernel](/semantic-kernel/concepts/plugins/adding-mcp-plugins) allows you to add plugins for MCP servers. Semantic Kernel supports both local MCP servers through standard I/O and remote servers that connect through SSE over HTTPS.
- [Azure Functions remote MCP servers](https://devblogs.microsoft.com/dotnet/build-mcp-remote-servers-with-azure-functions/) combine MCP standards with the flexible architecture of Azure Functions. Visit the [Remote MCP functions sample repository](https://aka.ms/cadotnet/mcp/functions/remote-sample) for code examples.
- [Azure MCP Server](https://github.com/Azure/azure-mcp) implements the MCP specification to seamlessly connect AI agents with key Azure services like Azure Storage, Cosmos DB, and more.

Learn more about .NET and MCP using these resources:

- [Microsoft partners with Anthropic to create official C# SDK for Model Context Protocol](https://devblogs.microsoft.com/blog/microsoft-partners-with-anthropic-to-create-official-c-sdk-for-model-context-protocol)
- [Build a Model Context Protocol (MCP) server in C#](https://devblogs.microsoft.com/dotnet/build-a-model-context-protocol-mcp-server-in-csharp/)
- [MCP C# SDK README](https://github.com/modelcontextprotocol/csharp-sdk/blob/main/README.md)

## Related content

- [Overview of the .NET + AI ecosystem](/dotnet/ai/dotnet-ai-ecosystem)
- [Microsoft.Extensions.AI](/dotnet/ai/ai-extensions)
- [Semantic Kernel overview for .NET](/dotnet/ai/semantic-kernel-dotnet-overview)
14 changes: 7 additions & 7 deletions docs/ai/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ landingContent:
# Card
- title: Get started
linkLists:
- linkListType: get-started
- linkListType: overview
links:
- text: Develop .NET apps with AI features
url: overview.md
- text: Connect to and prompt an AI model
url: quickstarts/prompt-model.md
- text: Microsoft.Extensions.AI libraries
url: microsoft-extensions-ai.md
- linkListType: get-started
links:
- text: Connect to and prompt an AI model
url: quickstarts/prompt-model.md
- text: Build an Azure AI chat app
url: quickstarts/get-started-openai.md
- text: Summarize text using an Azure OpenAI chat app
url: quickstarts/quickstart-openai-summarize-text.md
url: quickstarts/build-chat-app.md
- text: Generate images using Azure AI
url: quickstarts/quickstart-openai-generate-images.md
url: quickstarts/generate-images.md

# Card
- title: Essential concepts
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion docs/ai/quickstarts/evaluate-ai-response.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ ms.custom: devx-track-dotnet, devx-track-dotnet-ai
In this quickstart, you create an MSTest app to evaluate the chat response of an OpenAI model. The test app uses the [Microsoft.Extensions.AI.Evaluation](https://www.nuget.org/packages/Microsoft.Extensions.AI.Evaluation) libraries.

> [!NOTE]
> This quickstart demonstrates the simplest usage of the evaluation API. Notably, it doesn't demonstrate use of the [response caching](../conceptual/evaluation-libraries.md#cached-responses) and [reporting](../conceptual/evaluation-libraries.md#reporting) functionality, which are important if you're authoring unit tests that run as part of an "offline" evaluation pipeline. The scenario shown in this quickstart is suitable in use cases such as "online" evaluation of AI responses within production code and logging scores to telemetry, where caching and reporting aren't relevant. For a tutorial that demonstrates the caching and reporting functionality, see [Tutorial: Evaluate a model's response with response caching and reporting](../tutorials/evaluate-with-reporting.md)
>
> - The `Microsoft.Extensions.AI.Evaluation` library is currently in Preview.
> - This quickstart demonstrates the simplest usage of the evaluation API. Notably, it doesn't demonstrate use of the [response caching](../conceptual/evaluation-libraries.md#cached-responses) and [reporting](../conceptual/evaluation-libraries.md#reporting) functionality, which are important if you're authoring unit tests that run as part of an "offline" evaluation pipeline. The scenario shown in this quickstart is suitable in use cases such as "online" evaluation of AI responses within production code and logging scores to telemetry, where caching and reporting aren't relevant. For a tutorial that demonstrates the caching and reporting functionality, see [Tutorial: Evaluate a model's response with response caching and reporting](../tutorials/evaluate-with-reporting.md)

## Prerequisites

Expand Down
12 changes: 6 additions & 6 deletions docs/ai/quickstarts/generate-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Complete the following steps to create a .NET console app to connect to an AI mo

## Add the app code

1. In the **Program.cs** file, add the following code to connect and authenticate to the AI model.
1. In the `Program.cs` file, add the following code to connect and authenticate to the AI model.

:::zone target="docs" pivot="azure-openai"

Expand All @@ -117,12 +117,12 @@ Complete the following steps to create a .NET console app to connect to an AI mo

The preceding code:

- Reads essential configuration values from the project user secrets to connect to the AI model
- Creates an `ImageClient` to connect to the AI model
- Sends a prompt to the model that describes the desired image
- Prints the URL of the generated image to the console output
- Reads essential configuration values from the project user secrets to connect to the AI model.
- Creates an `OpenAI.Images.ImageClient` to connect to the AI model.
- Sends a prompt to the model that describes the desired image.
- Prints the URL of the generated image to the console output.

1. Use the `dotnet run` command to run the app:
1. Run the app:

```dotnetcli
dotnet run
Expand Down
2 changes: 1 addition & 1 deletion docs/ai/quickstarts/includes/clone-sample-repo.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ms.date: 07/03/2024
ms.topic: include
---

## Clone the sample repository
## (Optional) Clone the sample repository

You can create your own app using the steps in the sections ahead, or you can clone the GitHub repository that contains the completed sample apps for all of the quickstarts. If you plan to use Azure OpenAI, the sample repo is also structured as an Azure Developer CLI template that can provision an Azure OpenAI resource for you.

Expand Down
22 changes: 4 additions & 18 deletions docs/ai/quickstarts/includes/create-ai-service.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
## Create the AI service

# [Azure Developer CLI](#tab/azd)

[!INCLUDE [deploy-azd](deploy-azd.md)]

# [Azure CLI](#tab/azure-cli)
# [Azure Portal or Azure CLI](#tab/azure-cli)

1. To provision an Azure OpenAI service and model using the Azure CLI, complete the steps in the [Create and deploy an Azure OpenAI Service resource](/azure/ai-services/openai/how-to/create-resource?pivots=cli) article.
1. To provision an Azure OpenAI service and model, complete the steps in the [Create and deploy an Azure OpenAI Service resource](/azure/ai-services/openai/how-to/create-resource) article.

1. From a terminal or command prompt, navigate to the root of your project directory.

Expand All @@ -18,18 +14,8 @@
dotnet user-secrets set AZURE_OPENAI_GPT_NAME <your-azure-openai-model-name>
```

# [Azure Portal](#tab/azure-portal)

1. To provision an Azure OpenAI service and model using the Azure portal, complete the steps in the [Create and deploy an Azure OpenAI Service resource](/azure/ai-services/openai/how-to/create-resource?pivots=web-portal) article.

1. From a terminal or command prompt, navigate to the root of your project directory.

1. Run the following commands to configure your Azure OpenAI endpoint and model name for the sample app:
# [Azure Developer CLI](#tab/azd)

```bash
dotnet user-secrets init
dotnet user-secrets set AZURE_OPENAI_ENDPOINT <your-openai-key>
dotnet user-secrets set AZURE_OPENAI_GPT_NAME <your-azure-openai-model-name>
```
[!INCLUDE [deploy-azd](deploy-azd.md)]

---
Loading
Loading