
nlpresearchai/mcpcpp
Developer toolsこのページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る
A modern C++ implementation of the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) for building AI-powered applications with external tool integration.
概要
A modern C++ implementation of the Model Context Protocol (MCP) for building AI-powered applications with external tool integration. - ✅ - JSON-RPC 2.0 based protocol (v2024-11-05) - ✅ - STDIO and SSE/HTTP modes - ✅ - Register C++ functions as AI-callable tools - ✅ - Serve data, configurations, and files - ✅ - Provide reusable prompt templates - ✅ - Connect to MCP servers from C++ - ✅ - Load tools from JSON config files - ✅ - Easy integration - ✅ - Type-safe and efficient Create servers that expose tools, resources, and prompts to AI applications. Load server configuration from JSON files. - - Minimal MCP server - - Server with multiple tools, resources, and prompts - - Configuration-driven server - - MCP client usage - compiler (GCC 7+, Clang 5+, MSVC 2017+) - 3.14+ - (for HTTP/SSE support) Dependencies (auto-fetched by CMake): - nlohmann/json - JSON parsing - cpp-httplib - HTTP server Add to ~/Library/Application Support/Claude/claude_desktop_config.json:
README
以下は原文 README の抜粋です。原文を見る。
mcpcpp - C++ Model Context Protocol Library
A modern C++ implementation of the Model Context Protocol (MCP) 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
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
#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:
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.
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.
mcp::MCPClient client("client-name", "1.0.0");
// Connect
client.connect_sse("http://localhost:8080");
client.initialize();
// List and call tools
インストール
This server does not publish a one-line install command.
Open the repository installation guide MCP 初心者?mcpskill.org のガイドから始めましょう →設定
{
"mcpServers": {
"cppmcp-example": {
"command": "/path/to/build/examples/simple_server",
"args": ["stdio"]
}
}
}