# mcpcpp **Repository Path**: itrunk/mcpcpp ## Basic Information - **Project Name**: mcpcpp - **Description**: No description available - **Primary Language**: C/C++ - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-16 - **Last Updated**: 2026-04-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # mcpcpp - C++ Model Context Protocol Library [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![C++17](https://img.shields.io/badge/C++-17-blue.svg)](https://en.cppreference.com/w/cpp/17) [![CMake](https://img.shields.io/badge/CMake-3.14+-green.svg)](https://cmake.org/) A modern C++ implementation of the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) for building AI-powered applications with external tool integration. ## ๐Ÿš€ Features - โœ… **Full MCP Protocol Support** - JSON-RPC 2.0 based protocol (v2024-11-05) - โœ… **Dual Transport** - STDIO and SSE/HTTP modes - โœ… **Tools** - Register C++ functions as AI-callable tools - โœ… **Resources** - Serve data, configurations, and files - โœ… **Prompts** - Provide reusable prompt templates - โœ… **Client Library** - Connect to MCP servers from C++ - โœ… **Dynamic Configuration** - Load tools from JSON config files - โœ… **Header-Only Option** - Easy integration - โœ… **Modern C++17** - Type-safe and efficient ## ๐Ÿ“ฆ Quick Start ### Installation ```bash git clone https://github.com/nlpresearchai/mcpcpp.git cd mcpcpp mkdir build && cd build cmake .. -DCMAKE_BUILD_TYPE=Release cmake --build . sudo cmake --install . ``` ### Basic Usage ```cpp #include int main() { // Create server mcp::MCPServer server("my-server", "1.0.0"); // Add a tool server.add_tool( "add", "Add two numbers", { {"type", "object"}, {"properties", { {"a", {{"type", "number"}}}, {"b", {{"type", "number"}}} }}, {"required", {"a", "b"}} }, [](const json& args) -> json { return {{"result", args["a"].get() + args["b"].get()}}; } ); // Run server (STDIO mode) server.run_stdio(); return 0; } ``` ### Using in Your Project **CMakeLists.txt:** ```cmake find_package(cppmcp REQUIRED) add_executable(my_server main.cpp) target_link_libraries(my_server PRIVATE cppmcp::cppmcp) ``` ## ๐Ÿ“š Documentation ### Core Components #### 1. **MCP Server** (`mcp_server.hpp`) Create servers that expose tools, resources, and prompts to AI applications. ```cpp mcp::MCPServer server("server-name", "1.0.0"); // Add tool server.add_tool("tool_name", "description", input_schema, [](const json& args) { return result; }); // Add resource server.add_resource("uri://resource", "name", "description", "mime-type", []() { return "data"; }); // Add prompt server.add_prompt("prompt_name", "description", arguments, [](const json& args) { return prompt; }); // Run server.run_stdio(); // or server.run_sse(port); ``` #### 2. **MCP Client** (`mcp_client.hpp`) Connect to MCP servers and call tools. ```cpp mcp::MCPClient client("client-name", "1.0.0"); // Connect client.connect_sse("http://localhost:8080"); client.initialize(); // List and call tools auto tools = client.list_tools(); auto result = client.call_tool("add", {{"a", 5}, {"b", 3}}); // Read resources auto resources = client.list_resources(); auto data = client.read_resource("config://app"); ``` #### 3. **Dynamic Server** (`dynamic_mcp_server.hpp`) Load server configuration from JSON files. ```cpp #include dynamic_mcp::ConfigLoader loader("tasks_config.json"); loader.load(); // Server is automatically configured from JSON ``` ## ๐Ÿ“– Examples See the [`examples/`](examples/) directory: - **`simple_server.cpp`** - Minimal MCP server - **`server_with_tools.cpp`** - Server with multiple tools, resources, and prompts - **`dynamic_server.cpp`** - Configuration-driven server - **`client_example.cpp`** - MCP client usage ### Building Examples ```bash cd build cmake .. -DCPPMCP_BUILD_EXAMPLES=ON cmake --build . ./examples/simple_server stdio ./examples/server_with_tools sse 8080 ``` ## ๐Ÿ—๏ธ Project Structure ``` mcpcpp/ โ”œโ”€โ”€ include/cppmcp/ # Public headers โ”‚ โ”œโ”€โ”€ mcp_server.hpp # Server API โ”‚ โ”œโ”€โ”€ mcp_client.hpp # Client API โ”‚ โ””โ”€โ”€ dynamic_mcp_server.hpp # Dynamic configuration โ”œโ”€โ”€ src/ # Implementation โ”‚ โ”œโ”€โ”€ mcp_server.cpp โ”‚ โ”œโ”€โ”€ mcp_sse.cpp โ”‚ โ”œโ”€โ”€ mcp_client.cpp โ”‚ โ””โ”€โ”€ dynamic_mcp_server.cpp โ”œโ”€โ”€ examples/ # Usage examples โ”œโ”€โ”€ tests/ # Unit tests โ”œโ”€โ”€ docs/ # Documentation โ””โ”€โ”€ CMakeLists.txt # Build configuration ``` ## ๐Ÿ› ๏ธ Building ### Requirements - **C++17** compiler (GCC 7+, Clang 5+, MSVC 2017+) - **CMake** 3.14+ - **libcurl** (for HTTP/SSE support) Dependencies (auto-fetched by CMake): - [nlohmann/json](https://github.com/nlohmann/json) - JSON parsing - [cpp-httplib](https://github.com/yhirose/cpp-httplib) - HTTP server ### CMake Options ```cmake -DCPPMCP_BUILD_EXAMPLES=ON # Build examples (default: ON) -DCPPMCP_BUILD_TESTS=ON # Build tests (default: ON) -DCPPMCP_BUILD_SHARED=ON # Build shared library (default: ON) -DCPPMCP_BUILD_STATIC=ON # Build static library (default: ON) ``` ### Ubuntu/Debian ```bash sudo apt-get install build-essential cmake libcurl4-openssl-dev ``` ### macOS ```bash brew install cmake curl ``` ## ๐Ÿงช Testing ```bash cd build cmake .. -DCPPMCP_BUILD_TESTS=ON cmake --build . ctest ``` ## ๐Ÿ”Œ Integration with AI Clients ### Claude Desktop Add to `~/Library/Application Support/Claude/claude_desktop_config.json`: ```json { "mcpServers": { "cppmcp-example": { "command": "/path/to/build/examples/simple_server", "args": ["stdio"] } } } ``` ### Custom Python Client ```python import httpx import json # Connect to SSE server response = httpx.post( "http://localhost:8080/message", json={ "jsonrpc": "2.0", "id": 1, "method": "initialize", "params": { "protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "python-client", "version": "1.0"} } } ) print(response.json()) ``` ## ๐Ÿ“Š Performance - **Low Latency** - Direct C++ execution, no Python overhead - **High Throughput** - Handles thousands of requests per second - **Memory Efficient** - Minimal allocations, optimized data structures - **Async Ready** - Non-blocking SSE connections ## ๐Ÿค Contributing Contributions welcome! Please: 1. Fork the repository 2. Create a feature branch (`git checkout -b feature/amazing-feature`) 3. Commit your changes (`git commit -m 'Add amazing feature'`) 4. Push to the branch (`git push origin feature/amazing-feature`) 5. Open a Pull Request ## ๐Ÿ“„ License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. ## ๐Ÿ”— Related Projects - [Model Context Protocol](https://modelcontextprotocol.io/) - Official MCP specification - [mcp Python SDK](https://github.com/modelcontextprotocol/python-sdk) - Official Python implementation - [mcp TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk) - Official TypeScript implementation ## ๐Ÿ“ฌ Contact - **Issues**: [GitHub Issues](https://github.com/nlpresearchai/mcpcpp/issues) - **Discussions**: [GitHub Discussions](https://github.com/nlpresearchai/mcpcpp/discussions) ## โญ Star History If you find this project helpful, please consider giving it a star! --- **Built with โค๏ธ for the AI and C++ communities**