10#include <neograph/mcp/harness_program_translator.h>
16#include <neograph/types.h>
17#include <neograph/tool_set.h>
32namespace sp {
class NativeArchive; }
41namespace neograph::mcp {
45enum class HarnessWorkerResponseKind {
52 AWAITING_TOOL_RESULTS,
62 std::size_t attempt = 1;
63 std::string repair_feedback;
64 std::optional<json> resume_value;
68 std::shared_ptr<UsageAccumulator> usage;
69 std::uint64_t model_token_budget = 0;
70 std::shared_ptr<std::atomic_bool> budget_exhausted;
75 HarnessWorkerResponseKind kind = HarnessWorkerResponseKind::VALUE;
79 bool provider_effect_uncertain =
false;
86 static HarnessWorkerResponse cancelled(std::string message = {});
87 static HarnessWorkerResponse awaiting_tool_results(json pending);
88 static HarnessWorkerResponse input_required(json pending);
91using HarnessWorkerExecutor = std::function<HarnessWorkerResponse(
92 const HarnessWorkerCall&,
const std::shared_ptr<graph::CancelToken>&)>;
94using HarnessCapabilityExecutor = std::function<json(
const json& tool_definition,
95 const json& arguments,
96 const std::shared_ptr<graph::CancelToken>&)>;
98struct HarnessProviderExecutorConfig {
99 std::shared_ptr<Provider> provider;
101 HarnessCapabilityExecutor capability_executor;
102 std::size_t max_tool_rounds = 8;
104 std::shared_ptr<sp::NativeArchive> native_archive;
108NEOGRAPH_HARNESS_API HarnessWorkerExecutor
116 virtual void append_event(
const json& event) = 0;
117 virtual std::vector<json> list_events(
const std::string& run_id,
118 std::size_t after_sequence = 0,
119 std::size_t limit = 1000) = 0;
127 virtual void save_artifact(
const std::string& artifact_id,
const json& record) = 0;
128 virtual std::optional<json> load_artifact(
const std::string& artifact_id) = 0;
129 virtual void save_run(
const std::string& run_id,
const json& record) = 0;
130 virtual std::optional<json> load_run(
const std::string& run_id) = 0;
135 std::size_t max_artifacts = std::numeric_limits<std::size_t>::max();
136 std::size_t max_runs = std::numeric_limits<std::size_t>::max();
137 std::vector<std::string> protected_artifact_ids;
138 std::vector<std::string> protected_run_ids;
146 std::vector<std::string> artifact_ids;
147 std::vector<std::string> run_ids;
164 void save_artifact(
const std::string& artifact_id,
const json& record)
override;
165 std::optional<json> load_artifact(
const std::string& artifact_id)
override;
166 void save_run(
const std::string& run_id,
const json& record)
override;
167 std::optional<json> load_run(
const std::string& run_id)
override;
171 std::unique_ptr<Impl> impl_;
176struct HarnessProgramHostConfig {
177 HarnessWorkerExecutor worker_executor;
178 HarnessCapabilityExecutor capability_executor;
179 HarnessProgramSnapshotConfig snapshots;
180 std::shared_ptr<graph::CheckpointStore> checkpoints;
181 std::shared_ptr<graph::Store> state_store;
182 std::shared_ptr<program::EngineGenerationCache> engines;
183 std::string compiler_build_id;
184 std::string provider_binding_identity;
186 json provider_host_configuration = json::object();
187 std::map<std::string, std::string> tool_binding_identities;
188 std::size_t scheduler_threads = 1;
191NEOGRAPH_HARNESS_API HarnessServiceResources
192make_harness_program_service_resources(HarnessProgramHostConfig config);
194using HarnessProgramCatalogFactory = std::function<std::shared_ptr<program::ProgramCatalog>(
195 std::shared_ptr<program::ProgramStore>,
196 const HarnessCapabilityBindingRequest&)>;
198using HarnessProgramRuntimeFactory = std::function<std::shared_ptr<program::ProgramRuntime>(
199 std::shared_ptr<program::ProgramCatalog>,
200 std::shared_ptr<program::ProgramTransitionStore>)>;
202 const program::ProgramVersion&,
203 const HarnessCapabilityBindingRequest&,
204 const std::vector<program::ProgramEvent>&)>;
213 HarnessProgramSnapshots snapshots;
214 std::shared_ptr<program::ProgramCompiler> compiler;
215 HarnessProgramCatalogFactory make_program_catalog;
216 HarnessProgramRuntimeFactory make_program_runtime;
217 HarnessRecordedBindingFactory make_recorded_binding;
218 std::string owner_scope;
223struct HarnessServiceConfig {
224 std::shared_ptr<HarnessRecordStore> record_store;
225 HarnessTranslationDefaults translation_defaults;
226 std::size_t max_artifacts = 128;
227 std::size_t max_runs = 128;
228 std::chrono::milliseconds poll_interval{1000};
229 std::chrono::milliseconds run_ttl{std::chrono::hours(24)};
232 bool enable_experimental_tasks =
false;
245 std::shared_ptr<HarnessJournal> journal,
268 json
get(
const std::string& run_id,
const std::string& view =
"status")
const;
271 json
get(
const std::string& run_id,
272 const std::string& view,
273 std::size_t after_sequence,
274 std::size_t limit)
const;
277 json
read(
const std::string& uri)
const;
284 std::shared_ptr<Impl> impl_;
NEOGRAPH_API export/import macro for shared-library builds.
Cooperative cancellation primitive for graph runs.
Admission and process-local materialization of immutable Programs.
Atomic JSON-file implementation suitable for local process restarts.
Append-only causal event boundary, separate from mutable run snapshots.
Durable storage boundary for retained Harness artifacts and run records.
Optional sibling boundary; HarnessRecordStore's stable vtable remains unchanged.
virtual HarnessRetentionResult cleanup_retained(const HarnessRetentionPolicy &policy)=0
Namespace filtering, reference checks and deletion must share one transaction.
Strict MCP adapter over ProgramCompiler -> ProgramCatalog -> ProgramRuntime.
json resume(const json &arguments)
Resume the exact pending call with a schema-validated host result.
json get(const std::string &run_id, const std::string &view="status") const
Return a compact snapshot for a run.
json start(const json &arguments)
Start from {artifact_id} or compile-and-start from {request}.
bool cancel(const std::string &run_id)
Request cooperative cancellation. Returns false for unknown/terminal runs.
json schema() const
Build-specific schemas, node palette, presets, and capabilities.
json get(const std::string &run_id, const std::string &view, std::size_t after_sequence, std::size_t limit) const
Return a paginated debugger view without changing the compact default.
void register_tools(MCPServer &server)
Register neograph_schema/compile/start/get/resume/cancel on a server.
json compile(const json &request)
Compile and retain an immutable artifact when the request is valid.
json read(const std::string &uri) const
Dereference a neograph://runs/<run_id>/<view> result URI.
Local, stdio-first MCP server with typed tools and bounded execution.
Move-only captured evidence proposal.
Cross-thread shared memory store (LangGraph Store equivalent).
NEOGRAPH_HARNESS_API HarnessWorkerExecutor make_provider_harness_executor(HarnessProviderExecutorConfig config)
Build a worker executor that calls a NeoGraph Provider directly.
Thin C++ RAII wrapper around yyjson with nlohmann-compatible API.
Pure versioned Program source compiler.
Atomic storage of admitted Program bundles and versions.
Execution service for admitted immutable Programs.
Count-bounded cleanup policy for stores that support durable retention.
std::string namespace_prefix
Restrict both counts and deletion candidates to this exact byte prefix.
Records removed by one atomic record-store cleanup pass.
Immutable host-owned Program control/data-plane resources.
std::string artifact_binding_identity
Host configuration identity that makes an artifact safe to reconnect.
Input handed to the embedding's provider/tool execution backend.
std::string run_id
Program-scoped accounting and cancellation budget supplied by the host node.
Typed worker response; failure classes never masquerade as valid output.