| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
fastmcpp is a C++ port of the Python fastmcp library, providing native performance for MCP servers and clients with support for tools, resources, prompts, and MCP-standard transport layers (STDIO, HTTP/SSE, Streamable HTTP).
Status: Beta – core MCP features track the Python fastmcp reference.
Current version: 3.4.7.1
Optional:
The cpp‑httplib transports negotiate TLS only when cpp‑httplib itself is compiled with CPPHTTPLIB_OPENSSL_SUPPORT, so with the default FASTMCPP_ENABLE_OPENSSL=OFF an https:// URL fails at runtime with 'https' scheme is not supported. The URL parser accepts the scheme and defaults to port 443; only the TLS handshake is missing.
Three ways to fix that:
All three implement ITransport, so they drop into Client in place of StreamableHttpTransport. The two above share HttpRpcTransport, which owns the JSON-RPC framing, the redirect policy and session handling, so they also support the per-request header provider and report failures as TransportHttpError.
git clone https://github.com/0xeb/fastmcpp.git
cd fastmcpp
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release -jcmake -B build -S . \
-DCMAKE_BUILD_TYPE=Release \
-DFASTMCPP_ENABLE_POST_STREAMING=ON \
-DFASTMCPP_FETCH_CURL=ON \
-DFASTMCPP_ENABLE_STREAMING_TESTS=ONKey options:
| Option | Default | Description |
|---|---|---|
| CMAKE_BUILD_TYPE | Debug | Build configuration (Debug/Release/RelWithDebInfo) |
| FASTMCPP_BUILD_TESTS | ON | Build the test suite |
| FASTMCPP_BUILD_EXAMPLES | ON | Build the example programs |
| FASTMCPP_BUILD_CLI | ON | Build the fastmcpp command-line executable |
| FASTMCPP_ENABLE_POST_STREAMING | OFF | Enable HTTP POST streaming (requires libcurl) |
| FASTMCPP_FETCH_CURL | ON | Fetch and build curl (via FetchContent) if not found |
| FASTMCPP_ENABLE_OPENSSL | OFF | HTTPS for the cpp-httplib transports, via OpenSSL |
| FASTMCPP_ENABLE_WINHTTP | ON (Windows) | Build the WinHTTP client transport |
| FASTMCPP_ENABLE_CURL_TRANSPORT | OFF | Build the libcurl client transport (all platforms) |
| FASTMCPP_ENABLE_SAMPLING_HTTP_HANDLERS | OFF | Built-in OpenAI/Anthropic sampling handlers |
| FASTMCPP_ENABLE_STREAMING_TESTS | OFF | Enable SSE streaming tests |
Windows (Visual Studio):
cmake -B build -S . -G "Visual Studio 17 2022"
cmake --build build --config ReleaseLinux/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#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() {
// Create client with HTTP transport
fastmcpp::client::Client client(
std::make_unique<fastmcpp::client::HttpTransport>("http://localhost:8080")
);
// Initialize MCP session
auto init = client.initialize();
std::cout << "Connected to: " << init.serverInfo.name << std::endl;
// List available tools
auto tools = client.list_tools();
for (const auto& tool : tools) {
std::cout << "Tool: " << tool.name << std::endl;
}
// Call a tool
auto result = client.call_tool("calculator", {{"a", 5}, {"b", 3}});
std::cout << "Result: " << result.text() << std::endl;
return 0;
}#include <fastmcpp/tools/manager.hpp>
#include <fastmcpp/mcp/handler.hpp>
#include <fastmcpp/server/streamable_http_server.hpp>
int main() {
fastmcpp::tools::ToolManager tm;
// register tools on tm...
auto handler = fastmcpp::mcp::make_mcp_handler(
"myserver", "1.0.0", tm
);
// Streamable HTTP server on /mcp endpoint
fastmcpp::server::StreamableHttpServerWrapper server(
handler, "127.0.0.1", 8080, "/mcp"
);
server.start(); // non-blocking
std::this_thread::sleep_for(std::chrono::hours(1));
server.stop();
return 0;
}#include <fastmcpp/client/client.hpp>
#include <fastmcpp/client/transports.hpp>
int main() {
// Create client with Streamable HTTP transport (MCP spec 2025-03-26)
fastmcpp::client::Client client(
std::make_unique<fastmcpp::client::StreamableHttpTransport>(
"http://localhost:8080", "/mcp"
)
);
// Initialize MCP session (session ID managed automatically)
auto init = client.initialize();
std::cout << "Server: " << init.serverInfo.name << std::endl;
// Use the same clean API as other transports
auto tools = client.list_tools();
auto result = client.call_tool("echo", {{"message", "Hello!"}});
return 0;
}Create a proxy that forwards requests to a backend MCP server while allowing local overrides:
#include <fastmcpp/proxy.hpp>
#include <fastmcpp/server/sse_server.hpp>
#include <fastmcpp/util/schema_build.hpp>
int main() {
using fastmcpp::util::schema_build::to_object_schema_from_simple;
// Create a proxy to a remote backend
auto proxy = fastmcpp::create_proxy("http://backend:8080/mcp");
// Add local tools that extend or override remote capabilities
proxy.local_tools().register_tool({
"double",
to_object_schema_from_simple({{"n", "number"}}), // input: {n: number}
{{"type", "number"}}, // output schema
[](const fastmcpp::Json& args) { return args["n"].get<int>() * 2; }
});
// Create MCP handler and serve via SSE
auto handler = fastmcpp::mcp::make_mcp_handler(proxy);
fastmcpp::server::SseServerWrapper server(handler, "127.0.0.1", 8080);
server.start();
// Server runs until stopped...
return 0;
}The create_proxy() factory function automatically detects the transport type from the URL:
Local tools, resources, and prompts take precedence over remote ones with the same name.
Providers enable modular composition of tools and resources with automatic transforms:
#include <fastmcpp/providers/filesystem_provider.hpp>
#include <fastmcpp/providers/local_provider.hpp>
int main() {
using namespace fastmcpp::providers;
// Create a filesystem provider that exposes directory contents
FilesystemProvider fs_provider("./data", {
.allowed_extensions = {".txt", ".json", ".md"},
.max_file_size = 1024 * 1024 // 1MB
});
// Create a local provider with custom tools
LocalProvider local;
local.add_tool("greet", /*...*/);
// Apply namespace transform to prefix all tool names
auto namespaced = apply_transform<NamespaceTransform>(local, "myapp");
// Tools now: myapp_greet, etc.
auto handler = fastmcpp::mcp::make_mcp_handler(namespaced);
// ...
}Provider Transforms:
| Transform | Description |
|---|---|
| NamespaceTransform | Prefix tool/resource names (e.g., math_add) |
| VisibilityTransform | Filter which tools/resources are exposed |
| ToolTransform | Wrap tool inputs/outputs for preprocessing |
Resources can include metadata hints for clients:
fastmcpp::resources::ResourceDefinition res;
res.uri = "config://settings";
res.name = "Application Settings";
res.mime_type = "application/json";
res.annotations = Json{
{"audience", Json::array({"user", "assistant"})},
{"priority", 0.8}
};
res.icons = {{"icon.png", "image/png"}};
res.provider = [](const Json&) {
return ResourceContent{"config://settings", "application/json",
R"({"theme": "dark"})"};
};Annotations help clients:
See the examples/ directory for complete programs, including:
fastmcpp/
include/fastmcpp/ # Public headers (client, server, tools, etc.)
src/ # Implementation
tests/ # Test suite (standalone executables, no framework)
examples/ # Example programs
CMakeLists.txt # Build configuration
LICENSE # Apache 2.0 license
NOTICE # Attribution notices
README.md # This file
| Project | Description |
|---|---|
| copilot-sdk-cpp | C++ SDK for GitHub Copilot CLI |
| claude-agent-sdk-cpp | C++ SDK for Claude Code CLI with MCP support |
Want to add your project? Open a PR!
Contributions are welcome. Please:
Elias Bachaalany (@0xeb)
Pair-programmed with Claude Code and Codex.
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.
| Back | FazBrowse Home | New Git URL |