fastmcpp is a C++ port of fastmcp: MCP servers and clients with tools, resources, prompts, providers and middleware, over STDIO, HTTP/SSE and Streamable HTTP.
Version: 4.2.6.3. The first three numbers are the fastmcp release it matches; the fourth is a fastmcpp-only fix on top.
- Server and client for MCP
2025-11-25(default) and earlier handshake revisions, negotiated per client, plus the sessionless2026-07-28protocol from the same server. - Transports: STDIO, HTTP/SSE, Streamable HTTP. HTTPS clients through WinHTTP (Windows) or libcurl (any platform).
FastMCPapplication: tools, resources, resource templates, prompts, mounting, providers (local, filesystem, OpenAPI, skills, proxy) and transforms (namespace, visibility, tool transform, version filter, search, prompts/resources as tools).- Middleware: logging, timing, caching, rate limiting, error handling, ping, response limiting.
- Elicitation, sampling, progress, completions,
subscriptions/listen, background tasks, extensions and skills. - Client auth: bearer token and OAuth (discovery, dynamic registration, PKCE, refresh).
fastmcppcommand-line tool: discover, list and call servers; install server configs.- Windows, Linux, macOS.
Requires a C++17 compiler and CMake 3.16+. Dependencies (nlohmann/json, cpp-httplib, libcurl when needed) are 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| Option | Default | Description |
|---|---|---|
FASTMCPP_BUILD_EXAMPLES |
ON | Build the example programs |
FASTMCPP_BUILD_CLI |
ON | Build the fastmcpp executable |
FASTMCPP_ENABLE_WINHTTP |
ON (Windows) | WinHTTP client transport (HTTPS via Schannel) |
FASTMCPP_ENABLE_CURL_TRANSPORT |
OFF | libcurl client transport (HTTPS on every platform) |
FASTMCPP_ENABLE_POST_STREAMING |
OFF | Streamed POST responses (libcurl) |
FASTMCPP_FETCH_CURL |
ON | Fetch and build libcurl when it is not found |
FASTMCPP_ENABLE_OPENSSL |
OFF | HTTPS for the cpp-httplib transports |
FASTMCPP_ENABLE_SAMPLING_HTTP_HANDLERS |
OFF | Built-in OpenAI/Anthropic sampling handlers |
The default cpp-httplib transports have no TLS, so an https:// URL fails with 'https' scheme is not supported. Use client::WinHttpTransport on Windows (built by default) or
client::CurlTransport (FASTMCPP_ENABLE_CURL_TRANSPORT=ON); both drop into Client and support
the per-request header provider and auth. FASTMCPP_ENABLE_OPENSSL=ON also works, but if your
project supplies its own httplib::httplib target, that target must itself be built with OpenSSL.
#include <fastmcpp/app.hpp>
#include <fastmcpp/mcp/handler.hpp>
#include <fastmcpp/server/stdio_server.hpp>
int main()
{
using fastmcpp::Json;
fastmcpp::FastMCP app("calculator", "1.0.0");
app.tool("add", Json{{"a", "number"}, {"b", "number"}},
[](const Json& args) { return args.at("a").get<double>() + args.at("b").get<double>(); });
fastmcpp::server::StdioServerWrapper server(fastmcpp::mcp::make_mcp_handler(app));
server.run();
}Serve the same handler over Streamable HTTP or SSE instead:
fastmcpp::server::StreamableHttpServerWrapper http(handler, "127.0.0.1", 8080, "/mcp");
http.start();#include <fastmcpp/client/client.hpp>
#include <fastmcpp/client/transports.hpp>
fastmcpp::client::Client client(
std::make_unique<fastmcpp::client::StreamableHttpTransport>("http://localhost:8080", "/mcp"));
client.connect(); // sessionless 2026-07-28, falling back to the initialize handshake
for (const auto& tool : client.list_tools())
std::cout << tool.name << "\n";
std::cout << client.call_tool("add", {{"a", 2}, {"b", 3}}).text() << "\n";auto proxy = fastmcpp::create_proxy("http://backend:8080/mcp");
proxy.local_tools().register_tool(my_tool); // local components win over remote ones
fastmcpp::server::SseServerWrapper server(fastmcpp::mcp::make_mcp_handler(proxy), "127.0.0.1", 8080);
server.start();transport->set_auth(std::make_shared<client::auth::BearerAuth>("my-token"));
transport->set_auth(std::make_shared<client::auth::OAuth>()); // full OAuth flowOAuth opens the system browser and waits on a loopback callback by default; set
OAuthOptions::redirect_handler/callback_handler for headless use and
OAuthOptions::token_storage to keep tokens across runs.
-
Two protocol eras from one server. On Streamable HTTP a request whose
MCP-Protocol-Versionis not a handshake revision is served sessionlessly: noMcp-Session-Id, POST only, the envelope inparams._meta. On STDIO the first request decides. SSE is handshake-only. -
No server-initiated requests on the sessionless era.
Context::elicit()andContext::sample()throw there; ask for input by returningmcp::input_required(...)instead (below). -
Tool errors are results. Bad arguments, an unknown tool or an exception from the tool body come back as
isError: true. Middleware sees them first, asValidationError,NotFoundErrororfastmcpp::Error, and can turn them into JSON-RPC errors:struct JsonRpcArgumentErrors : fastmcpp::server::Middleware { fastmcpp::Json on_call_tool(const fastmcpp::server::MiddlewareContext& ctx, fastmcpp::server::CallNext next) override { try { return next(ctx); } catch (const fastmcpp::ValidationError& e) { return {{"jsonrpc", "2.0"}, {"id", ctx.message.value("id", fastmcpp::Json())}, {"error", {{"code", -32602}, {"message", e.what()}}}}; } } };
-
Resource not found is
-32602, withdata.uri. Malformed JSON-RPC messages are answered-32600 Invalid Request. -
Component metadata is in
_meta.fastmcp(tags,version). fastmcp 4 servers list static resources with a trailing slash (file://readme.txt/); read them by the listed URI. -
Host/Origin protection (DNS rebinding) for the HTTP servers is off by default. Enable it with
set_host_origin_guard(...)orFASTMCPP_HTTP_HOST_ORIGIN_PROTECTION=auto|strict, adding hosts and origins withFASTMCPP_HTTP_ALLOWED_HOSTS/FASTMCPP_HTTP_ALLOWED_ORIGINS.
On 2026-07-28 a handler that needs input returns what it needs; the client answers with its
elicitation, sampling or roots callback and calls again, and the handler runs again from the top.
#include "fastmcpp/mcp/input_required.hpp"
app.tool("book_flight", schema, [](const Json& args) -> Json {
auto answers = mcp::input_responses_of(args); // nullopt on the first round
if (!answers)
return mcp::input_required({{"dest", mcp::elicit_input("Where to?", dest_schema)}});
return "Booked " + (*answers)["dest"]["content"]["dest"].get<std::string>();
});State carried between rounds (mcp::request_state_of) is sealed with AES-256-GCM in the MCP
Python SDK's format and expires after 10 minutes. Replicas behind one endpoint need a shared key:
StreamableHttpServerWrapper::set_request_state_security(mcp::RequestStateSecurity::from_keys({secret})).
Client::call_tool(), get_prompt() and read_resource() drive the rounds automatically.
- Extensions: a
server::ServerExtensionadds a capability undercapabilities.extensions[id], request methods and atools/callinterceptor (FastMCP::add_extension()); clients opt in withClient::set_extension(id). - Background tasks: add
server::TasksExtensionand give a toolToolOptions::task_support = TaskSupport::Optional(orRequired).call_tool()follows a task to its result;call_tool_task()returns a handle. Tasks live in process memory. - Skills: serve
SKILL.mdbundles withskills::SkillCatalogProviderorskills::SkillsDirectoryProvider; clients useclient::skills::list_skills(),get_skill()andread_skill()(which verifies sizes and SHA-256 digests).
examples/ has complete programs, among them simple_echo.cpp (STDIO server),
stdio_instructions_server.cpp (FastMCP app), client_api.cpp, openapi_provider.cpp,
skills_provider.cpp, context_elicitation.cpp and tool_injection_middleware.cpp.
| Project | Description |
|---|---|
| copilot-sdk-cpp | C++ SDK for GitHub Copilot CLI |
| claude-agent-sdk-cpp | C++ SDK for Claude Code CLI with MCP support |
Copyright 2025 Elias Bachaalany (@0xeb). Apache License 2.0; see
LICENSE and NOTICE. fastmcpp is a port of fastmcp by
Jeremiah Lowin, which remains the reference implementation.
