|
| 1 | +# MCP Server |
| 2 | + |
| 3 | +This README was created using the C# MCP server project template. |
| 4 | +It demonstrates how you can easily create an MCP server using C# and publish it as a NuGet package. |
| 5 | + |
| 6 | +The MCP server is built as a self-contained application and does not require the .NET runtime to be installed on the target machine. |
| 7 | +However, since it is self-contained, it must be built for each target platform separately. |
| 8 | +By default, the template is configured to build for: |
| 9 | +* `win-x64` |
| 10 | +* `win-arm64` |
| 11 | +* `osx-arm64` |
| 12 | +* `linux-x64` |
| 13 | +* `linux-arm64` |
| 14 | +* `linux-musl-x64` |
| 15 | + |
| 16 | +If your users require more platforms to be supported, update the list of runtime identifiers in the project's `<RuntimeIdentifiers />` element. |
| 17 | + |
| 18 | +See [aka.ms/nuget/mcp/guide](https://aka.ms/nuget/mcp/guide) for the full guide. |
| 19 | + |
| 20 | +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). |
| 21 | + |
| 22 | +## Checklist before publishing to NuGet.org |
| 23 | + |
| 24 | +- Test the MCP server locally using the steps below. |
| 25 | +- Update the package metadata in the .csproj file, in particular the `<PackageId>`. |
| 26 | +- Update `.mcp/server.json` to declare your MCP server's inputs. |
| 27 | + - See [configuring inputs](https://aka.ms/nuget/mcp/guide/configuring-inputs) for more details. |
| 28 | +- Pack the project using `dotnet pack`. |
| 29 | + |
| 30 | +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). |
| 31 | + |
| 32 | +## Developing locally |
| 33 | + |
| 34 | +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`. |
| 35 | + |
| 36 | +```json |
| 37 | +{ |
| 38 | + "servers": { |
| 39 | + "mcpserver": { |
| 40 | + "type": "stdio", |
| 41 | + "command": "dotnet", |
| 42 | + "args": [ |
| 43 | + "run", |
| 44 | + "--project", |
| 45 | + "<PATH TO PROJECT DIRECTORY>" |
| 46 | + ] |
| 47 | + } |
| 48 | + } |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +## Testing the MCP Server |
| 53 | + |
| 54 | +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. |
| 55 | + |
| 56 | +## Publishing to NuGet.org |
| 57 | + |
| 58 | +1. Run `dotnet pack -c Release` to create the NuGet package |
| 59 | +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` |
| 60 | + |
| 61 | +## Using the MCP Server from NuGet.org |
| 62 | + |
| 63 | +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. |
| 64 | + |
| 65 | +- **VS Code**: Create a `<WORKSPACE DIRECTORY>/.vscode/mcp.json` file |
| 66 | +- **Visual Studio**: Create a `<SOLUTION DIRECTORY>\.mcp.json` file |
| 67 | + |
| 68 | +For both VS Code and Visual Studio, the configuration file uses the following server definition: |
| 69 | + |
| 70 | +```json |
| 71 | +{ |
| 72 | + "servers": { |
| 73 | + "mcpserver": { |
| 74 | + "type": "stdio", |
| 75 | + "command": "dnx", |
| 76 | + "args": [ |
| 77 | + "<your package ID here>", |
| 78 | + "--version", |
| 79 | + "<your package version here>", |
| 80 | + "--yes" |
| 81 | + ] |
| 82 | + } |
| 83 | + } |
| 84 | +} |
| 85 | +``` |
| 86 | + |
| 87 | +## More information |
| 88 | + |
| 89 | +.NET MCP servers use the [ModelContextProtocol](https://www.nuget.org/packages/ModelContextProtocol) C# SDK. For more information about MCP: |
| 90 | + |
| 91 | +- [Official Documentation](https://modelcontextprotocol.io/) |
| 92 | +- [Protocol Specification](https://spec.modelcontextprotocol.io/) |
| 93 | +- [GitHub Organization](https://github.com/modelcontextprotocol) |
| 94 | + |
| 95 | +Refer to the VS Code or Visual Studio documentation for more information on configuring and using MCP servers: |
| 96 | + |
| 97 | +- [Use MCP servers in VS Code (Preview)](https://code.visualstudio.com/docs/copilot/chat/mcp-servers) |
| 98 | +- [Use MCP servers in Visual Studio (Preview)](https://learn.microsoft.com/visualstudio/ide/mcp-servers) |
0 commit comments