轻量级C++ MCP(模型上下文协议)SDK
概览
模型上下文协议(MCP)是一种开放协议,为AI模型和代理与各种资源、工具和服务的交互提供了标准化方式。该框架实现了MCP协议的核心功能,符合2025-03-26基本协议规范。 - :基于JSON-RPC 2.0标准的请求/响应通信 - :文件、API等资源的标准接口 - :注册和调用带有结构化参数的工具 - :注册并向客户端开放提示模板以支持AI工作流程 - :易于扩展新的资源类型和工具 - 支持HTTP及标准输入/输出(stdio)通信方法 这里有一些开源项目正在使用这个仓库。如果你也在用它,欢迎提交PR申请,在这里被推荐! - humanus.cpp:轻量级C++大型语言模型代理框架 - ...等待您的贡献...
概述(AI 翻译)
模型上下文协议(MCP)是一种开放协议,为AI模型和代理与各种资源、工具和服务的交互提供了标准化方式。该框架实现了MCP协议的核心功能,符合2025-03-26基本协议规范。
核心功能
- JSON-RPC 2.0 通信:基于 JSON-RPC 2.0 标准的请求/响应通信
- 资源抽象:文件、API等资源的标准接口。
- 工具注册:带结构化参数的注册和调用工具
- 提示模板:注册并向客户展示提示模板,用于AI工作流程
- 可扩展架构:易于扩展新的资源类型和工具
- 多传输支持:支持HTTP和标准输入/输出(stdio)通信方式
如何建造
用CMake构建示例:
通过测试构建:
支持SSL的构建:
收养者
以下是一些正在使用该仓库的开源项目。 如果你也在用,欢迎提交永久居民申请,在这里展示!
- humanus.cpp:轻量级C++大型语言模型代理框架
- …等你的贡献…
组成部分
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
MCP Protocol Framework
Model Context Protocol (MCP) is an open protocol that provides a standardized way for AI models and agents to interact with various resources, tools, and services. This framework implements the core functionality of the MCP protocol, conforming to the 2025-03-26 basic protocol specification.
Core Features
- JSON-RPC 2.0 Communication: Request/response communication based on JSON-RPC 2.0 standard
- Resource Abstraction: Standard interfaces for resources such as files, APIs, etc.
- Tool Registration: Register and call tools with structured parameters
- Prompt Templates: Register and expose prompt templates to clients for AI workflows
- Extensible Architecture: Easy to extend with new resource types and tools
- Multi-Transport Support: Supports HTTP and standard input/output (stdio) communication methods
How to Build
Example of building with CMake:
cmake -B build
cmake --build build --config Release
Build with tests:
git submodule update --init --recursive # Get GoogleTest
cmake -B build -DMCP_BUILD_TESTS=ON
cmake --build build --config Release
Build with SSL support:
git submodule update --init --recursive # Get GoogleTest
cmake -B build -DMCP_SSL=ON
cmake --build build --config Release
Adopters
Here are some open-source projects that are using this repository.
If you’re using it too, feel free to submit a PR to be featured here!
- humanus.cpp: Lightweight C++ LLM agent framework
- …waiting for your contribution…
Components
The MCP C++ library includes the following main components:
Core Components
Client Interface (mcp_client.h)
Defines the abstract interface for MCP clients, which all concrete client implementations inherit from.
SSE Client (mcp_sse_client.h, mcp_sse_client.cpp)
Client implementation that communicates with MCP servers using HTTP and Server-Sent Events (SSE).
Stdio Client (mcp_stdio_client.h, mcp_stdio_client.cpp)
Client implementation that communicates with MCP servers using standard input/output, capable of launching subprocesses and communicating with them.
Message Processing (mcp_message.h, mcp_message.cpp)
Handles serialization and deserialization of JSON-RPC messages.
Tool Management (mcp_tool.h, mcp_tool.cpp)
Manages and invokes MCP tools.
Resource Management (mcp_resource.h, mcp_resource.cpp)
Manages MCP resources.
Server (mcp_server.h, mcp_server.cpp)
Implements MCP server functionality.
Examples
HTTP Server Example (examples/server_example.cpp)
Example MCP server implementation over HTTP/SSE with custom tools:
- Time tool: Get the current time
- Calculator tool: Perform mathematical operations
- Echo tool: Echo input with optional transformations (to uppercase, reverse)
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →