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

Show on the map →

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;
}
Activity · 17 steps
lines 163–163ServeArgs args;lines 164–164◇ if (!parse_args(argc, argv, args))lines 165–165print_usage();lines 166–166return 1;lines 168–168sigset_t set;lines 169–169block_shutdown_signals(set);lines 170–170entropic_handle_t handle = nullptr;lines 171–171const entropic_error_t rc = configure_host(args, &handle);lines 172–172◇ if (rc != ENTROPIC_OK)lines 173–173const char* why = handle != nullptr ? entropic_last_error(handle) : nullptr;lines 174–175std::fprintf(stderr, "entropic serve: cannot start (%d): %s\n", static_cast<int>(rc), why != nullptr ? why : "unknown");lines 176–176elselines 177–181std::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());lines 182–182const int sig = serve_until_stopped(handle, set);lines 183–184std::fprintf(stderr, "entropic serve: %s, shutting down\n", sig == SIGTERM ? "SIGTERM" : "SIGINT");lines 186–186entropic_destroy(handle);lines 187–187return rc == ENTROPIC_OK ? 0 : 1;

Requirements

REQ-BRIDGE-001