Content
# MCP Server
[](https://opensource.org/licenses/MIT)
[](https://en.cppreference.com/w/cpp/17)
A C++ implementation of the MCP (Model Context Protocol) Server. Based on the JSON-RPC protocol, it supports the registration and invocation of three types of primitives: Tools, Resources, and Prompts. AI clients communicate with the Server through stdio or HTTP, and the Server calls local tools to execute commands, query data, and access files.
## Architecture
```
AI Client (Claude / Cursor / Ollama)
→ MCP Protocol (JSON-RPC over stdio / HTTP)
→ JsonRpcDispatcher(Method Routing: tools/list / tools/call / resources/read ...)
→ McpServer(Tool / Resource / Prompt Registration + Invocation)
→ Specific Handler(echo / calculate / get_weather / write_file / ask_ai ...)
```
### Module Hierarchy
| Layer | File | Responsibility |
|------|------|------|
| **Type System** | `types.h` | MCP Protocol Core Data Structures (Tool / Resource / Prompt / ToolResult) |
| **Configuration** | `config.h` | Singleton Pattern, JSON File Loading + Validation + Default Values |
| **JSON-RPC** | `jsonrpc.h` | Request / Response / Error JSON Encoding + Decoding + Method Dispatcher |
| **Transport** | `stdio_jsonrpc.h` / `http_jsonrpc.h` | stdio Line Protocol / HTTP SSE + POST |
| **MCP Core** | `mcp_server.h` | Three Maps Managing Tools / Resources / Prompts Registration + Invocation |
| **Main Program** | `main.cpp` | Assemble Layers + Register Specific Tools |
## Roadmap
- [x] Config Module (Singleton + JSON Loading + Validation + Default Values)
- [ ] Types Module (Tool / Resource / Prompt / ToolResult Data Structures)
- [ ] JsonRpc Module (Dispatcher: method → handler Routing)
- [ ] McpServer Core (register_tool / call_tool / list_tools)
- [ ] Stdio Transport (One-line JSON In → dispatch → One-line JSON Out)
- [ ] First Batch of Tools (echo / calculate / get_time / ask_ai)
- [ ] HTTP Transport (POST /rpc + SSE Event Stream)
## Quick Start
```bash
# Dependency Installation (vcpkg)
vcpkg install nlohmann-json spdlog
# Compilation
cmake -B build -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg.cmake
cmake --build build
# Run (stdio Mode)
./build/mcp_server --mode stdio
```
## Configuration File
```json
{
"server": {
"port": 8089
},
"logging": {
"log_level": "debug"
}
}
```
## License
MIT