MCP Client-Server Examples
This repository contains example implementations of Model Context Protocol (MCP) client and server applications in both C# and Node.js/TypeScript. The examples demonstrate how to build MCP-compatible servers that expose tools for hotel search functionality and clients that can connect to and interact with these servers.
🏗️ Project Structure```
mcp-client-server/
├── csharp/ # C# implementations
│ ├── mcp-client/ # C# MCP client (console application)
│ └── mcp-server/ # C# MCP server (ASP.NET Core web app)
├── nodejs/ # Node.js/TypeScript implementations
│ ├── mcp-client/ # Node.js MCP client
│ └── mcp-server/ # Node.js MCP server (Express.js)
└── README.md # This file
## 🌟 Features
### MCP Servers
Both server implementations provide the following MCP tools:
- **Hotel Search**: Search for hotels by location or name
- **Available Hotels**:
- Ocean View (Miami) - 5 rooms available
- Mountain Lodge (Denver) - 2 rooms available
### MCP Clients
Both client implementations demonstrate:
- Connecting to MCP servers via Server-Sent Events (SSE)
- Listing available tools from the server
- Calling MCP tools with parameters
- Displaying formatted results
## 🚀 Quick Start
### Prerequisites
#### For C# Projects
- .NET 9.0 or later
- Visual Studio 2022 or VS Code with C# extension
#### For Node.js Projects
- Node.js v16 or higher
- npm or pnpm package manager
### Running the Examples
#### Option 1: C# Implementation
1. **Start the C# MCP Server:**```bash
cd csharp/mcp-server
dotnet run
# or use: run.cmd
```
Server will be available at `http://localhost:3001`
2. **Run the C# MCP Client:**```bash
cd csharp/mcp-client
dotnet run
# or use: run.cmd
```
#### Option 2: Node.js Implementation
1. **Start the Node.js MCP Server:**```bash
cd nodejs/mcp-server
pnpm install
pnpm run build && pnpm start
# or use: run.cmd
```
Server will be available at `http://localhost:3001`
2. **Run the Node.js MCP Client:**```bash
cd nodejs/mcp-client
pnpm install
pnpm run build && pnpm start
# or use: run.cmd
```
## 🔧 Technical Details
### Communication Protocol
- **Transport**: Server-Sent Events (SSE) over HTTP
- **Port**: 3001 (default for all servers)
- **Endpoints**:
- `/sse` - SSE connection endpoint for MCP communication
- `/messages` - POST endpoint for tool execution
### MCP Tools Available
- **Tool Name**: `searchHotels` (Node.js) / `Search` (C#)
- **Description**: Search for hotels by location or name
- **Parameters**:
- `query` (string) - Search term for hotel location or name
## 🛠️ Development
### Building the Projects
#### C# Projects```bash
# Build server
cd csharp/mcp-server
dotnet build
# Build client
cd csharp/mcp-client
dotnet build
Node.js Projects```bash
Build server
cd nodejs/mcp-server
pnpm install
pnpm run build
Build client
cd nodejs/mcp-client
pnpm install
pnpm run build
### Development Mode
#### Node.js Server (with auto-reload)```bash
cd nodejs/mcp-server
pnpm run dev
Node.js Client (development mode)```bash
cd nodejs/mcp-client
pnpm run dev
## 🧪 Testing
### Using MCP Inspector
Both servers can be tested using the MCP Inspector tool:```bash
npx -y @modelcontextprotocol/inspector
Manual Testing
- Start any of the MCP servers
- Use the corresponding client to connect and test functionality
- Try searching for hotels with queries like:
- "miami" (should find Ocean View)
- "denver" (should find Mountain Lodge)
- "ocean" (should find Ocean View)
📝 Example Usage
C# Client Example```
MCP Client Console Application
Enter your hotel search query (or 'quit' to exit): miami
Connecting to MCP server...
Connected! Listing available tools...
Available tool: Search (Searches for hotels based on the user's query.)
Searching for hotels with query: 'miami'...
Search Results:
Found hotels:
- Ocean View (Miami): 5 rooms available
Enter your hotel search query (or 'quit' to exit): quit
Goodbye!
### Node.js Client Example```
[CLIENT] Connected to MCP server
[CLIENT] searchHotels response: {
content: [
{
type: 'text',
text: 'Found 1 hotel(s):\n\n🏨 Ocean View in Miami (5 rooms available)'
}
]
}
📚 Learn More
- Model Context Protocol Documentation
- MCP SDK Documentation
- Microsoft MCP Server SDK
📄 License
This project is provided as example code for learning MCP implementation patterns.
