Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
0898b44
Initial draft
JonDouglas Jun 30, 2025
0929dc4
Fix image path
JonDouglas Jun 30, 2025
cfd6d95
Add to ToC
JonDouglas Jun 30, 2025
2e218fc
Fix NuGet link
JonDouglas Jun 30, 2025
881fdb4
Fix download link
JonDouglas Jun 30, 2025
67feebd
Add VS docs
JonDouglas Jun 30, 2025
15e1148
Update docs/ai/quickstarts/build-mcp-server-publish-nuget.md
JonDouglas Jul 1, 2025
3b81b04
Update docs/ai/quickstarts/build-mcp-server-publish-nuget.md
JonDouglas Jul 1, 2025
7da8068
Update docs/ai/quickstarts/build-mcp-server-publish-nuget.md
JonDouglas Jul 1, 2025
73dcd40
Update docs/ai/quickstarts/build-mcp-server-publish-nuget.md
JonDouglas Jul 1, 2025
36301eb
Update docs/ai/quickstarts/build-mcp-server-publish-nuget.md
JonDouglas Jul 1, 2025
d57afb3
Update docs/ai/quickstarts/build-mcp-server-publish-nuget.md
JonDouglas Jul 1, 2025
2eebf55
Add to list
JonDouglas Jul 1, 2025
9b44d02
Update pkg args
JonDouglas Jul 1, 2025
3b6816e
Fix indention, use auto-number, fix tool name based on latest templat…
joelverhagen Jul 1, 2025
9238f77
Undo
joelverhagen Jul 1, 2025
4a6351d
Update docs/ai/quickstarts/build-mcp-server-publish-nuget.md
joelverhagen Jul 1, 2025
f2e4f02
Update image with new tool name
joelverhagen Jul 1, 2025
c04f9e7
Merge into existing quickstart
joelverhagen Jul 2, 2025
a525a33
Improve
joelverhagen Jul 2, 2025
eb6d4e4
Fix lint issues
joelverhagen Jul 2, 2025
790d356
Fix up
joelverhagen Jul 2, 2025
a9e8b7d
Improve sample, suggest int environment as an option
joelverhagen Jul 2, 2025
c402d78
Fix
joelverhagen Jul 2, 2025
b145877
Fix method name
joelverhagen Jul 2, 2025
12f65e1
Word
joelverhagen Jul 2, 2025
5f63725
Fix lint
joelverhagen Jul 3, 2025
7950495
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen Jul 3, 2025
72323e6
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen Jul 3, 2025
2903727
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen Jul 3, 2025
5aaf9ca
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen Jul 3, 2025
62b7731
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen Jul 3, 2025
444dda7
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen Jul 3, 2025
6aa8a64
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen Jul 3, 2025
98b668b
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen Jul 3, 2025
af7bb13
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen Jul 3, 2025
e7eef78
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen Jul 3, 2025
384ca48
Indent and polish
joelverhagen Jul 3, 2025
5ece1ef
Move to snippet
joelverhagen Jul 3, 2025
3720db2
Use full snippet
joelverhagen Jul 3, 2025
1c7b5ee
Lint
joelverhagen Jul 3, 2025
6e6d072
Fix rename references
joelverhagen Jul 3, 2025
13d8f52
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen Jul 3, 2025
d6ece12
Fix URLs
joelverhagen Jul 3, 2025
cff7ef1
Add NuGet.org screenshots
joelverhagen Jul 3, 2025
5d71c33
Bigger screenshots
joelverhagen Jul 3, 2025
a2e9b7d
Use real template version
joelverhagen Jul 8, 2025
295ea8d
Add a trouble shooting section for tool not being called
joelverhagen Jul 8, 2025
e8ead19
Update embedded sample
joelverhagen Jul 9, 2025
b4c2ca8
Update screenshot
joelverhagen Jul 9, 2025
140b995
Fix up inputs
joelverhagen Jul 9, 2025
e74233c
Polish
joelverhagen Jul 9, 2025
2d991f1
Update based on blog and latest template
joelverhagen Jul 14, 2025
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
Binary file added docs/ai/media/mcp/available-tools-nuget.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
220 changes: 220 additions & 0 deletions docs/ai/quickstarts/build-mcp-server-publish-nuget.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
---
title: Quickstart - Create a minimal MCP Server using .NET and publish to NuGet
description: Learn to create and connect to a minimal MCP server using .NET and publish it to NuGet.
ms.date: 06/30/2025
ms.topic: quickstart
ms.custom: devx-track-dotnet, devx-track-dotnet-ai
author: jondouglas
ms.author: jondouglas
---

# Create, connect, and publish a minimal MCP server to NuGet

