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
113#pragma once
114
115#include <neograph/api.h>
116#include <neograph/acp/server.h>
117
118#include <chrono>
119#include <cstddef>
120#include <functional>
121#include <memory>
122#include <optional>
123#include <string>
124#include <string_view>
125#include <vector>
126
127namespace neograph::acp {
128
130struct NEOGRAPH_API ACPHttpConnection {
133 std::shared_ptr<void> owner;
134
138 std::unique_ptr<ACPServer> server;
139};
140
146struct NEOGRAPH_API ACPHttpConfig {
151 std::function<std::optional<std::string>(std::string_view authorization_header)>;
152
155 std::string host = "127.0.0.1";
156 int port = 0;
159 std::string endpoint = "/acp";
160
162 bool streamable_http = true;
164 bool websocket = true;
165
167 std::size_t max_connections = 16;
174 std::size_t max_payload_bytes = 4 * 1024 * 1024;
175
182 std::size_t http_threads = 8;
183 std::size_t max_http_threads = 64;
184 std::size_t max_queued_requests = 64;
185
190 std::chrono::milliseconds connection_idle_timeout = std::chrono::seconds(60);
193 std::chrono::milliseconds keepalive_interval = std::chrono::seconds(15);
194
201 std::vector<std::string> allowed_origins;
202
210 std::vector<std::string> allowed_hosts;
211
221 bool allow_client_mcp_servers = false;
222
229};
230
245class NEOGRAPH_API ACPHttpServer {
246public:
250 using ConnectionFactory = std::function<ACPHttpConnection(std::string_view principal)>;
251
258
259 ACPHttpServer(const ACPHttpServer&) = delete;
260 ACPHttpServer& operator=(const ACPHttpServer&) = delete;
261
264 bool start();
265
268
271 void stop();
272
273 bool is_running() const;
275 int port() const;
276
278 std::size_t connection_count() const;
279
284 std::shared_ptr<ACPClient> client();
285
290 void attach_client(std::shared_ptr<ACPClient> client);
291
292private:
293 struct Impl;
294 std::unique_ptr<Impl> impl_;
295};
296
297} // namespace neograph::acp
ACP server — exposes a NeoGraph as an Agent Client Protocol agent.
NEOGRAPH_API export/import macro for shared-library builds.
ACP over Streamable HTTP and WebSocket; see the file comment for the mapping, the deviations from the...
int port() const
The bound port; useful when ACPHttpConfig::port is 0.
bool start()
Bind and serve until stop() is called. Returns false if the address cannot be bound.
void stop()
Stop accepting, close every connection (cancelling its prompts) and join the threads....
std::function< ACPHttpConnection(std::string_view principal)> ConnectionFactory
Called once per new connection, with the principal the authenticator returned (empty without one)....
bool start_async()
Bind and serve on a background listener thread.
ACPHttpServer(ConnectionFactory factory, ACPHttpConfig config={})
std::shared_ptr< ACPClient > client()
A handle for agent-to-client requests (fs/*, permission) that reaches the connection owning the sessi...
void attach_client(std::shared_ptr< ACPClient > client)
Bind a client that graph nodes captured before this server existed, as ACPServer::attach_client does ...
std::size_t connection_count() const
The number of open connections.
Limits, Host and Origin rules and authentication of an ACPHttpServer.
std::vector< std::string > allowed_hosts
Host header names the server answers: host names, IPv4 addresses and bracketed IPv6 addresses ([::1])...
std::function< std::optional< std::string >(std::string_view authorization_header)> Authenticator
Resolve the HTTP Authorization header (empty when the request has none) into the principal that made ...
std::vector< std::string > allowed_origins
Exact allowed Origin values. An Origin header is rejected unless listed, except that a loopback bind ...
Authenticator authenticator
Authenticates every request, stream and upgrade when set (HTTP 401 and WWW-Authenticate: Bearer other...
What the factory of an ACPHttpServer returns for one new connection.
std::unique_ptr< ACPServer > server
A fresh, uninitialized ACPServer. The transport drives it with ACPServer::run(); set its capabilities...
std::shared_ptr< void > owner
Optional lifetime owner for objects captured by server; declared first so that it is released after t...