- Introduction
- Features
- Architecture
- Getting Started
- Building from Source
- Configuration
- Authentication
- HTTPS and Certificate Generation
- Plugins
- API Reference
- Docker Deployment
- CI/CD Pipeline
- Contributing
- License
MCPServer.cpp is a high-performance, cross-platform server implementation of the Model Communication Protocol (MCP) written in modern C++. It enables seamless communication between AI models and external tools, providing a standardized interface for extending model capabilities.
The server implements the JSON-RPC 2.0 protocol over HTTP transport and supports both regular request-response and Server-Sent Events (SSE) streaming for real-time communication.
Primitive | Status | Notes |
---|---|---|
Tools | ✅ Full Support | Execute tools in isolated plugin environment |
Prompts | ✅ Basic Support | Prompt templates and management |
Resources | ✅ Basic Support | Expose data and content to LLMs |
Sampling | 🚧 Planned | LLM-based sampling operations |
Roots | 🚧 Planned | Filesystem access control |
- Full implementation of the Model Communication Protocol (MCP)
- JSON-RPC 2.0 over HTTP/HTTPS transport
- Plugin system for extending functionality
- Built-in tools (echo, file operations, HTTP requests, system commands)
- Streaming responses with Server-Sent Events (SSE)
- Comprehensive logging and error handling
- 🚀 High Performance: Built with C++20 and optimized with mimalloc for superior performance
- 🔌 Plugin System: Extensible architecture with dynamic plugin loading
- 🌐 HTTP Transport: Full HTTP/1.1 support with SSE streaming capabilities
- 📦 JSON-RPC 2.0: Complete implementation of the JSON-RPC 2.0 specification
- 🛠️ Built-in Tools: Includes file operations, HTTP requests, and system commands
- 🧠 AI Model Ready: Designed specifically for AI model integration
- 🔄 Asynchronous I/O: Powered by ASIO for efficient concurrent handling
- 📊 Logging: Comprehensive logging with spdlog
- 📈 Scalable: Multi-threaded architecture for handling concurrent requests
- 🌍 Cross-platform: Works on Windows, Linux, and macOS
- 📁 Resource Management: Expose data and content to LLMs via Resources primitive
MCPServer.cpp uses a modular architecture with clear boundaries between components:
┌─────────────────────────────────────────────────────────────┐
│ MCPServer.cpp │
├─────────────────────────────────────────────────────────────┤
│ Transport Layer │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ HTTP Server │ │ Stdio I/O │ │ Other Protocols │ │
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
├─────────────────────────────────────────────────────────────┤
│ Protocol Layer │
│ ┌──────────────────────┐ │
│ │ JSON-RPC 2.0 │ │
│ └──────────────────────┘ │
├─────────────────────────────────────────────────────────────┤
│ Business Logic Layer │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ Tool Reg. │ │ Plugins │ │ Request Processing │ │
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
├─────────────────────────────────────────────────────────────┤
│ Core Services │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ Logger │ │ Resources │ │ Configuration │ │
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
- Transport Layer: Handles communication over various protocols (HTTP, stdio, etc.)
- Protocol Layer: Implements JSON-RPC 2.0 message parsing and formatting
- Business Logic Layer: Manages tools, plugins, and request processing
- Core Services: Provides essential services like logging
- C++20 compatible compiler (MSVC, GCC 10+, Clang 12+)
- CMake 3.23 or higher
- Git
-
Clone the repository:
git clone https://github.com/caomengxuan666/MCPServer.cpp.git cd MCPServer.cpp
-
Build the project:
mkdir build cd build cmake .. cmake --build .
-
Run the server:
./bin/mcp-server++
The server will start on the default port and load the built-in plugins.
mkdir build
cd build
cmake ..
cmake --build . --config Release
mkdir build
cd build
cmake ..
make -j$(nproc)
Option | Description | Default |
---|---|---|
BUILD_TESTS |
Build unit tests | ON |
CMAKE_BUILD_TYPE |
Build type (Debug, Release, etc.) | Release |
See Configuration section for details on how to configure the server.
MCPServer++ supports authentication mechanisms to secure your server from unauthorized access. See AUTH.md for detailed information on how to configure and use authentication.
MCPServer++ supports secure communication over HTTPS. By default, HTTPS is disabled for security reasons and must be manually enabled in the configuration file.
To enable HTTPS:
- Set
enable_https=1
in your config.ini - Ensure you have valid SSL certificate files
- Configure the required SSL file paths
There are two ways to generate SSL/TLS certificates for development and testing:
- Using the built-in generate_cert tool (recommended)
- Using OpenSSL command line tools
For detailed instructions on both methods, please refer to the HTTPS and Certificate Generation documentation.
MCPServer.cpp supports a powerful plugin system that allows extending functionality without modifying the core server. Plugins are dynamic libraries that implement the MCP plugin interface.
file_plugin
: File system operationshttp_plugin
: HTTP client functionalitysafe_system_plugin
: Secure system command executionexample_stream_plugin
: Streaming data example
See plugins/README.md for detailed information on developing custom plugins.
The server implements the JSON-RPC 2.0 protocol over HTTP. All requests should be sent to the /mcp
endpoint.
MCPServer++ provides basic support for the MCP Resources primitive, which allows exposing data and content to LLMs. Resources can be accessed through the following JSON-RPC methods:
resources/list
: List available resourcesresources/read
: Read the content of a specific resourceresources/write
: Write content to a specific resource (if permitted)
{
"jsonrpc": "2.0",
"id": 2,
"method": "resources/read",
"params": {
"name": "example.txt"
}
}
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"content": "This is the content of the example resource.",
"contentType": "text/plain",
"lastModified": "2025-05-13T10:00:00Z"
}
}
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools",
"params": {}
}
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"name": "read_file",
"description": "Read a file",
"inputSchema": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "Path to the file to read"
}
},
"required": ["path"]
}
}
]
}
-
Multi-stage build (Image size optimized to 10-15MB)
docker build -t mcp-server . docker run -p 6666:6666 -v $(pwd)/plugins:/plugins -v $(pwd)/certs:/certs mcp-server
-
HTTPS Configuration (Certificate directory mounting required)
# Enable HTTPS by setting enable_https=1 in config.ini # Certificate files must be placed in /certs directory inside container docker run -p 6667:6667 -v $(pwd)/certs:/certs mcp-server
- Plugin Path Mapping: Container plugin directory is
/plugins
, recommend mapping local directory via volume - Plugin Loading: Supports runtime hot-loading (ensure correct file permissions)
- Based on minimal
gcr.io/distroless/cc-debian12
base image - Static linking + debug info stripping (LTO optimized)
- Domestic users can configure mirror accelerators (see configuration examples)
Pre-built Docker images are available on Docker Hub: https://hub.docker.com/r/mgzy/mcp-server
You can pull and run the latest image directly:
docker pull mgzy/mcp-server
docker run -p 6666:6666 -v $(pwd)/plugins:/plugins -v $(pwd)/certs:/certs mgzy/mcp-server
Our project uses GitHub Actions for continuous integration and deployment. The pipeline automatically builds and tests the server on multiple platforms:
- Ubuntu 22.04 (GitHub Actions latest LTS)
- Ubuntu 24.04 (GitHub Actions latest Ubuntu release)
- Windows Server 2022 (GitHub Actions latest Windows)
We provide two build variants to suit different needs:
- Full build: Includes all libraries and development headers
- Minimal build: Contains only the executable and essential files (no development headers or libraries)
The CI/CD pipeline generates packages in multiple formats:
- Windows: ZIP, NSIS installer (EXE)
- Linux: DEB, RPM, TAR.GZ, ZIP
We welcome contributions from the community! Please see CONTRIBUTING.md for guidelines on how to contribute to this project.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.