In this quickstart, you create a minimal Model Context Protocol (MCP) server using the [C# SDK for MCP](https://github.com/modelcontextprotocol/csharp-sdk), connect to it using GitHub Copilot, and publish it to NuGet. MCP servers are services that expose capabilities to clients through the Model Context Protocol (MCP).

## Prerequisites

- [.NET 10.0 SDK or higher](https://dotnet.microsoft.com/download/dotnet)
- [Visual Studio Code](https://code.visualstudio.com/)
- [GitHub Copilot extension](https://marketplace.visualstudio.com/items?itemName=GitHub.copilot) for Visual Studio Code
- [NuGet account](https://www.nuget.org/users/account/LogOn)

## Create the project

1. In a terminal window, install the `dotnet new mcpserver` template:

```bash
dotnet new install Microsoft.Extensions.AI.Templates::9.6.0-preview.2.25310.2
```

2. Create a new MCP server app with the `dotnet new mcpserver` command:

```bash
dotnet new mcpserver -n MinimalMcpServer
```

3. Navigate to the `MinimalMcpServer` directory:

```bash
cd MinimalMcpServer
```

4. Build the project:

```bash
dotnet build
```

## Configure the MCP server in Visual Studio Code

Configure GitHub Copilot for Visual Studio Code to use your custom MCP server:

1. If you haven't already, open your project folder in Visual Studio Code.
2. Create a `.vscode` folder at the root of your project.
3. Add an `mcp.json` file in the `.vscode` folder with the following content:

```json
{
"servers": {
"MinimalMcpServer": {
"type": "stdio",
"command": "dotnet",
"args": [
"run",
"--project",
"<path-to-your-csproj>",
"--",
"start-mcp"
],
"env": {
"MAX_RANDOM_NUMBER": 100
}
}
}
}
```

4. Save the file.

## Test the MCP server

1. Open GitHub Copilot in Visual Studio Code and switch to agent mode.

2. Select the **Select tools** icon to verify your **MinimalMcpServer** is available with both tools listed.

:::image type="content" source="../media/mcp/available-tools-nuget.png" alt-text="A screenshot showing the available MCP tools.":::

3. Enter a prompt to run the **GetRandomNumber** tool:

```console
Give me a random number between 1 and 100.
```

4. GitHub Copilot requests permission to run the **GetRandomNumber** tool for your prompt. Select **Continue** or use the arrow to select a more specific behavior:

- **Current session** always runs the operation in the current GitHub Copilot Agent Mode session.
- **Current workspace** always runs the command for the current Visual Studio Code workspace.
- **Always allow** sets the operation to always run for any GitHub Copilot Agent Mode session or any Visual Studio Code workspace.

5. Verify that the server responds with the echoed message:

```output
Your random number is 9.
```

## Pack and publish to NuGet

1. Update the `<PackageId>` in the `.csproj` file to be unique on NuGet.org.

2. Update your `.mcp/server.json` file with your respective MCP configuration details.

```json
{
"description": "<your description here>",
"name": "io.github.<your GitHub username here>/<your repo name>",
"packages": [
{
"registry_name": "nuget",
"name": "<your package ID here>",
"version": "0.1.0-beta",
"package_arguments": [
{
"description": "Start the MCP server tool in server mode",
"is_required": true,
"format": "string",
"value": "start-mcp",
"default": "start-mcp",
"type": "positional",
"value_hint": "start-mcp"
}
],
"environment_variables": [
{
"description": "The maximum number to return from the random number generator",
"name": "MAX_RANDOM_NUMBER"
}
]
}
],
"repository": {
"url": "https://github.com/<your GitHub username here>/<your repo name>",
"source": "github"
},
"version_detail": {
"version": "0.1.0-beta"
}
}
```

3. Pack the project:

```bash
dotnet pack -c Release
```

4. Publish the package to NuGet:

```bash
dotnet nuget push <path-to-nupkg-file> --source nuget.org --api-key <your-api-key>
```

For more information, see [Publish a package](/nuget/nuget-org/publish-a-package).

## Discover MCP servers on NuGet.org

1. Browse for your MCP Server package on [NuGet.org](https://www.nuget.org/packages?q=&includeComputedFrameworks=true&packagetype=mcpserver&prerel=true&sortby=relevance).

2. View the MCP Server details and copy the JSON.

3. In your `mcp.json` file in the `.vscode` folder, add the following:

```json
{
"servers": {
"MinimalMcpServer": {
"type": "stdio",
"command": "dotnet",
"args": [ "tool",
"exec",
"<your-package-id>",
"--version",
"0.0.1-beta",
"--yes",
"--",
"start-mcp"

],
"env": {
"MAX_RANDOM_NUMBER": 100
}
}
}
}
```

4. Save the file.

5. In GitHub Copilot, select the **Select tools** icon to verify your **MinimalMcpServer** is available with the tools listed.

6. Enter a prompt to run the **GetRandomNumber** tool:

```console
Give me a random number between 1 and 100.
```

7. Verify that the server responds with the echoed message:

```output
Your random number is 9.
```

## Related content

[Build a minimal MCP server](build-mcp-server.md)
[Get started with .NET AI and the Model Context Protocol](../get-started-mcp.md)
[Use agent mode in VS Code](https://code.visualstudio.com/docs/copilot/chat/chat-agent-mode)
[Use agent mode in Visual Studio](https://learn.microsoft.com/visualstudio/ide/copilot-agent-mode)
[Model Context Protocol .NET Samples](https://github.com/microsoft/mcp-dotnet-samples)
[What's New in .NET 10](https://learn.microsoft.com/dotnet/whats-new/dotnet-10)
[Find and evaluate NuGet packages for your project](https://learn.microsoft.com/en-us/nuget/consume-packages/finding-and-choosing-packages)
[Publish a package](https://learn.microsoft.com/nuget/nuget-org/publish-a-package)
2 changes: 2 additions & 0 deletions docs/ai/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ items:
href: quickstarts/build-mcp-server.md
- name: Build a minimal MCP client
href: quickstarts/build-mcp-client.md
- name: Build a minimal MCP server and publish to NuGet
href: quickstarts/build-mcp-server-publish-nuget.md
- name: Concepts
items:
- name: How generative AI and LLMs work
Expand Down
Loading