serve.cpp¶
src/cli/serve.cpp
@file serve.cpp @brief `entropic serve` — a headless host for every MCP client (gh#204).
Owners: @tvanfossen
run_serve
int entropic::cli::run_serve(int argc, char *argv[])
entropic serve entry point.
src/cli/serve.cpp:162
Called by none
Calls block_shutdown_signals, configure_host, entropic_destroy, entropic_last_error, parse_args, print_usage, serve_until_stopped
Source · 27 lines
int run_serve(int argc, char* argv[]) {
ServeArgs args;
if (!parse_args(argc, argv, args)) {
print_usage();
return 1;
}
sigset_t set;
block_shutdown_signals(set);
entropic_handle_t handle = nullptr;
const entropic_error_t rc = configure_host(args, &handle);
if (rc != ENTROPIC_OK) {
const char* why = handle != nullptr ? entropic_last_error(handle) : nullptr;
std::fprintf(stderr, "entropic serve: cannot start (%d): %s\n",
static_cast<int>(rc), why != nullptr ? why : "unknown");
} else {
std::fprintf(stderr,
"entropic serve: http://127.0.0.1:%s/mcp (token: %s/.entropic/serve/%s.token)\n",
args.port.c_str(),
std::getenv("HOME") != nullptr ? std::getenv("HOME") : "~",
args.port.c_str());
const int sig = serve_until_stopped(handle, set);
std::fprintf(stderr, "entropic serve: %s, shutting down\n",
sig == SIGTERM ? "SIGTERM" : "SIGINT");
}
entropic_destroy(handle); // stops the listener, removes the token
return rc == ENTROPIC_OK ? 0 : 1;
}