Token导航 LogoToken导航TokenDH.com
Cpp MCP SDK logo
AI代理stdio官方级别未说明来源级核验

Cpp MCP SDK

MCP Server

一个完全符合MCP 2025-11-25规范的C++ SDK,用于构建生产就绪的MCP服务器和客户端,支持流式HTTP传输和基于OAuth的授权。

工具数

1

提示词数

0

GitHub Stars

3

资源数

0
C++服务器开发Python

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

itcv-GmbH

提供方

itcv-GmbH

最后核验

2026/5/17 20:23

运行时

Python

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

python3 tools/checks/run_checks.py

详细介绍

mcpc++SDK

![Build Status](https://github.com/itcv-GmbH/cpp-mcp-sdk/actions/workflows/ci.yml) ![License: MIT](https://opensource.org/licenses/MIT) ![C++17](https://isocpp.org/) ![MCP Spec](https://modelcontextprotocol.io/)

首个完全符合MCP 2025-11-25标准的C++SDK -构建生产就绪的MCP服务器和客户端,提供完整的协议支持,包括可流式HTTP传输和基于OAuth的授权。

特性

完成MCP 2025-11-25的实施

  • 运输:stdio+流式HTTP(单端点,可恢复SSE)
  • 服务器功能:工具、资源、带有完整CRUD操作的提示
  • 客户特点:根、采样、启发式(表单+URL模式)
  • 公用事业:Ping、取消、进度、任务、分页、日志记录、完成
  • 授权:OAuth 2.1+PKC、RFC9728发现、WWW身份验证挑战
  • 安全:源验证、SSRF保护、运行时间限制、令牌存储抽象

与跨平台支持

  • Linux (Ubuntu 24.04+)
  • macOS (14+)
  • 视窗 (服务器2022+)

生产就绪

  • 综合测试套件(18K+行,一致性+集成测试)
  • 具有可复制构建的固定依赖关系的CI/CD
  • 广泛的文档和安全指南
  • 零原始指针-RAII贯穿始终

快速开始

先决条件

  • CMake 3.16+
  • C++17编译器(GCC 7+、Clang 5+、MSVC 2017+)
  • vcpkg(用于依赖关系管理)
  • Python 3.12+(用于代码库检查)

构建

# Clone the repository
git clone https://github.com/itcv-GmbH/cpp-mcp-sdk.git
cd cpp-mcp-sdk

# Configure (macOS/Linux)
cmake --preset vcpkg-unix-release

# Configure (Windows)
cmake --preset vcpkg-windows-release

# Build
cmake --build build/vcpkg-unix-release        # macOS/Linux
cmake --build build/vcpkg-windows-release --config Release --parallel  # Windows

测试

# Run all tests
ctest --test-dir build/vcpkg-unix-release

# Run specific test
ctest --test-dir build/vcpkg-unix-release -R mcp_sdk_smoke_test -V

基本示例-MCP服务器

#include 
#include 
#include 

auto main() -> int
{
  try
  {
    // Create server with stdio transport
    auto server = mcp::Server::create();
    
    // Register a tool
    server->registerTool(
      mcp::server::ToolDefinition{
        .name = "echo",
        .description = "Echo back the input message",
        .inputSchema = R"({
          "type": "object",
          "properties": {
            "message": {"type": "string"}
          },
          "required": ["message"]
        })"_json
      },
      [](const mcp::server::ToolCallContext& ctx) -> mcp::server::CallToolResult {
        auto message = ctx.arguments["message"].asString();
        return mcp::server::CallToolResult::success(
          mcp::server::ResourceContent::text("echo://result", message)
        );
      }
    );
    
    // Start server (blocks on stdio)
    server->start();
    
    return 0;
  }
  catch (const std::exception& e)
  {
    std::cerr 
#include 
#include 

auto main() -> int
{
  try
  {
    // Create client
    auto client = mcp::Client::create();
    
    // Connect to MCP server via HTTP
    client->connectHttp(mcp::transport::http::HttpClientOptions{
      .serverUrl = "http://localhost:8080/mcp"
    });
    
    // Initialize session
    auto initResponse = client->initialize().get();
    
    // List available tools
    auto toolsResult = client->listTools();
    std::cout callTool("echo", {{"message", "Hello, MCP!"}});
    
    return 0;
  }
  catch (const std::exception& e)
  {
    std::cerr << "Client error: " << e.what() << '\n';
    return 1;
  }
}

安装

使用vcpkg(覆盖端口)

# In your CMakeLists.txt
find_package(mcp_sdk CONFIG REQUIRED)
target_link_libraries(your_target PRIVATE mcp::sdk)

使用CMake获取内容

include(FetchContent)

FetchContent_Declare(
  mcp_sdk
  GIT_REPOSITORY https://github.com/itcv-GmbH/cpp-mcp-sdk.git
  GIT_TAG        v0.1.0  # or specific commit
)

FetchContent_MakeAvailable(mcp_sdk)
target_link_libraries(your_target PRIVATE mcp::sdk)

文档

例子

examples/ 完整工作示例目录:

  • minimal_example.cpp -SDK基本用法
  • stdio_server/ -stdio传输服务器
  • dual_transport_server/ -多传输服务器(stdio+HTTP)
  • http_listen_example/ -具有侦听模式的HTTP服务器
  • bidirectional_sampling_elicitation/ -客户抽样和启发
  • http_server_auth/ -带有OAuth的HTTP服务器(需要TLS)
  • http_client_auth/ -具有身份验证的HTTP客户端(需要TLS)
  • consumer_find_package/ -CMake消费者示例
  • consumer_vcpkg_overlay/ -vcpkg覆盖消费者示例

建筑

include/mcp/
├── server/          # Server component (tools, resources, prompts)
├── client/          # Client component (roots, sampling, elicitation)
├── transport/       # Transports (stdio, Streamable HTTP)
├── jsonrpc/         # JSON-RPC 2.0 layer
├── auth/            # OAuth authorization
├── security/        # Security policies and limits
├── schema/          # JSON Schema validation
├── lifecycle/       # Session lifecycle management
└── util/            # Utilities (tasks, cancellation, progress)

测试

测试类别

  • 单元测试:单个组件测试
  • 一致性测试:MCP规范合规性验证
  • 集成测试:跨SDK互操作性
  • 特征矩阵测试:构建配置变体

运行测试

# All tests
ctest --test-dir build/vcpkg-unix-release

# Conformance tests only
ctest --test-dir build/vcpkg-unix-release -L conformance

# Integration tests (requires MCP_SDK_INTEGRATION_TESTS=ON)
ctest --test-dir build/vcpkg-unix-release -L integration

编译选项

选项默认值描述
MCP_SDK_BUILD_TESTSON构建测试套件
MCP_SDK_BUILD_EXAMPLESON构建示例
BUILD_SHARED_LIBS关闭构建共享库
MCP_SDK_ENABLE_TLSON启用TLS(需要OpenSSL)
MCP_SDK_ENABLE_AUTHON启用OAuth功能
MCP_SDK_INTEGRATION_TESTSOFF构建集成测试

合规

这个SDK是 完全符合 根据MCP规范2025-11-25:

  • ✅ 可流式HTTP传输(单端点,可恢复SSE)
  • ✅ OAuth 2.1+PKCE授权
  • ✅ RFC9728资源元数据发现
  • ✅ 所有服务器功能(工具、资源、提示)
  • ✅ 所有客户端特征(根、采样、启发)
  • ✅ 所有实用程序(ping、取消、进度、任务)
  • ✅ 跨平台(Linux、macOS、Windows)

请参阅中的MCP规范 .docs/requirements/mcp-spec-2025-11-25/ 了解详细的协议要求。

依赖项

通过vcpkg管理:

贡献

  1. 阅读 代理商.md 发展指南
  2. 创建要素分支
  3. 按照代码风格(clang-format/clang-tidy)进行更改
  4. 运行测试: ctest --test-dir build/vcpkg-unix-release
  5. 运行代码库检查: cmake --build build/vcpkg-unix-release --target codebase-check
  6. 提交拉取请求

代码质量

# Format code
cmake --build build/vcpkg-unix-release --target clang-format

# Check formatting
cmake --build build/vcpkg-unix-release --target clang-format-check

# Run all codebase checks
python3 tools/checks/run_checks.py

许可证

分布在 MIT许可证。参见 许可证 了解详情。

致谢

目录标签

目录标签

C++服务器开发Python本地部署MCP协议C++SDK客户端开发流式HTTPOAuth授权

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

oauth

运行时(runtime,运行环境)

Python

工具数量(toolCount,工具数)

1

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdiooauth部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP