Get the FREE Ultimate OpenClaw Setup Guide →

How-To-Create

This guide will help you set up a basic MCP (Model Context Protocol) server in .NET, configure it in VS Code, and interact with it using Copilot Chat.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio nisalgunawardhana-how-to-create-mcp-server dotnet run --project HelloSriLankaServer/HelloSriLankaServer.csproj \
  --env DOTNET_ENVIRONMENT="Development"

How to use

This MCP server demonstrates using the .NET Model Context Protocol (MCP) setup with a simple HelloTool inside a console app. The server is built with the ModelContextProtocol and exposes a tool (e.g., HelloTool) that Copilot Chat can invoke to interact with the server. You’ll run the server with dotnet run from the project, and then connect via Copilot Chat to discover and execute tools, inspect context, and experiment with the server’s capabilities. The example emphasizes creating a basic tool that logs to the console, which you can extend with more MCP server tools to expose additional commands and interactions. When connected in Copilot Chat, you’ll see an Add Tool button, choose the Command (stdio) server type, and point to the dotnet process and project so Copilot can interact with the server during a chat session.

How to install

Prerequisites:

  • Install the .NET SDK 8 (https://dotnet.microsoft.com/download) and ensure dotnet --version reports a recent 8.x version.
  • Optionally install Visual Studio Code and the C# Dev Kit extension for a smoother development workflow.

Step-by-step installation:

  1. Create a new directory for your MCP server project and initialize a .NET console project (as shown in the guide).
  2. Add the required MCP packages: dotnet add package ModelContextProtocol --prerelease dotnet add package Microsoft.Extensions.Hosting
  3. Implement your MCP server logic (e.g., WithStdioServerTransport and WithToolsFromAssembly) and add at least one tool to demonstrate interaction.
  4. Build and run the server: dotnet run --project HelloSriLankaServer/HelloSriLankaServer.csproj
  5. In VS Code, configure MCP in the .vscode/mcp.json (Command: stdio) to enable Copilot Chat integration.

Notes:

  • Ensure the project builds successfully with all required dependencies before attempting to connect via Copilot Chat.
  • You can customize environment variables as needed for development or production settings.

Additional notes

Tips and caveats:

  • The sample tool (HelloTool) prints to the console; you can replace or extend it to perform actual MCP operations (e.g., query context, transform data).
  • Use COPILOT CHAT's Add Tool feature to register your server toolset; ensure the server is running and reachable via the configured stdio channel.
  • If you encounter startup issues, verify the project path in the --project argument and ensure all NuGet packages are restored (dotnet restore).
  • Consider adding more environment variables to control logging levels, environment, or feature flags during development.

Related MCP Servers

Sponsor this space

Reach thousands of developers