McpClientServerExample
A simple .NET implementation of an MCP (Model Context Protocol) Client and Server example. This project demonstrates how to create and interact with an MCP server using custom tools, natural language prompts, and standard I/O transport.
claude mcp add --transport stdio dks50217-mcpclientserverexample dotnet run --project client/McpClient.csproj \ --env OPENAI_API_KEY="your_api_key_here"
How to use
McpClientServerExample demonstrates a basic MCP setup with a client and a server that communicate using the Model Context Protocol. The server exposes simple built-in tools that can be invoked by the client, such as Echo (returns the input) and ReverseEcho (returns the reversed input). The client uses the ModelContextProtocol.Client interface to send messages, request GPT-powered responses, and invoke available tools. This example focuses on a minimal, self-contained flow to illustrate client-server interactions and how tools can be discovered and invoked during a session.
How to install
Prerequisites:
- .NET 8.0 SDK installed
- OpenAI API key if you plan to use GPT models
-
Clone the repository: git clone <repository-url> cd McpClientServerExample
-
(Optional) Set your OpenAI API key: export OPENAI_API_KEY=your_api_key_here
-
Restore and run the client project: dotnet build dotnet run --project client/McpClient.csproj
-
If you want to run or inspect the server-side separately, ensure you have the corresponding server project setup and run it similarly (dotnet run --project server/McpServer.csproj) and point the client to connect to that server if needed.
Additional notes
Tips:
- Ensure OPENAI_API_KEY is set in your environment if you intend to use GPT models.
- The built-in tools Echo and ReverseEcho are useful for testing basic request/response flows.
- If you modify the client or server, re-build before running to pick up changes.
- Confirm network connectivity between client and server endpoints if they run as separate processes.
Related MCP Servers
mssql
MSSQL Server MCP implementation written in C#
McpDotNet.Extensions.SemanticKernel
Microsoft SemanticKernel integration for the Model Context Protocol (MCP). Enables seamless use of MCP tools as AI functions.
DatabaseMcpServer
MCP server from ttcc666/DatabaseMcpServer
mcp-dataverse
MCP Server for querying Dataverse using SQL
xperience-community
ASP.NET Core MCP server for Xperience by Kentico projects
console-to-http
Example of converting a stdio MCP server to HTTP using ModelContextProtocol.AspNetCore