NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
http_server.h
Go to the documentation of this file.
1
5#pragma once
6
7#include <neograph/api.h>
9
10#include <chrono>
11#include <cstddef>
12#include <functional>
13#include <memory>
14#include <optional>
15#include <string>
16#include <string_view>
17#include <vector>
18
19namespace neograph::mcp {
20
21struct NEOGRAPH_API MCPHttpServerSession {
22 std::unique_ptr<MCPServer> server;
23
25 std::shared_ptr<void> owner;
26};
27
28struct NEOGRAPH_API MCPHttpServerConfig {
29 using BearerAuthorizer = std::function<std::optional<std::string>(std::string_view token)>;
30
31 std::string host = "127.0.0.1";
32 int port = 0;
33 std::string endpoint = "/mcp";
34
38 std::size_t max_sessions = 64;
39 std::size_t max_payload_bytes = 1024 * 1024;
45 std::size_t http_threads = 8;
46 std::size_t max_http_threads = 64;
47 std::size_t max_queued_requests = 64;
50 std::chrono::milliseconds response_timeout = std::chrono::minutes(10);
55 std::chrono::milliseconds session_idle_timeout = std::chrono::minutes(30);
56
61 std::vector<std::string> allowed_origins;
62
70 std::vector<std::string> allowed_hosts;
71
80 BearerAuthorizer bearer_authorizer;
81
94 json protected_resource_metadata;
95};
96
109class NEOGRAPH_API MCPHttpServer {
110public:
111 using ServerFactory = std::function<MCPHttpServerSession(std::string_view authorization_scope)>;
112
113 MCPHttpServer(ServerFactory factory, MCPHttpServerConfig config = {});
115
116 MCPHttpServer(const MCPHttpServer&) = delete;
117 MCPHttpServer& operator=(const MCPHttpServer&) = delete;
118
120 bool start();
121
124
126 void stop();
127
128 bool is_running() const;
129 int port() const;
130
131private:
132 struct Impl;
133 std::unique_ptr<Impl> impl_;
134};
135
136} // namespace neograph::mcp
NEOGRAPH_API export/import macro for shared-library builds.
Session-aware MCP Streamable HTTP server.
bool start_async()
Bind and serve on a background listener thread.
void stop()
Stop HTTP acceptance, cancel session work, and join the listener.
bool start()
Bind and serve until stop() is called.
Reusable MCP 2025-11-25 stdio server substrate.