-
Notifications
You must be signed in to change notification settings - Fork 841
Update MCP server template #6772
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 all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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
21 changes: 19 additions & 2 deletions
21
...tensions.AI.Templates/src/McpServer/McpServer-CSharp/.template.config/dotnetcli.host.json
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 |
|---|---|---|
| @@ -1,7 +1,24 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/dotnetcli.host", | ||
| "symbolInfo": {}, | ||
| "symbolInfo": { | ||
| "TargetFrameworkOverride": { | ||
| "isHidden": "true", | ||
| "longName": "target-framework-override", | ||
| "shortName": "" | ||
| }, | ||
| "Framework": { | ||
| "longName": "framework" | ||
| }, | ||
| "NativeAot": { | ||
| "longName": "aot", | ||
| "shortName": "" | ||
| }, | ||
| "SelfContained": { | ||
| "longName": "self-contained", | ||
| "shortName": "" | ||
| } | ||
| }, | ||
| "usageExamples": [ | ||
| "" | ||
| ] | ||
| } | ||
| } |
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
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
22 changes: 21 additions & 1 deletion
22
...crosoft.Extensions.AI.Templates/src/McpServer/McpServer-CSharp/McpServer-CSharp.csproj.in
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
22 changes: 21 additions & 1 deletion
22
...ates/Microsoft.Extensions.AI.Templates/src/McpServer/McpServer-CSharp/README.md
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
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
21 changes: 21 additions & 0 deletions
21
...emplates.IntegrationTests/Snapshots/mcpserver.AotTrue.verified/mcpserver/.mcp/server.json
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,21 @@ | ||
| { | ||
| "$schema": "https://modelcontextprotocol.io/schemas/draft/2025-07-09/server.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": [], | ||
| "environment_variables": [] | ||
| } | ||
| ], | ||
| "repository": { | ||
| "url": "https://github.com/<your GitHub username here>/<your repo name>", | ||
| "source": "github" | ||
| }, | ||
| "version_detail": { | ||
| "version": "0.1.0-beta" | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
...s.AI.Templates.IntegrationTests/Snapshots/mcpserver.AotTrue.verified/mcpserver/Program.cs
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,16 @@ | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Hosting; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| var builder = Host.CreateApplicationBuilder(args); | ||
|
|
||
| // Configure all logs to go to stderr (stdout is used for the MCP protocol messages). | ||
| builder.Logging.AddConsole(o => o.LogToStandardErrorThreshold = LogLevel.Trace); | ||
|
|
||
| // Add the MCP services: the transport to use (stdio) and the tools to register. | ||
| builder.Services | ||
| .AddMcpServer() | ||
| .WithStdioServerTransport() | ||
| .WithTools<RandomNumberTools>(); | ||
|
|
||
| await builder.Build().RunAsync(); |
98 changes: 98 additions & 0 deletions
98
...lates.IntegrationTests/Snapshots/mcpserver.AotTrue.verified/mcpserver/README.md
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,98 @@ | ||
| # MCP Server | ||
|
|
||
| This README was created using the C# MCP server project template. | ||
| It demonstrates how you can easily create an MCP server using C# and publish it as a NuGet package. | ||
|
|
||
| The MCP server is built as a self-contained application and does not require the .NET runtime to be installed on the target machine. | ||
| However, since it is self-contained, it must be built for each target platform separately. | ||
| By default, the template is configured to build for: | ||
| * `win-x64` | ||
| * `win-arm64` | ||
| * `osx-arm64` | ||
| * `linux-x64` | ||
| * `linux-arm64` | ||
| * `linux-musl-x64` | ||
|
|
||
| If your users require more platforms to be supported, update the list of runtime identifiers in the project's `<RuntimeIdentifiers />` element. | ||
|
|
||
| See [aka.ms/nuget/mcp/guide](https://aka.ms/nuget/mcp/guide) for the full guide. | ||
|
|
||
| Please note that this template is currently in an early preview stage. If you have feedback, please take a [brief survey](http://aka.ms/dotnet-mcp-template-survey). | ||
|
|
||
| ## Checklist before publishing to NuGet.org | ||
|
|
||
| - Test the MCP server locally using the steps below. | ||
| - Update the package metadata in the .csproj file, in particular the `<PackageId>`. | ||
| - Update `.mcp/server.json` to declare your MCP server's inputs. | ||
| - See [configuring inputs](https://aka.ms/nuget/mcp/guide/configuring-inputs) for more details. | ||
| - Pack the project using `dotnet pack`. | ||
|
|
||
| The `bin/Release` directory will contain the package file (.nupkg), which can be [published to NuGet.org](https://learn.microsoft.com/nuget/nuget-org/publish-a-package). | ||
|
|
||
| ## Developing locally | ||
|
|
||
| To test this MCP server from source code (locally) without using a built MCP server package, you can configure your IDE to run the project directly using `dotnet run`. | ||
|
|
||
| ```json | ||
| { | ||
| "servers": { | ||
| "mcpserver": { | ||
| "type": "stdio", | ||
| "command": "dotnet", | ||
| "args": [ | ||
| "run", | ||
| "--project", | ||
| "<PATH TO PROJECT DIRECTORY>" | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Testing the MCP Server | ||
|
|
||
| Once configured, you can ask Copilot Chat for a random number, for example, `Give me 3 random numbers`. It should prompt you to use the `get_random_number` tool on the `mcpserver` MCP server and show you the results. | ||
|
|
||
| ## Publishing to NuGet.org | ||
|
|
||
| 1. Run `dotnet pack -c Release` to create the NuGet package | ||
| 2. Publish to NuGet.org with `dotnet nuget push bin/Release/*.nupkg --api-key <your-api-key> --source https://api.nuget.org/v3/index.json` | ||
|
|
||
| ## Using the MCP Server from NuGet.org | ||
|
|
||
| Once the MCP server package is published to NuGet.org, you can configure it in your preferred IDE. Both VS Code and Visual Studio use the `dnx` command to download and install the MCP server package from NuGet.org. | ||
|
|
||
| - **VS Code**: Create a `<WORKSPACE DIRECTORY>/.vscode/mcp.json` file | ||
| - **Visual Studio**: Create a `<SOLUTION DIRECTORY>\.mcp.json` file | ||
|
|
||
| For both VS Code and Visual Studio, the configuration file uses the following server definition: | ||
|
|
||
| ```json | ||
| { | ||
| "servers": { | ||
| "mcpserver": { | ||
| "type": "stdio", | ||
| "command": "dnx", | ||
| "args": [ | ||
| "<your package ID here>", | ||
| "--version", | ||
| "<your package version here>", | ||
| "--yes" | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## More information | ||
|
|
||
| .NET MCP servers use the [ModelContextProtocol](https://www.nuget.org/packages/ModelContextProtocol) C# SDK. For more information about MCP: | ||
|
|
||
| - [Official Documentation](https://modelcontextprotocol.io/) | ||
| - [Protocol Specification](https://spec.modelcontextprotocol.io/) | ||
| - [GitHub Organization](https://github.com/modelcontextprotocol) | ||
|
|
||
| Refer to the VS Code or Visual Studio documentation for more information on configuring and using MCP servers: | ||
|
|
||
| - [Use MCP servers in VS Code (Preview)](https://code.visualstudio.com/docs/copilot/chat/mcp-servers) | ||
| - [Use MCP servers in Visual Studio (Preview)](https://learn.microsoft.com/visualstudio/ide/mcp-servers) |
18 changes: 18 additions & 0 deletions
18
...ntegrationTests/Snapshots/mcpserver.AotTrue.verified/mcpserver/Tools/RandomNumberTools.cs
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,18 @@ | ||
| using System.ComponentModel; | ||
| using ModelContextProtocol.Server; | ||
|
|
||
| /// <summary> | ||
| /// Sample MCP tools for demonstration purposes. | ||
| /// These tools can be invoked by MCP clients to perform various operations. | ||
| /// </summary> | ||
| internal class RandomNumberTools | ||
| { | ||
| [McpServerTool] | ||
| [Description("Generates a random number between the specified minimum and maximum values.")] | ||
| public int GetRandomNumber( | ||
| [Description("Minimum value (inclusive)")] int min = 0, | ||
| [Description("Maximum value (exclusive)")] int max = 100) | ||
| { | ||
| return Random.Shared.Next(min, max); | ||
| } | ||
| } |
Oops, something went wrong.
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.