Skip to content
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
Binary file modified 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.
20 changes: 13 additions & 7 deletions docs/ai/quickstarts/build-mcp-server.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Quickstart - Create a minimal MCP server and publish to NuGet
description: Learn to create and connect to a minimal MCP server using C# and publish it to NuGet.
ms.date: 07/02/2025
ms.date: 10/20/2025
ms.topic: quickstart
author: alexwolfmsft
ms.author: alexwolf
Expand All @@ -23,7 +23,7 @@ In this quickstart, you create a minimal Model Context Protocol (MCP) server usi

## Create the project

1. In a terminal window, install the MCP Server template (version 9.7.0-preview.2.25356.2 or newer):
1. In a terminal window, install the MCP Server template (version 9.10.0-preview.3.25513.3 or newer):

```bash
dotnet new install Microsoft.Extensions.AI.Templates
Expand All @@ -35,6 +35,8 @@ In this quickstart, you create a minimal Model Context Protocol (MCP) server usi
dotnet new mcpserver -n SampleMcpServer
```

By default, this command creates a self-contained tool package targeting all of the most common platforms that .NET is supported on. To see more options, use `dotnet new mcpserver --help`.

1. Navigate to the `SampleMcpServer` directory:

```bash
Expand Down Expand Up @@ -125,7 +127,7 @@ In this example, you enhance the MCP server to use a configuration value set in
"args": [
"run",
"--project",
"<RELATIVE PATH TO PROJECT DIRECTORY>"
"<relative-path-to-project-file>"
],
"env": {
"WEATHER_CHOICES": "sunny,humid,freezing"
Expand All @@ -145,13 +147,13 @@ In this example, you enhance the MCP server to use a configuration value set in

1. Update the `.mcp/server.json` to declare your environment variable input. The `server.json` file schema is defined by the [MCP Registry project](https://github.com/modelcontextprotocol/registry/blob/main/docs/reference/server-json/generic-server-json.md) and is used by NuGet.org to generate VS Code MCP configuration.

- Use the `environment_variables` property to declare environment variables used by your app that will be set by the client using the MCP server (for example, VS Code).
- Use the `environmentVariables` property to declare environment variables used by your app that will be set by the client using the MCP server (for example, VS Code).

- Use the `package_arguments` property to define CLI arguments that will be passed to your app. For more examples, see the [MCP Registry project](https://github.com/modelcontextprotocol/registry/blob/main/docs/reference/server-json/generic-server-json.md#examples).
- Use the `packageArguments` property to define CLI arguments that will be passed to your app. For more examples, see the [MCP Registry project](https://github.com/modelcontextprotocol/registry/blob/main/docs/reference/server-json/generic-server-json.md#examples).

:::code language="json" source="snippets/mcp-server/.mcp/server.json":::

The only information used by NuGet.org in the `server.json` is the first `packages` array item with the `registry_name` value matching `nuget`. The other top-level properties aside from the `packages` property are currently unused and are intended for the upcoming central MCP Registry. You can leave the placeholder values until the MCP Registry is live and ready to accept MCP server entries.
The only information used by NuGet.org in the `server.json` is the first `packages` array item with the `registryType` value matching `nuget`. The other top-level properties aside from the `packages` property are currently unused and are intended for the upcoming central MCP Registry. You can leave the placeholder values until the MCP Registry is live and ready to accept MCP server entries.

You can [test your MCP server again](#test-the-mcp-server) before moving forward.

Expand All @@ -163,12 +165,16 @@ You can [test your MCP server again](#test-the-mcp-server) before moving forward
dotnet pack -c Release
```

1. Publish the package to NuGet:
This command produces one tool package and several platform-specific packages based on the `<RuntimeIdentifiers>` list in `SampleMcpServer.csproj`.

1. Publish the packages to NuGet:

```bash
dotnet nuget push bin/Release/*.nupkg --api-key <your-api-key> --source https://api.nuget.org/v3/index.json
```

Be sure to publish all `.nupkg` files to ensure every supported platform can run the MCP server.

If you want to test the publishing flow before publishing to NuGet.org, you can register an account on the NuGet Gallery integration environment: [https://int.nugettest.org](https://int.nugettest.org). The `push` command would be modified to:

```bash
Expand Down
22 changes: 12 additions & 10 deletions docs/ai/quickstarts/snippets/mcp-server/.mcp/server.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
{
"$schema": "https://modelcontextprotocol.io/schemas/draft/2025-07-09/server.json",
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-09-29/server.schema.json",
"description": "<your description here>",
"name": "io.github.<your GitHub username here>/<your repo name>",
"version": "<your package version here>",
"packages": [
{
"registry_name": "nuget",
"name": "<your package ID here>",
"registryType": "nuget",
"registryBaseUrl": "https://api.nuget.org",
"identifier": "<your package ID here>",
"version": "<your package version here>",
"package_arguments": [],
"environment_variables": [
"transport": {
"type": "stdio"
},
"packageArguments": [],
"environmentVariables": [
{
"name": "WEATHER_CHOICES",
"value": "{weather_choices}",
"variables": {
"weather_choices": {
"description": "Comma separated list of weather descriptions to randomly select.",
"is_required": true,
"is_secret": false
"isRequired": true,
"isSecret": false
}
}
}
Expand All @@ -26,8 +31,5 @@
"repository": {
"url": "https://github.com/<your GitHub username here>/<your repo name>",
"source": "github"
},
"version_detail": {
"version": "<your package version here>"
}
}
14 changes: 11 additions & 3 deletions docs/ai/quickstarts/snippets/mcp-server/SampleMcpServer.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RuntimeIdentifiers>win-x64;win-arm64;osx-arm64;linux-x64;linux-arm64;linux-musl-x64</RuntimeIdentifiers>
<OutputType>Exe</OutputType>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -10,6 +11,13 @@
<PackAsTool>true</PackAsTool>
<PackageType>McpServer</PackageType>

<!-- Set up the MCP server to be a self-contained application that does not rely on a shared framework -->
<SelfContained>true</SelfContained>
<PublishSelfContained>true</PublishSelfContained>

<!-- Set up the MCP server to be a single file executable -->
<PublishSingleFile>true</PublishSingleFile>

<!-- Set recommended package metadata -->
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageId>SampleMcpServer</PackageId>
Expand All @@ -25,8 +33,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0-preview.5.25277.114" />
<PackageReference Include="ModelContextProtocol" Version="0.3.0-preview.2" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0-preview.6.25358.103" />
<PackageReference Include="ModelContextProtocol" Version="0.4.0-preview.1" />
</ItemGroup>

</Project>