0xeb/fastmcpp: C++ port of the fastmcp Python library

High-performance C++ implementation of Model Context Protocol (MCP) with support for device, resource, signaling, 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.

Situation: Beta – Core MCP features track Python fastmcp References, but the C++ test suite is intentionally much smaller than Python.

current version: 2.13.0. Python fastmcp remains the canonical source of truth for behavior and APIs; This C++ port is expected to follow suit.

  • Core MCP protocol implementation (JSON‑RPC).
  • Multiple transports: STDIO, HTTP (SSE), WebSocket.
  • Device management and invocation.
  • Resource and signal support.
  • JSON Schema Validation.
  • Middleware for request/response processing.
  • Integration with MCP-compliant CLI tools.
  • Cross-platform: Windows, Linux, MacOS.
  • C++17 or later compiler.
  • CMake 3.20 or higher.
  • nlohmann/json (brought in automatically).

optional:

  • libcurl (for HTTP POST streaming).
  • cpp‑httplib (HTTP server, invoked automatically).
  • easywsclient (WebSocket client, invoked 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

Main options:

OptiondefaultDescription
CMAKE_BUILD_TYPEdebugBuild configuration (Debug/Release/RelWithDebInfo)
FASTMCPP_ENABLE_POST_STREAMINGCloseEnable HTTP POST streaming (requires libcurl)
FASTMCPP_FETCH_CURLCloseIf not found then get and create curl
FASTMCPP_ENABLE_STREAMING_TESTSCloseEnable SSE Streaming Test
FASTMCPP_ENABLE_WS_STREAMING_TESTSCloseEnable WebSocket Streaming Testing

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):

  • Passed 24/24 testing (100% success rate).
  • 3 streaming tests were disabled due to infrastructure dependencies.
  • C++ test line count is much less than Python fastmcp Suite (see CCSDK parity documentation).
#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<: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<: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 examples/ Directory for complete programs, including:

  • stdio_server.cpp – STDIO MCP Server.
  • server_quickstart.cpp – HTTP server with routes.
  • client_quickstart.cpp – Use of HTTP client.
  • tool_example.cpp – Device 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. Make sure all tests pass.
  2. Follow existing code style.
  3. Add tests for new features.
  4. Update documents as needed.

Copyright 2025 Elias Bachalani

Licensed under the Apache License 2.0. Look LICENSE And NOTICE For information.

This is a C++ port of FastMCP by Jeremiah Lovin. The Python library is the canonical implementation; fastmcpp aims to match its behavior to key features.

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



Leave a Comment