NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1
10#pragma once
11
12#include <neograph/api.h>
13#include <neograph/types.h>
14
15#include <algorithm>
16#include <array>
17#include <chrono>
18#include <cstddef>
19#include <filesystem>
20#include <functional>
21#include <optional>
22#include <stdexcept>
23#include <string>
24#include <string_view>
25#include <utility>
26#include <vector>
27
28namespace neograph::mcp {
29
36inline constexpr std::array<std::string_view, 4> MCP_SUPPORTED_PROTOCOL_VERSIONS = {
37 "2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"};
38
39inline bool is_supported_protocol_version(std::string_view version) noexcept {
40 return std::find(MCP_SUPPORTED_PROTOCOL_VERSIONS.begin(),
41 MCP_SUPPORTED_PROTOCOL_VERSIONS.end(),
42 version) != MCP_SUPPORTED_PROTOCOL_VERSIONS.end();
43}
44
45using HeaderList = std::vector<std::pair<std::string, std::string>>;
46using HeaderProvider = std::function<HeaderList()>;
47
48struct NEOGRAPH_API MCPClientConfig {
49 std::chrono::milliseconds request_timeout{std::chrono::seconds(30)};
50 HeaderList headers;
51 HeaderProvider header_provider;
52};
53
55struct NEOGRAPH_API StdioClientConfig {
56 std::vector<std::string> argv;
57 std::filesystem::path cwd;
65 std::vector<std::pair<std::string, std::string>> environment;
66 bool replace_environment = false;
67 std::size_t max_frame_bytes = 16 * 1024 * 1024;
78 std::size_t max_stdout_text_lines = 1000;
79 std::size_t max_stdout_text_bytes = 256 * 1024;
84 std::size_t max_stderr_bytes = 64 * 1024;
87 std::chrono::milliseconds startup_timeout{10000};
88 std::chrono::milliseconds request_timeout{30000};
93 std::chrono::milliseconds cancel_grace{500};
94};
95
96class NEOGRAPH_API MCPError : public std::runtime_error {
97 public:
100 MCPError(int code, std::string message, json data = nullptr, int http_status = 0);
101
102 int code() const noexcept { return code_; }
103 const json& data() const noexcept { return data_; }
104 int http_status() const noexcept { return http_status_; }
105
106 private:
107 int code_;
108 json data_;
109 int http_status_ = 0;
110};
113enum class MCPFailure {
114 connection, timeout, cancelled, shutdown, http_status, protocol
115};
116
117class NEOGRAPH_API MCPTransportError : public std::runtime_error {
118 public:
119 MCPTransportError(MCPFailure failure, std::string message, int http_status = 0);
120 MCPFailure failure() const noexcept { return failure_; }
121 int http_status() const noexcept { return http_status_; }
122
123 private:
124 MCPFailure failure_;
125 int http_status_;
126};
127
128
129struct NEOGRAPH_API InitializeResult {
130 std::string protocol_version;
131 json capabilities = json::object();
132 json server_info = json::object();
133 std::string instructions;
134 json raw = json::object();
135
136 static InitializeResult from_json(const json& value);
137};
138
139struct NEOGRAPH_API ToolDefinition {
140 std::string name;
141 std::string title;
142 std::string description;
143 json icons = json::array();
147 json input_schema = json{{"type", "object"}};
148 json output_schema;
149 json annotations = json::object();
150 json execution = json::object();
151 json meta = json::object();
152 json raw = json::object();
153
154 static ToolDefinition from_json(const json& value);
155 json to_json() const;
156};
157
158struct NEOGRAPH_API ListToolsPage {
159 std::vector<ToolDefinition> tools;
160 std::optional<std::string> next_cursor;
161 json meta = json::object();
162 json raw = json::object();
163
164 static ListToolsPage from_json(const json& value);
165};
166
167struct NEOGRAPH_API CallToolResult {
168 json content = json::array();
169 json structured_content;
170 bool is_error = false;
171 json meta = json::object();
172 json raw = json::object();
173
174 static CallToolResult from_json(const json& value);
175 json to_json() const;
176};
177
178} // namespace neograph::mcp
NEOGRAPH_API export/import macro for shared-library builds.
constexpr std::array< std::string_view, 4 > MCP_SUPPORTED_PROTOCOL_VERSIONS
The MCP revisions NeoGraph's server answers and its client accepts, newest first, as the official SDK...
Definition types.h:36
MCPFailure
Transport and wire failures have one classification on both HTTP and stdio.
Definition types.h:113
Explicit subprocess boundary for local credentialless MCP adoption.
Definition types.h:55
std::vector< std::pair< std::string, std::string > > environment
Environment entries for the server.
Definition types.h:65