SimpleMcp.Demo

hassanhabib/SimpleMcp.Demo

3.3

If you are the rightful owner of SimpleMcp.Demo and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The Simple MCP Server & Client demo showcases the use of the Model-Context-Protocol (MCP) framework in C# for building AI-powered tools.

🧠 Simple MCP Server & Client in C#

Welcome to the Simple MCP Server & Client demo built using MCPSharp, a .NET implementation of the Model-Context-Protocol (MCP) framework for building AI-powered tools.

🎯 This repo shows how to define tools on the server side and call them from a local client β€” all in plain C#!


πŸ“¦ What’s Inside

SimpleMcp/
β”œβ”€β”€ SimpleMcp.Server/      # MCP Server with one registered tool: addition
β”‚   └── CalculatorTool.cs
β”œβ”€β”€ SimpleMcp.Client/      # MCP Client that calls the addition tool
β”‚   └── Program.cs
└── README.md              # You're reading it :)

πŸš€ Getting Started

1. Clone the repo

git clone https://github.com/yourusername/SimpleMcp.git
cd SimpleMcp

2. Build the server

cd SimpleMcp.Server
dotnet build

3. Run the client

Make sure the server path in the client is correctly pointing to the server executable:

server: "D:\\path\\to\\SimpleMcp.Server.exe"

Then run:

cd ../SimpleMcp.Client
dotnet run

βœ… Expected Output

115

πŸ“ (Because 5 + 10 + 100 = 115 β€” see the easter egg in CalculatorTool!)


πŸ› οΈ MCP Concepts in Action

ConceptIn This Project
ModelCalculatorTool.Addition
ContextSimple runtime context per call
ProtocolMCPSharp handles tool invocation over local process communication

πŸ“š MCPSharp Usage

  • Decorate tools with [McpTool]
  • Define parameters using [McpParameter]
  • Register tools on the server with MCPServer.Register<T>()
  • Use MCPClient to call tools by name with parameters

πŸ’‘ Why MCP?

MCP lets you define structured AI tools that can be embedded into agentic systems, LLM orchestration, and more. This example keeps it minimal, but real-world apps can scale up with context, memory, chaining, and local/remote AI models.


πŸ§ͺ Example Tool

[McpTool(name: "addition", Description = "This tool will add two numbers.")]
public static int Addition(
    [McpParameter(required: true)] int firstNumber,
    [McpParameter(required: true)] int secondNumber)
{
    return firstNumber + secondNumber + 100;
}

πŸ™Œ Credits

Inspired by the Anthropic Model-Context-Protocol specification and the MCPSharp .NET implementation.


🧡 Want to Go Deeper?

  • Add multiple tools
  • Use session or memory for persistent context
  • Connect to local AI models (e.g. Llama.cpp, Ollama) via MCP
  • Build UI/agent shells around this infrastructure

πŸ“½οΈWatch YouTube video about this repo


πŸ“œ License

MIT β€” use this freely for learning, demos, or real projects!