Fastmcpp (C++ Fastmcp)
Fastmcpp (Fastmcp for C++)

原始链接: https://github.com/0xeb/fastmcpp

## fastmcpp:高性能C++ MCP实现 fastmcpp是Python库`fastmcp`的C++移植版本,处于测试阶段,提供模型上下文协议(MCP)的高性能实现。它支持工具、资源、提示,以及多种传输层,包括STDIO、HTTP/SSE和WebSocket。 该库为构建MCP服务器和客户端提供原生C++体验,依赖项极少(nlohmann/json,可选libcurl、cpp-httplib、easywsclient)。主要特性包括JSON-RPC协议处理、JSON Schema验证,以及用于请求/响应处理的中间件。 fastmcpp跨平台(Windows、Linux、macOS),需要C++17或更高版本以及CMake 3.20+。虽然核心MCP功能与Python参考实现一致,但C++测试套件目前较小。Python的`fastmcp`仍然是行为和API的权威来源。 示例程序展示了服务器和客户端的使用、工具集成以及中间件实现。开发正在积极进行中,欢迎通过GitHub贡献代码。([https://github.com/0xeb/fastmcpp](https://github.com/0xeb/fastmcpp))

A new C++ implementation of the Multi-Modal Conversational Protocol (MCP), dubbed “Fastmcpp,” has been released on GitHub and is generating discussion on Hacker News. While some question the value of optimizing MCP given its ongoing development (specifically the pending stateless update) and the inherent speed limitations of Large Language Models compared to MCP servers, others see merit in the effort. Comments suggest optimization is valuable for resource-constrained environments where MCPs might run on devices or laptops, favoring self-contained binaries. One critique focuses on the choice of JSON library (nholmann-json) citing performance issues and recommending alternatives like RapidJSON. Despite these points, the project is largely praised as impressive, particularly for its asynchronous design.
相关文章

原文

High‑performance C++ implementation of the Model Context Protocol (MCP), with support for tools, resources, prompts, and multiple transport layers (STDIO, HTTP/SSE, WebSocket).

fastmcpp is a C++ port of the Python fastmcp library, providing native performance for MCP servers and clients with a small, focused dependency set.

Status: Beta – core MCP features track the Python fastmcp reference, but the C++ test suite is intentionally much smaller than the Python one.

Current version: 2.13.0. Python fastmcp remains the canonical source of truth for behavior and API; this C++ port is expected to follow it.

  • Core MCP protocol implementation (JSON‑RPC).
  • Multiple transports: STDIO, HTTP (SSE), WebSocket.
  • Tool management and invocation.
  • Resources and prompts support.
  • JSON Schema validation.
  • Middleware for request/response processing.
  • Integration with MCP‑compatible CLI tools.
  • Cross‑platform: Windows, Linux, macOS.
  • C++17 or later compiler.
  • CMake 3.20 or higher.
  • nlohmann/json (fetched automatically).

Optional:

  • libcurl (for HTTP POST streaming).
  • cpp‑httplib (HTTP server, fetched automatically).
  • easywsclient (WebSocket client, fetched automatically).
git clone https://github.com/0xeb/fastmcpp.git
cd fastmcpp

cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release -j

Recommended configuration options

cmake -B build -S . \
  -DCMAKE_BUILD_TYPE=Release \
  -DFASTMCPP_ENABLE_POST_STREAMING=ON \
  -DFASTMCPP_FETCH_CURL=ON \
  -DFASTMCPP_ENABLE_STREAMING_TESTS=ON \
  -DFASTMCPP_ENABLE_WS_STREAMING_TESTS=ON

Key options:

Option Default Description
CMAKE_BUILD_TYPE Debug Build configuration (Debug/Release/RelWithDebInfo)
FASTMCPP_ENABLE_POST_STREAMING OFF Enable HTTP POST streaming (requires libcurl)
FASTMCPP_FETCH_CURL OFF Fetch and build curl if not found
FASTMCPP_ENABLE_STREAMING_TESTS OFF Enable SSE streaming tests
FASTMCPP_ENABLE_WS_STREAMING_TESTS OFF Enable WebSocket streaming tests

Windows (Visual Studio):

cmake -B build -S . -G "Visual Studio 17 2022"
cmake --build build --config Release

Linux/macOS:

cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
cmake --build build -j"$(nproc)"
# Run all tests
ctest --test-dir build -C Release --output-on-failure

# Parallel
ctest --test-dir build -C Release -j4 --output-on-failure

# Run a specific test
ctest --test-dir build -C Release -R fastmcp_smoke --output-on-failure

# List tests
ctest --test-dir build -C Release -N

Current status (CI / WSL configuration):

  • 24/24 tests passing (100% success rate).
  • 3 streaming tests disabled due to infrastructure dependencies.
  • C++ test line count is much smaller than the Python fastmcp suite (see CCSDK parity docs).
#include <fastmcpp/tools/manager.hpp>
#include <fastmcpp/mcp/handler.hpp>
#include <fastmcpp/server/stdio_server.hpp>

int main() {
    fastmcpp::tools::ToolManager tm;
    // register tools on tm...

    auto handler = fastmcpp::mcp::make_mcp_handler(
        "myserver", "1.0.0", tm
    );

    fastmcpp::server::StdioServerWrapper server(handler);
    server.run();  // blocking
    return 0;
}
#include <fastmcpp/server/server.hpp>
#include <fastmcpp/server/http_server.hpp>

int main() {
    auto srv = std::make_shared<fastmcpp::server::Server>();
    srv->register_get("/health", [](const nlohmann::json&) {
        return nlohmann::json{{"status", "ok"}};
    });

    fastmcpp::server::HttpServerWrapper http(srv, "127.0.0.1", 8080);
    http.start();  // non‑blocking

    std::this_thread::sleep_for(std::chrono::hours(1));
    http.stop();
    return 0;
}
#include <fastmcpp/client/client.hpp>
#include <fastmcpp/client/transports.hpp>

int main() {
    auto transport = std::make_shared<fastmcpp::client::HttpTransport>(
        "http://localhost:8080"
    );

    fastmcpp::client::Client client(transport);
    auto response = client.call("tool/invoke", {
        {"name", "calculator"},
        {"input", {{"operation", "add"}, {"a", 5}, {"b", 3}}}
    });

    std::cout << response.dump() << std::endl;
    return 0;
}

See the examples/ directory for complete programs, including:

  • stdio_server.cpp – STDIO MCP server.
  • server_quickstart.cpp – HTTP server with routes.
  • client_quickstart.cpp – HTTP client usage.
  • tool_example.cpp – tool registration and invocation.
  • middleware_example.cpp – request/response middleware.
fastmcpp/
  include/fastmcpp/   # Public headers (client, server, tools, etc.)
  src/                # Implementation
  tests/              # Test suite (GoogleTest)
  examples/           # Example programs
  CMakeLists.txt      # Build configuration
  LICENSE             # Apache 2.0 license
  NOTICE              # Attribution notices
  README.md           # This file

Contributions are welcome. Please:

  1. Ensure all tests pass.
  2. Follow the existing code style.
  3. Add tests for new features.
  4. Update documentation as needed.

Copyright 2025 Elias Bachaalany

Licensed under the Apache License 2.0. See LICENSE and NOTICE for details.

This is a C++ port of fastmcp by Jeremiah Lowin. The Python library is the canonical implementation; fastmcpp aims to match its behavior for core features.

For issues and questions, use the GitHub issue tracker: https://github.com/0xeb/fastmcpp/issues.

联系我们 contact @ memedata.com