-
Notifications
You must be signed in to change notification settings - Fork 6k
Add quickstart for minimal MCP Server using .NET and publish to NuGet #47007
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
Changes from 6 commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
0898b44
Initial draft
JonDouglas 0929dc4
Fix image path
JonDouglas cfd6d95
Add to ToC
JonDouglas 2e218fc
Fix NuGet link
JonDouglas 881fdb4
Fix download link
JonDouglas 67feebd
Add VS docs
JonDouglas 15e1148
Update docs/ai/quickstarts/build-mcp-server-publish-nuget.md
JonDouglas 3b81b04
Update docs/ai/quickstarts/build-mcp-server-publish-nuget.md
JonDouglas 7da8068
Update docs/ai/quickstarts/build-mcp-server-publish-nuget.md
JonDouglas 73dcd40
Update docs/ai/quickstarts/build-mcp-server-publish-nuget.md
JonDouglas 36301eb
Update docs/ai/quickstarts/build-mcp-server-publish-nuget.md
JonDouglas d57afb3
Update docs/ai/quickstarts/build-mcp-server-publish-nuget.md
JonDouglas 2eebf55
Add to list
JonDouglas 9b44d02
Update pkg args
JonDouglas 3b6816e
Fix indention, use auto-number, fix tool name based on latest templat…
joelverhagen 9238f77
Undo
joelverhagen 4a6351d
Update docs/ai/quickstarts/build-mcp-server-publish-nuget.md
joelverhagen f2e4f02
Update image with new tool name
joelverhagen c04f9e7
Merge into existing quickstart
joelverhagen a525a33
Improve
joelverhagen eb6d4e4
Fix lint issues
joelverhagen 790d356
Fix up
joelverhagen a9e8b7d
Improve sample, suggest int environment as an option
joelverhagen c402d78
Fix
joelverhagen b145877
Fix method name
joelverhagen 12f65e1
Word
joelverhagen 5f63725
Fix lint
joelverhagen 7950495
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen 72323e6
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen 2903727
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen 5aaf9ca
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen 62b7731
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen 444dda7
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen 6aa8a64
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen 98b668b
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen af7bb13
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen e7eef78
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen 384ca48
Indent and polish
joelverhagen 5ece1ef
Move to snippet
joelverhagen 3720db2
Use full snippet
joelverhagen 1c7b5ee
Lint
joelverhagen 6e6d072
Fix rename references
joelverhagen 13d8f52
Update docs/ai/quickstarts/build-mcp-server.md
joelverhagen d6ece12
Fix URLs
joelverhagen cff7ef1
Add NuGet.org screenshots
joelverhagen 5d71c33
Bigger screenshots
joelverhagen a2e9b7d
Use real template version
joelverhagen 295ea8d
Add a trouble shooting section for tool not being called
joelverhagen e8ead19
Update embedded sample
joelverhagen b4c2ca8
Update screenshot
joelverhagen 140b995
Fix up inputs
joelverhagen e74233c
Polish
joelverhagen 2d991f1
Update based on blog and latest template
joelverhagen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 using .NET to NuGet | ||
JonDouglas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
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) | ||
joelverhagen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- [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) | ||
JonDouglas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## 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 | ||
joelverhagen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
joelverhagen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
``` | ||
|
||
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": { | ||
joelverhagen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
"MinimalMcpServer": { | ||
"type": "stdio", | ||
"command": "dotnet", | ||
"args": [ | ||
"run", | ||
"--project", | ||
"<path-to-your-csproj>", | ||
joelverhagen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
"--", | ||
"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. | ||
joelverhagen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
:::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 | ||
JonDouglas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
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": [ | ||
{ | ||
JonDouglas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
"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> | ||
joelverhagen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
``` | ||
|
||
See [Publish a package](https://learn.microsoft.com/nuget/nuget-org/publish-a-package) for more information. | ||
JonDouglas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## 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. | ||
JonDouglas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
3. In your `mcp.json` file in the `.vscode` folder, add the following: | ||
|
||
```json | ||
{ | ||
"servers": { | ||
"MinimalMcpServer": { | ||
"type": "stdio", | ||
"command": "dotnet", | ||
"args": [ "tool", | ||
"exec", | ||
joelverhagen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
"<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) | ||
JonDouglas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
[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) | ||
JonDouglas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
[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) | ||
JonDouglas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.