51#include <Poco/Dynamic/Var.h>
52#include <Poco/Exception.h>
53#include <Poco/JSON/Array.h>
54#include <Poco/JSON/Object.h>
55#include <Poco/JSON/Parser.h>
56#include <Poco/JSON/Stringifier.h>
57#include <Poco/Net/NetException.h>
58#include <Poco/Net/ServerSocket.h>
59#include <Poco/Net/SocketAddress.h>
60#include <Poco/Net/StreamSocket.h>
61#include <Poco/Timespan.h>
77std::string idToJson(
const Poco::Dynamic::Var&
id) {
78 if (
id.isEmpty())
return "null";
80 if (
id.isInteger() ||
id.isNumeric())
return std::to_string(
id.convert<Poco::Int64>());
84 return std::string(
"\"") +
mcpJsonEscape(
id.convert<std::string>()) +
"\"";
90std::string makeResult(
const std::string& idJson,
const std::string& resultJson) {
91 return std::string(
"{\"jsonrpc\":\"2.0\",\"id\":") + idJson +
",\"result\":" + resultJson +
"}";
94std::string makeError(
const std::string& idJson,
int code,
const std::string&
message) {
95 return std::string(
"{\"jsonrpc\":\"2.0\",\"id\":") + idJson +
",\"error\":{\"code\":" + std::to_string(
code) +
106 default:
return "none";
110std::string engineStatusJson(
const McpServer& mcp) {
112 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
114 o->set(
"paused", dbg.isPaused());
115 o->set(
"pauseReason", pauseReasonName(dbg.lastPauseReason()));
116 const auto& loc = dbg.pauseLocation();
117 o->set(
"source", loc.source);
118 o->set(
"line", loc.line);
119 o->set(
"function", loc.function);
120 o->set(
"mcpPort", mcp.port());
121 o->set(
"mcpConnected", mcp.hasClient());
122 switch (mcp.transport()) {
125 default: o->set(
"transport",
"none");
break;
128 o->set(
"gameRoot", mcp.gameRoot());
129 o->set(
"host", eve::cap::query<eve::IEditorHost>() ? eve::cap::query<eve::IEditorHost>()->
status()
140glm::vec3 argVec3(Poco::JSON::Object::Ptr args,
const char*
key,
const glm::vec3& def = {}) {
141 if (!args || !args->has(
key))
return def;
143 auto arr = args->getArray(
key);
144 if (arr && arr->size() >= 3) {
145 return glm::vec3(
static_cast<float>(arr->get(0).convert<
double>()),
146 static_cast<float>(arr->get(1).convert<
double>()),
147 static_cast<float>(arr->get(2).convert<
double>()));
154Poco::JSON::Array::Ptr vec3ToArray(
const glm::vec3&
v) {
155 Poco::JSON::Array::Ptr arr = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
167 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
169 o->set(
"error",
"Graphics module not available");
173 o->set(
"width",
s.width);
174 o->set(
"height",
s.height);
175 o->set(
"pixelWidth",
s.pixelWidth);
176 o->set(
"pixelHeight",
s.pixelHeight);
177 o->set(
"had3DThisFrame",
s.had3DThisFrame);
178 o->set(
"readbackEnabled",
s.readbackEnabled);
179 o->set(
"backend",
s.backend);
180 o->set(
"renderFlowEvents",
static_cast<int>(
DevTool::instance().renderFlow().eventCount()));
201void runPendingVisionDump() {
203 auto* cap = mcpCapture();
208 Poco::JSON::Object::Ptr
output = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
212 output->set(
"status",
"stale");
213 output->set(
"entityId", entityId);
215 output->set(
"error", inspected.status().describe());
218 const auto&
info = inspected.value();
219 output->set(
"status",
"ok");
222 Poco::JSON::Array::Ptr
position = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
227 Poco::JSON::Array::Ptr
tint = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
235 output->set(
"parallaxScale",
info.parallaxScale);
237 output->set(
"receiveLight",
info.receiveLight);
239 output->set(
"receiveShadow",
info.receiveShadow);
240 output->set(
"hasPackedMaterial",
info.hasPackedMaterial);
247 const std::string&
node) {
248 Poco::JSON::Object::Ptr
output = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
249 output->set(
"observer",
"scene-node");
253 output->set(
"status",
"not-found");
254 output->set(
"error",
"Scene node is missing from the observed host");
259 output->set(
"status",
"not-found");
260 output->set(
"error",
"Scene node is missing from the observed host");
264 output->set(
"status",
"ok");
279 Poco::JSON::Array::Ptr
children = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
285Poco::JSON::Object::Ptr runtimeObservation(Poco::JSON::Object::Ptr args, std::string*
error) {
288 auto* capture = mcpCapture();
290 if (
error) *
error =
"graphics module not available";
293 const int entityId =
getArgInt(args,
"entityId", -1);
296 if (
error) *
error =
"entityId and generation are required";
304 auto*
scene = mcpScene();
306 if (
error) *
error =
"scene module not available";
315struct ExpectationMatch {
322bool isJsonObject(
const Poco::Dynamic::Var&
value) {
return value.type() ==
typeid(Poco::JSON::Object::Ptr); }
324bool isJsonArray(
const Poco::Dynamic::Var&
value) {
return value.type() ==
typeid(Poco::JSON::Array::Ptr); }
326void compareExpectation(
const Poco::Dynamic::Var& actual,
const Poco::Dynamic::Var& expected,
const std::string&
path,
327 double tolerance, ExpectationMatch* match) {
328 if (!match || !match->valid)
return;
329 if (isJsonObject(expected)) {
330 if (!isJsonObject(actual)) {
331 match->valid =
false;
332 match->error =
"Expected object at " +
path;
335 auto actualObject = actual.extract<Poco::JSON::Object::Ptr>();
336 auto expectedObject = expected.extract<Poco::JSON::Object::Ptr>();
337 for (
const auto& item : *expectedObject) {
338 const std::string childPath =
path.empty() ? item.first :
path +
"." + item.first;
339 if (!actualObject->has(item.first)) {
340 match->valid =
false;
341 match->error =
"Observed value has no field " + childPath;
344 compareExpectation(actualObject->get(item.first), item.second, childPath, tolerance, match);
348 if (isJsonArray(expected)) {
349 if (!isJsonArray(actual)) {
350 match->valid =
false;
351 match->error =
"Expected array at " +
path;
354 auto actualArray = actual.extract<Poco::JSON::Array::Ptr>();
355 auto expectedArray = expected.extract<Poco::JSON::Array::Ptr>();
356 if (actualArray->size() < expectedArray->size()) {
357 match->valid =
false;
358 match->error =
"Observed array is shorter than expectation at " +
path;
362 compareExpectation(actualArray->get(
static_cast<unsigned>(
index)),
363 expectedArray->get(
static_cast<unsigned>(
index)),
364 path +
"[" + std::to_string(
index) +
"]", tolerance, match);
368 if (expected.isNumeric()) {
369 if (!actual.isNumeric()) {
370 match->valid =
false;
371 match->error =
"Expected numeric value at " +
path;
374 const double error = std::abs(actual.convert<
double>() - expected.convert<
double>());
375 match->maxError = std::max(match->maxError,
error);
376 if (
error > tolerance) match->mismatches.push_back(
path);
379 if (expected.isBoolean()) {
380 if (!actual.isBoolean()) {
381 match->valid =
false;
382 match->error =
"Expected boolean value at " +
path;
385 if (actual.convert<
bool>() != expected.convert<
bool>()) match->mismatches.push_back(
path);
388 if (expected.isString()) {
389 if (!actual.isString()) {
390 match->valid =
false;
391 match->error =
"Expected string value at " +
path;
394 if (actual.convert<std::string>() != expected.convert<std::string>()) match->mismatches.push_back(
path);
397 if (expected.isEmpty()) {
398 if (!actual.isEmpty()) match->mismatches.push_back(
path);
401 match->valid =
false;
402 match->error =
"Unsupported expectation value at " +
path;
405Poco::JSON::Object::Ptr expectationValue(
const ExpectationMatch& match) {
406 Poco::JSON::Object::Ptr
output = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
407 output->set(
"valid", match.valid);
408 output->set(
"converged", match.valid && match.mismatches.empty());
409 output->set(
"maxError", match.maxError);
410 Poco::JSON::Array::Ptr
mismatches = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
413 if (!match.error.empty())
output->set(
"error", match.error);
417Poco::JSON::Object::Ptr observationEvent(Poco::JSON::Object::Ptr
descriptor, Poco::JSON::Object::Ptr observation,
418 std::string*
error) {
419 Poco::JSON::Object::Ptr
event = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
420 event->set(
"observation", observation);
421 if (!observation || observation->optValue<std::string>(
"status",
"unavailable") !=
"ok") {
422 event->set(
"status",
"observation-unavailable");
423 event->set(
"converged",
false);
428 double tolerance = 0.001;
431 tolerance =
descriptor->get(
"tolerance").convert<
double>();
436 if (!std::isfinite(tolerance) || tolerance < 0.0) {
437 if (
error) *
error =
"tolerance must be a finite non-negative number";
440 const Poco::Dynamic::Var expected =
descriptor->get(
"expect");
441 if (!isJsonObject(expected)) {
442 if (
error) *
error =
"expect must be a JSON object";
445 ExpectationMatch match;
446 compareExpectation(Poco::Dynamic::Var(observation), expected,
"", tolerance, &match);
451 event->set(
"expectation", expectationValue(match));
452 event->set(
"converged", match.mismatches.empty());
453 event->set(
"maxError", match.maxError);
457std::string callTool(McpServer& mcp,
const std::string&
name, Poco::JSON::Object::Ptr args) {
461 if (
name ==
"eve_status")
return engineStatusJson(mcp);
463 if (
name ==
"eve_api_search") {
465 const std::string
module = getArgString(args, "module");
466 const std::string scriptClass =
getArgString(args,
"class");
471 std::ostringstream json;
472 json <<
"{\"ok\":true,\"schema\":\"eve.binding-api\",\"schemaVersion\":1,\"query\":\"" <<
mcpJsonEscape(query)
474 <<
"\",\"count\":" << hits.size() <<
",\"matches\":[";
475 for (
size_t i = 0; i < hits.size(); ++i) {
476 if (i != 0) json <<
',';
477 json <<
"{\"score\":" << hits[i].score <<
",\"contract\":" << hits[i].contract.toJson() <<
'}';
483 if (
name ==
"eve_api_get") {
485 const std::string scriptClass =
getArgString(args,
"class");
489 std::string lookupKey =
key;
494 const auto slash =
key.find(
'/');
495 if (slash == std::string::npos) {
496 const auto firstDot =
key.find(
'.');
497 if (firstDot != std::string::npos) {
499 lookupKey[firstDot] =
'/';
504 }
else if (!scriptClass.empty() && !
method.empty()) {
506 }
else if (!
method.empty()) {
509 return "{\"ok\":false,\"error\":\"missing key or method\"}";
512 std::string needle = !
key.empty() ?
key : (!scriptClass.empty() ? scriptClass +
"." +
method :
method);
513 for (
char& ch : needle) {
514 if (ch ==
'/' || ch ==
'.') ch =
' ';
517 std::ostringstream json;
518 json <<
"{\"ok\":false,\"error\":\"binding not found or method name is ambiguous\"";
520 json <<
",\"suggestions\":[";
521 for (
size_t i = 0; i < hits.size(); ++i) {
522 if (i != 0) json <<
',';
531 return std::string(
"{\"ok\":true,\"schema\":\"eve.binding-api\",\"schemaVersion\":1,\"contract\":") +
536 if (
name ==
"eve_script_components") {
538 return payload ? std::move(
payload).takeValue() : std::string(
"error: ") +
payload.status().describe();
541 if (
name ==
"eve_gameplay") {
542 if (!args || !args->has(
"request"))
return "error: missing request";
546 }
catch (
const std::exception&
error) {
547 return std::string(
"error: invalid request: ") +
error.what();
553 if (
name ==
"eve_play") {
554 if (!args || !args->has(
"request"))
return "error: missing request";
558 }
catch (
const std::exception&
error) {
559 return std::string(
"error: invalid request: ") +
error.what();
565 if (
name.rfind(
"eve_pixelworld_", 0) == 0) {
567 if (!
provider)
return "{\"ok\":false,\"error\":\"pixelworld module not available\"}";
568 return provider->invoke(
name.substr(std::string(
"eve_pixelworld_").size()),
573 if (
name ==
"eve_ui_tree") {
574 return mcpUI() ? mcpUI()->tree(
getArgString(args,
"host")) :
"error: ui module not available";
576 if (
name ==
"eve_ui_get") {
578 :
"error: ui module not available";
580 if (
name ==
"eve_ui_click") {
582 :
"error: ui module not available";
586 const auto editorInvoke = [&](
const char*
operation) {
588 : std::string(
"error: editor module not available");
590 if (
name ==
"eve_editor_commands")
return editorInvoke(
"commands");
591 if (
name ==
"eve_editor_target_list")
return editorInvoke(
"target-list");
592 if (
name ==
"eve_editor_target_create")
return editorInvoke(
"target-create");
593 if (
name ==
"eve_editor_target_close")
return editorInvoke(
"target-close");
594 if (
name ==
"eve_editor_inspect")
return editorInvoke(
"inspect");
595 if (
name ==
"eve_editor_plan")
return editorInvoke(
"plan");
596 if (
name ==
"eve_editor_commit")
return editorInvoke(
"commit");
597 if (
name ==
"eve_editor_execute")
return editorInvoke(
"execute");
598 if (
name ==
"eve_editor_observe_start") {
599 auto* editor = mcpEditor();
600 if (!editor)
return "error: editor module not available";
602 Poco::JSON::Object::Ptr observation = runtimeObservation(args, &
error);
603 if (!observation)
return "error: " +
error;
604 if (observation->getValue<std::string>(
"status") !=
"ok")
return mcpStringify(Poco::Dynamic::Var(observation));
605 Poco::JSON::Object::Ptr
event = observationEvent(args, observation, &
error);
607 Poco::JSON::Object::Ptr
invalid = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
608 invalid->set(
"status",
"invalid-expectation");
610 invalid->set(
"observation", observation);
613 Poco::JSON::Object::Ptr
request = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
614 request->set(
"descriptor", args);
618 if (
name ==
"eve_editor_observe_poll") {
619 auto* editor = mcpEditor();
620 if (!editor)
return "error: editor module not available";
622 Poco::JSON::Parser describeParser;
623 Poco::Dynamic::Var described =
624 describeParser.parse(editor->invoke(
"observe-describe",
mcpStringify(Poco::Dynamic::Var(args))));
625 auto describedObject = described.extract<Poco::JSON::Object::Ptr>();
626 if (!describedObject || describedObject->optValue<std::string>(
"status",
"") !=
"applied")
628 auto descriptor = describedObject->getObject(
"descriptor");
630 Poco::JSON::Object::Ptr observation = runtimeObservation(
descriptor, &
error);
632 observation = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
633 observation->set(
"status",
"unavailable");
634 observation->set(
"error",
error);
636 Poco::JSON::Object::Ptr
event = observationEvent(
descriptor, observation, &
error);
638 event = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
639 event->set(
"observation", observation);
640 event->set(
"status",
"expectation-observation-failed");
641 event->set(
"error",
error);
643 Poco::JSON::Object::Ptr
publish = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
646 Poco::JSON::Parser publishParser;
647 Poco::Dynamic::Var published =
648 publishParser.parse(editor->invoke(
"observe-publish",
mcpStringify(Poco::Dynamic::Var(publish))));
649 auto publishedObject = published.extract<Poco::JSON::Object::Ptr>();
650 if (!publishedObject || publishedObject->optValue<std::string>(
"status",
"") !=
"applied")
652 return editor->invoke(
"observe-poll",
mcpStringify(Poco::Dynamic::Var(args)));
653 }
catch (
const std::exception& exception) {
654 return std::string(
"error: could not poll observation session: ") + exception.what();
657 if (
name ==
"eve_editor_observe_close")
return editorInvoke(
"observe-close");
658 if (
name ==
"eve_editor_execute_observe") {
659 auto* editor = mcpEditor();
660 if (!editor)
return "error: editor module not available";
662 Poco::JSON::Object::Ptr before = runtimeObservation(args, &
error);
663 if (!before)
return "error: " +
error;
664 if (before->getValue<std::string>(
"status") !=
"ok")
return mcpStringify(Poco::Dynamic::Var(before));
666 Poco::JSON::Object::Ptr
output = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
667 output->set(
"before", before);
668 const bool hasExpectation = args && args->has(
"expect");
669 double tolerance = 0.001;
670 if (args && args->has(
"tolerance")) {
672 tolerance = args->get(
"tolerance").convert<
double>();
677 if (!std::isfinite(tolerance) || tolerance < 0.0) {
678 output->set(
"status",
"invalid-expectation");
679 output->set(
"error",
"tolerance must be a finite non-negative number");
682 Poco::Dynamic::Var expected;
683 if (hasExpectation) {
684 expected = args->get(
"expect");
685 if (!isJsonObject(expected)) {
686 output->set(
"status",
"invalid-expectation");
687 output->set(
"error",
"expect must be a JSON object");
690 ExpectationMatch validation;
691 compareExpectation(Poco::Dynamic::Var(before), expected,
"", tolerance, &validation);
692 if (!validation.valid) {
693 output->set(
"status",
"invalid-expectation");
694 output->set(
"expectation", expectationValue(validation));
695 output->set(
"error", validation.error);
699 bool transactionAccepted =
false;
701 Poco::JSON::Parser parser;
702 Poco::Dynamic::Var transaction =
703 parser.parse(editor->invoke(
"execute",
mcpStringify(Poco::Dynamic::Var(args))));
704 output->set(
"transaction", transaction);
705 Poco::JSON::Object::Ptr transactionObject = transaction.extract<Poco::JSON::Object::Ptr>();
706 transactionAccepted = transactionObject && transactionObject->optValue<
bool>(
"accepted",
false);
707 output->set(
"status", transactionAccepted ?
"observed" :
"transaction-rejected");
708 }
catch (
const std::exception& exception) {
709 output->set(
"status",
"failed");
710 output->set(
"error", std::string(
"Could not parse Editor transaction response: ") + exception.what());
713 Poco::JSON::Object::Ptr after = runtimeObservation(args, &
error);
715 after = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
716 after->set(
"status",
"unavailable");
717 after->set(
"error",
error);
719 output->set(
"after", after);
720 if (transactionAccepted && after->getValue<std::string>(
"status") !=
"ok")
721 output->set(
"status",
"runtime-observation-failed");
722 if (hasExpectation && after->getValue<std::string>(
"status") ==
"ok") {
723 ExpectationMatch match;
724 compareExpectation(Poco::Dynamic::Var(after), expected,
"", tolerance, &match);
725 output->set(
"expectation", expectationValue(match));
726 output->set(
"converged", match.valid && match.mismatches.empty());
727 output->set(
"maxError", match.maxError);
729 output->set(
"status",
"expectation-observation-failed");
730 output->set(
"error", match.error);
732 }
else if (hasExpectation) {
733 output->set(
"converged",
false);
736 Poco::JSON::Parser parser;
737 Poco::Dynamic::Var editorState =
738 parser.parse(editor->invoke(
"inspect",
mcpStringify(Poco::Dynamic::Var(args))));
739 output->set(
"editor", editorState);
740 }
catch (
const std::exception& exception) {
741 output->set(
"editorError", std::string(
"Could not parse Editor observation: ") + exception.what());
745 if (
name ==
"eve_editor_cancel")
return editorInvoke(
"cancel");
746 if (
name ==
"eve_editor_undo")
return editorInvoke(
"undo");
747 if (
name ==
"eve_editor_redo")
return editorInvoke(
"redo");
748 if (
name ==
"eve_editor_diagnostics")
return editorInvoke(
"diagnostics");
750 if (
name ==
"eve_renderable3d_get") {
751 auto* capture = mcpCapture();
752 if (!capture)
return "error: graphics module not available";
753 const int entityId =
getArgInt(args,
"entityId", -1);
755 if (entityId < 0 ||
generation < 0)
return "error: entityId and generation are required";
760 if (
name ==
"eve_scene_status") {
761 auto*
scene = mcpScene();
762 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
764 o->set(
"error",
"Scene module not available");
767 const std::string
host =
scene->activeHost();
769 o->set(
"activeHost", Poco::Dynamic::Var());
770 o->set(
"nodeCount", 0);
773 o->set(
"activeHost",
host);
774 o->set(
"nodeCount",
scene->nodeCount());
775 o->set(
"rootId",
scene->rootId());
779 if (
name ==
"eve_scene_nodes") {
780 auto*
scene = mcpScene();
781 if (!scene ||
scene->activeHost().empty())
return "error: no active scene host";
783 Poco::JSON::Array::Ptr arr = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
785 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
787 o->set(
"name",
n.name);
788 o->set(
"path",
n.path);
789 o->set(
"visible",
n.visible);
795 if (
name ==
"eve_scene_node_get") {
796 auto*
scene = mcpScene();
797 if (!scene ||
scene->activeHost().empty())
return "error: no active scene host";
799 if (
id.empty())
return "error: node not found: " +
id;
800 auto lookedUp =
scene->getNode(
id);
801 if (!lookedUp)
return "error: node not found: " +
id;
803 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
805 o->set(
"name",
n.name);
806 o->set(
"path",
n.path);
807 o->set(
"visible",
n.visible);
811 o->set(
"yaw",
n.yaw);
812 o->set(
"pitch",
n.pitch);
813 o->set(
"roll",
n.roll);
817 o->set(
"parent",
n.parent);
818 Poco::JSON::Array::Ptr kids = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
820 o->set(
"children", kids);
824 if (
name ==
"eve_scene_node_set") {
825 auto*
scene = mcpScene();
826 if (!scene ||
scene->activeHost().empty())
return "error: no active scene host";
828 if (
id.empty())
return "error: node not found: " +
id;
830 if (args && args->has(
"x") && args->has(
"y") && args->has(
"z")) {
834 if (args && args->has(
"visible")) {
837 return changed ?
"ok" :
"error: node not found: " +
id;
841 if (
name ==
"eve_procgen_recipes") {
842 auto* pg = mcpProcgen();
843 if (!pg)
return "error: Procgen module not available";
844 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
845 auto addList = [&](
const char*
key,
const std::vector<std::string>& items) {
846 Poco::JSON::Array::Ptr
a = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
847 for (
const auto& it : items)
a->
add(it);
850 addList(
"algorithms", pg->algorithms());
851 addList(
"meshRecipes", pg->meshRecipes());
852 addList(
"textureRecipes", pg->textureRecipes());
853 addList(
"pbrRecipes", pg->pbrRecipes());
857 if (
name ==
"eve_procgen_map") {
858 auto* pg = mcpProcgen();
859 if (!pg)
return "error: Procgen module not available";
860 const std::string algorithm =
getArgString(args,
"algorithm");
861 if (algorithm.empty())
return "error: missing algorithm";
862 std::vector<std::pair<std::string, std::string>>
params;
863 for (
const auto&
key : {
"roomCount",
"roomMin",
"roomMax",
"corridorWidth",
"autotile",
"scale",
"octaves"}) {
866 if (args && args->has(
"corridorStyle"))
868 auto generated = pg->generateMap(algorithm,
getArgInt(args,
"width", 32),
getArgInt(args,
"height", 32),
871 const auto* diag = generated.status().primaryDiagnostic();
872 return "error: " + (diag ? diag->message() : generated.status().describe());
874 return std::move(generated).value();
877 if (
name ==
"eve_procgen_mesh") {
878 auto* pg = mcpProcgen();
879 if (!pg)
return "error: Procgen module not available";
881 if (
recipe.empty())
return "error: missing recipe";
886 const auto* diag = built.status().primaryDiagnostic();
887 return "error: " + (diag ? diag->message() : built.status().describe());
889 const std::string json = std::move(built).value();
890 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
893 Poco::JSON::Parser parser;
894 Poco::Dynamic::Var parsed = parser.parse(json);
895 Poco::JSON::Object::Ptr jo = parsed.extract<Poco::JSON::Object::Ptr>();
896 o->set(
"vertices", jo->get(
"vertices"));
897 o->set(
"triangles", jo->get(
"triangles"));
905 if (
name ==
"eve_physics_new_world") {
906 auto* ph = mcpPhysics();
907 if (!ph)
return "error: Physics module not available";
909 if (
id < 0)
return "error: failed to create world";
910 float gx = 0.f, gy = 0.f;
911 ph->worldGravity(
id, &gx, &gy);
912 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
914 o->set(
"gravityX", gx);
915 o->set(
"gravityY", gy);
919 if (
name ==
"eve_physics_list_worlds") {
920 auto* ph = mcpPhysics();
921 if (!ph)
return "error: Physics module not available";
922 Poco::JSON::Array::Ptr arr = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
923 for (
int i = 0; i < ph->worldCount(); ++i) {
924 float gx = 0.f, gy = 0.f;
925 if (!ph->worldGravity(i, &gx, &gy))
continue;
926 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
928 o->set(
"gravityX", gx);
929 o->set(
"gravityY", gy);
935 if (
name ==
"eve_physics_raycast") {
936 auto* ph = mcpPhysics();
937 if (!ph)
return "error: Physics module not available";
941 return "error: unknown physics world id";
942 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
943 o->set(
"hit",
h.hit);
945 o->set(
"bodyId",
h.bodyId);
948 o->set(
"normalX",
h.normalX);
949 o->set(
"normalY",
h.normalY);
950 o->set(
"fraction",
h.fraction);
955 if (
name ==
"eve_physics_remove_world") {
956 auto* ph = mcpPhysics();
957 if (!ph)
return "error: Physics module not available";
958 return ph->removeWorld(
getArgInt(args,
"world", -1)) ?
"ok" :
"error: unknown physics world id";
962 if (
name ==
"eve_render_status") {
963 return renderStatusText(mcpCapture());
966 if (
name ==
"eve_render_describe") {
967 const bool fresh =
getArgBool(args,
"fresh",
false);
968 const std::string reason =
getArgString(args,
"reason");
972 if (
name ==
"eve_render_vision_config") {
974 if (args && args->has(
"baseUrl")) rv.setBaseUrl(
getArgString(args,
"baseUrl"));
975 if (args && args->has(
"apiKey")) rv.setApiKey(
getArgString(args,
"apiKey"));
976 if (args && args->has(
"model")) rv.setModel(
getArgString(args,
"model"));
977 if (args && args->has(
"path")) rv.setPath(
getArgString(args,
"path"));
978 if (args && args->has(
"timeoutMs")) rv.setTimeoutMs(
getArgInt(args,
"timeoutMs", 20000));
979 return rv.configJson();
982 if (
name ==
"eve_screenshot") {
983 auto* cap = mcpCapture();
984 if (!cap)
return "error: Graphics module not available";
986 if (
path.empty())
path =
"mcp_screenshot.png";
990 if (std::filesystem::path(
path).is_relative() && !mcp.gameRoot().empty())
991 path = (std::filesystem::path(mcp.gameRoot()) /
path).
string();
994 for (
char&
c :
path) {
995 if (
c ==
'\\')
c =
'/';
1005 const bool retryable = !
status.readbackEnabled;
1006 const auto* diag = captured.status().primaryDiagnostic();
1007 Poco::JSON::Object::Ptr o =
1009 retryable ?
"Wait one rendered frame and call eve_screenshot again"
1010 :
"Check eve_render_status / graphics readiness, then retry",
1011 retryable, {
"eve_render_status",
"eve_screenshot"});
1012 o->set(
"reason", retryable ?
"no-presented-frame" :
"capture-failed");
1013 o->set(
"readbackEnabled",
status.readbackEnabled);
1014 o->set(
"message", diag ? diag->message() : captured.
status().describe());
1020 std::error_code sizeError;
1021 const auto bytes = std::filesystem::file_size(
path, sizeError);
1022 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1024 o->set(
"path",
path);
1025 o->set(
"bytes", sizeError ? Poco::Int64(0) : static_cast<
Poco::Int64>(
bytes));
1026 o->set(
"width",
info.width);
1027 o->set(
"height",
info.height);
1032 if (
name ==
"eve_particles_status") {
1033 auto* part = mcpParticles();
1034 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1036 o->set(
"error",
"Particles module not available");
1039 o->set(
"emitterCount", part->emitterCount());
1043 if (
name ==
"eve_particles_emit") {
1044 auto* part = mcpParticles();
1045 if (!part)
return "error: Particles module not available";
1046 float ex = 0.f, ey = 0.f;
1050 return "error: failed to create emitter";
1051 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1054 o->set(
"count", cnt);
1059 if (
name ==
"eve_audio_status") {
1060 auto*
audio = mcpAudio();
1061 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1063 o->set(
"error",
"Audio module not available");
1066 o->set(
"volume",
audio->volume());
1070 if (
name ==
"eve_audio_set_volume") {
1071 auto*
audio = mcpAudio();
1072 if (!audio)
return "error: Audio module not available";
1077 if (
name ==
"eve_audio_stop_all") {
1078 auto*
audio = mcpAudio();
1079 if (!audio)
return "error: Audio module not available";
1085 if (
name ==
"eve_host_status") {
1086 return mcpHost() ? mcpHost()->status() :
"error: ui module not available";
1088 if (
name ==
"eve_host_window_open") {
1090 return mcpHost() ? mcpHost()->openWindow(
title,
getArgInt(args,
"width", 1280),
getArgInt(args,
"height", 800))
1091 :
"error: ui module not available";
1093 if (
name ==
"eve_host_window_close") {
1094 return mcpHost() ? mcpHost()->closeWindow() :
"error: ui module not available";
1096 if (
name ==
"eve_host_window_state") {
1097 return mcpHost() ? mcpHost()->windowState() :
"error: ui module not available";
1099 if (
name ==
"eve_host_editor_apply") {
1101 if (args && args->has(
"editor")) {
1103 Poco::JSON::Object::Ptr o = args->getObject(
"editor");
1112 if (json.empty())
return "error: missing editor";
1113 return mcpHost() ? mcpHost()->applyEditor(json) :
"error: ui module not available";
1115 if (
name ==
"eve_host_editor_remove") {
1116 return mcpHost() ? mcpHost()->removeEditor(
getArgString(args,
"id")) :
"error: ui module not available";
1118 if (
name ==
"eve_host_editor_list") {
1119 return mcpHost() ? mcpHost()->listEditors() :
"error: ui module not available";
1121 if (
name ==
"eve_host_editor_state") {
1122 return mcpHost() ? mcpHost()->editorState(
getArgString(args,
"id")) :
"error: ui module not available";
1124 if (
name ==
"eve_host_editor_set_value") {
1125 if (!args || !args->has(
"value"))
return "error: missing value";
1128 :
"error: ui module not available";
1130 if (
name ==
"eve_host_editor_save") {
1131 return mcpHost() ? mcpHost()->saveEditor(
getArgString(args,
"id")) :
"error: ui module not available";
1133 if (
name ==
"eve_host_editor_unload") {
1134 return mcpHost() ? mcpHost()->unloadEditor(
getArgString(args,
"id")) :
"error: ui module not available";
1136 if (
name ==
"eve_host_vm_register") {
1138 :
"error: ui module not available";
1140 if (
name ==
"eve_host_vm_unregister") {
1141 return mcpHost() ? mcpHost()->unregisterVM(
getArgString(args,
"name")) :
"error: ui module not available";
1143 if (
name ==
"eve_host_events") {
1144 return mcpHost() ? mcpHost()->consumeEvents(
getArgString(args,
"editor")) :
"error: ui module not available";
1146 if (
name ==
"eve_host_widget_rect") {
1148 :
"error: ui module not available";
1150 if (
name ==
"eve_host_capture") {
1151 return mcpHost() ? mcpHost()->capture(
getArgString(args,
"path")) :
"error: ui module not available";
1153 if (
name ==
"eve_host_script") {
1154 return mcpHost() ? mcpHost()->runScript(
getArgString(args,
"source")) :
"error: ui module not available";
1156 if (
name ==
"eve_host_resource_reload") {
1157 return mcpHost() ? mcpHost()->reloadResource(
getArgString(args,
"path")) :
"error: ui module not available";
1159 if (
name ==
"eve_host_hot_reload_status") {
1160 return mcpHost() ? mcpHost()->hotReloadStatus() :
"error: ui module not available";
1162 if (
name ==
"eve_host_shutdown") {
1163 if (mcpHost()) mcpHost()->requestExit();
1167 if (
name ==
"eve_eval") {
1168 const std::string expr =
getArgString(args,
"expression");
1169 if (expr.empty())
return "error: missing expression";
1170 auto info = dbg.evaluate(expr);
1171 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1172 o->set(
"expression", expr);
1173 o->set(
"name",
info.name);
1174 o->set(
"value",
info.value);
1175 o->set(
"type",
info.type);
1176 o->set(
"ok", !
info.value.empty() ||
info.type ==
"null" || !
info.name.empty());
1180 if (
name ==
"eve_skeleton_inspect") {
1183 if (actor.empty())
return "error: missing actor";
1184 const std::string expr =
1186 auto info = dbg.evaluate(expr);
1187 if (
info.value.empty())
return "error: eve_mcp_skeleton_inspect is unavailable";
1190 if (
info.value.size() >= 2 &&
info.value.front() ==
'"' &&
info.value.back() ==
'"')
1191 return info.value.substr(1,
info.value.size() - 2);
1195 if (
name ==
"eve_pause") {
1200 if (
name ==
"eve_continue") {
1202 dap.notifyContinued();
1205 if (
name ==
"eve_step_over") {
1207 dap.notifyContinued();
1210 if (
name ==
"eve_step_into") {
1212 dap.notifyContinued();
1215 if (
name ==
"eve_step_out") {
1217 dap.notifyContinued();
1220 if (
name ==
"eve_step_frame") {
1222 dap.notifyContinued();
1223 return "step_frame";
1226 if (
name ==
"eve_stack") {
1227 auto frames = dbg.stackTrace();
1228 Poco::JSON::Array::Ptr arr = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
1229 for (
const auto&
f : frames) {
1230 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1232 o->set(
"name",
f.name);
1233 o->set(
"source",
f.loc.source);
1234 o->set(
"line",
f.loc.line);
1235 o->set(
"function",
f.loc.function);
1241 if (
name ==
"eve_locals") {
1243 auto vars = dbg.locals(
level);
1244 Poco::JSON::Array::Ptr arr = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
1245 for (
const auto&
v : vars) {
1246 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1247 o->set(
"name",
v.name);
1248 o->set(
"value",
v.value);
1249 o->set(
"type",
v.type);
1255 if (
name ==
"eve_set_breakpoint") {
1258 if (
source.empty() ||
line <= 0)
return "error: need source and line";
1260 const int id = dbg.setBreakpoint(
source,
line,
true, condition);
1261 return "ok id=" + std::to_string(
id);
1263 if (
name ==
"eve_clear_breakpoint") {
1266 if (
source.empty() ||
line <= 0)
return "error: need source and line";
1267 return dbg.clearBreakpoint(
source,
line) ?
"cleared" :
"not_found";
1269 if (
name ==
"eve_list_breakpoints") {
1270 Poco::JSON::Array::Ptr arr = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
1271 for (
const auto& bp : dbg.breakpoints()) {
1272 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1273 o->set(
"id", bp.id);
1274 o->set(
"source", bp.source);
1275 o->set(
"line", bp.line);
1276 o->set(
"enabled", bp.enabled);
1277 o->set(
"condition", bp.condition);
1283 if (
name ==
"eve_watch_add") {
1284 const std::string expr =
getArgString(args,
"expression");
1285 if (expr.empty())
return "error: missing expression";
1287 dbg.refreshWatches();
1290 if (
name ==
"eve_watch_list") {
1291 dbg.refreshWatches();
1292 Poco::JSON::Array::Ptr arr = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
1293 for (
const auto&
w : dbg.watches()) {
1294 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1295 o->set(
"expression",
w.expression);
1296 o->set(
"value",
w.value);
1303 if (
name ==
"eve_snapshot_capture") {
1305 if (!
vm)
return "error: no VM";
1308 if (!err.empty() && json.empty())
return "error: " + err;
1311 if (
name ==
"eve_snapshot_restore") {
1313 if (!
vm)
return "error: no VM";
1319 if (
name ==
"eve_snapshot_save") {
1321 if (!
vm)
return "error: no VM";
1327 if (
name ==
"eve_snapshot_load") {
1329 if (!
vm)
return "error: no VM";
1336 if (
name ==
"eve_error_slice") {
1338 if (!last.empty())
return last;
1339 return "no prior error";
1342 if (
name ==
"eve_run_script") {
1344 if (!
vm)
return "error: no VM";
1346 if (
source.empty())
return "error: missing source";
1352 if (
name ==
"eve_ai_note") {
1354 if (
text.empty())
return "error: missing text";
1362 if (
name ==
"eve_scene_director_install") {
1364 if (!
vm)
return "error: no VM";
1372 if (
name ==
"eve_scene_director_status") {
1374 if (!
vm)
return "error: no VM";
1380 if (
name ==
"eve_scene_reset") {
1382 if (!
vm)
return "error: no VM";
1390 if (
name ==
"eve_scene_modify") {
1392 if (!
vm)
return "error: no VM";
1397 Poco::Dynamic::Var paramsVar;
1398 if (args && args->has(
"params")) {
1400 paramsVar = Poco::Dynamic::Var(args->getObject(
"params"));
1405 auto actionLiteral =
sceneLiteral(Poco::Dynamic::Var(action));
1411 const std::string snippet =
"return ::scene_director.modify(" + actionLiteral.value() +
"," +
1412 targetLiteral.value() +
"," + paramsLiteral.value() +
");";
1419 if (
name ==
"eve_scene_batch") {
1421 if (!
vm)
return "error: no VM";
1425 Poco::Dynamic::Var actionsVar;
1427 actionsVar = Poco::Dynamic::Var(args->getArray(
"actions"));
1431 Poco::JSON::Object::Ptr
options = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1432 if (args->has(
"stopOnError")) {
1434 options->set(
"stopOnError", args->get(
"stopOnError").convert<
bool>());
1439 options->set(
"stopOnError",
true);
1445 const std::string snippet =
1446 "return ::scene_director.batch(" + actionsLiteral.value() +
"," + optionsLiteral.value() +
");";
1452 if (
name ==
"eve_camera_generate") {
1454 if (!
vm)
return "error: no VM";
1458 const std::string snippet =
"return ::scene_director.cameras(" + std::to_string(
count) +
");";
1464 if (
name ==
"eve_scene_info") {
1466 if (!
vm)
return "error: no VM";
1475 if (
name ==
"inspect_generate_scene_camera_views") {
1476 const glm::vec3
center = argVec3(args,
"center");
1479 Poco::JSON::Object::Ptr
root = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1480 Poco::JSON::Array::Ptr arr = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
1481 for (
const auto&
v : views) {
1482 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1483 o->set(
"name",
v.name);
1484 o->set(
"kind",
v.kind);
1485 o->set(
"eye", vec3ToArray(
v.eye));
1486 o->set(
"target", vec3ToArray(
v.target));
1487 o->set(
"fov",
static_cast<double>(
v.fovYDeg));
1490 root->set(
"views", arr);
1494 if (
name ==
"set_camera_pose") {
1495 const glm::vec3
pos = argVec3(args,
"pos", glm::vec3(0.f, 1.8f, 0.f));
1496 const glm::vec3 rot = argVec3(args,
"rot", glm::vec3(0.f));
1499 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1502 o->set(
"error",
"failed to set camera pose (no Graphics/Camera3D)");
1505 Poco::JSON::Parser parser;
1513 if (
name ==
"capture_render_frame") {
1516 std::vector<std::string> buffers;
1517 if (args && args->has(
"buffers")) {
1519 auto arr = args->getArray(
"buffers");
1521 for (
size_t i = 0; i < arr->size(); ++i)
1522 buffers.push_back(arr->get(
static_cast<unsigned int>(i)).convert<std::string>());
1528 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1529 o->set(
"ok", res.ok);
1531 o->set(
"png", res.pngPath);
1532 o->set(
"json", res.jsonPath);
1533 o->set(
"width", res.width);
1534 o->set(
"height", res.height);
1535 o->set(
"entityCount", res.entityCount);
1536 if (!res.depthPngPath.empty()) o->set(
"depthPng", res.depthPngPath);
1537 if (!res.normalPngPath.empty()) o->set(
"normalPng", res.normalPngPath);
1538 if (!res.idPngPath.empty()) o->set(
"idPng", res.idPngPath);
1539 if (!res.idJsonPath.empty()) o->set(
"idJson", res.idJsonPath);
1540 if (!res.unsupported.empty()) {
1541 Poco::JSON::Array::Ptr uns = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
1542 for (
const auto&
u : res.unsupported) uns->
add(
u);
1543 o->set(
"unsupported", uns);
1546 o->set(
"error", res.error);
1551 if (
name ==
"get_visible_entities_screen_bbox") {
1552 const bool hasPos = args && args->has(
"pos");
1553 const bool hasTarget = args && args->has(
"target");
1554 if (hasPos && hasTarget) {
1555 const glm::vec3
eye = argVec3(args,
"pos");
1556 const glm::vec3 tgt = argVec3(args,
"target");
1564 return "error: unknown tool " +
name;
1570constexpr const char* kMcpProtocolLatest =
"2025-06-18";
1572bool isSupportedProtocol(
const std::string& requested) {
1573 return requested ==
"2025-06-18" || requested ==
"2025-03-26" || requested ==
"2024-11-05";
1576std::string handleInitialize(McpServer& mcp,
const std::string& idJson, Poco::JSON::Object::Ptr
params) {
1577 std::string clientName =
"mcp-client";
1578 std::string requested = kMcpProtocolLatest;
1581 if (
params->has(
"clientInfo")) {
1583 if (
info &&
info->has(
"name")) clientName =
info->get(
"name").convert<std::string>();
1585 if (
params->has(
"protocolVersion")) requested =
params->get(
"protocolVersion").convert<std::string>();
1596 const std::string protocol = isSupportedProtocol(requested) ? requested : kMcpProtocolLatest;
1599 const std::string resultJson =
1600 std::string(
"{\"protocolVersion\":\"") +
mcpJsonEscape(protocol) +
1601 "\",\"capabilities\":{\"tools\":{},\"resources\":{},\"prompts\":{}},"
1602 "\"serverInfo\":{\"name\":\"evengine\",\"title\":\"EVEngine MCP\",\"version\":\"0.7.0\"},"
1603 "\"instructions\":\"EVEngine MCP for AI-assisted game development. Call eve_api_search/eve_api_get to look up "
1604 "this build's EveScript bindings before writing .nut (do not invent Unity C# names); prefer eve_play and "
1605 "editor commands over eve_eval for gameplay. Diagnose through the game's own channels: "
1606 "eve_console_read returns the runtime console (Squirrel print/error plus engine log lines) with a monotonic "
1607 "seq cursor, eve_error_slice returns the last script/render error slice, and eve_render_status with "
1608 "eve_screenshot/eve_screenshot_image capture engine-owned frames. Drive a run with eve_pause/eve_step_* or "
1609 "eve_play (clock/step/observe/capture/checkpoint/act), assert with eve_eval/eve_run_script and snapshot "
1610 "tools, and inspect live state with eve_editor_*/eve_scene_*/eve_ui_*. Use eve_restart (optional args) to "
1611 "soft-restart the game without reloading the resource cache — do not kill the process between AI debug "
1612 "iterations. eve_host_* tools create JSON-defined editor windows bound to Squirrel ViewModels (MVVM) for "
1613 "AI-crafted terrain/material/event editors.\"}";
1614 return makeResult(idJson, resultJson);
1617std::string handleToolsList(
const std::string& idJson) {
1624 std::string
body = kToolsBody;
1626 if (!scripted.empty()) {
1633 std::string tools =
"{\"tools\":[";
1636 return makeResult(idJson, tools);
1639std::string handleToolsCall(McpServer& mcp,
const std::string& idJson, Poco::JSON::Object::Ptr
params) {
1640 if (!
params || !
params->has(
"name"))
return makeError(idJson, -32602,
"tools/call requires params.name");
1643 name =
params->get(
"name").convert<std::string>();
1645 return makeError(idJson, -32602,
"tools/call params.name must be a string");
1647 Poco::JSON::Object::Ptr args = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1648 if (
params->has(
"arguments")) {
1650 args =
params->getObject(
"arguments");
1669 const auto payload = route->call(mcp,
name, args);
1673 }
catch (
const std::exception& e) {
1675 return makeResult(idJson,
textContentResult(std::string(
"error: ") + e.what(),
true));
1684 }
catch (
const std::exception& e) {
1686 return makeResult(idJson,
textContentResult(std::string(
"error: ") + e.what(),
true));
1691 const std::string
out = callTool(mcp,
name, args);
1692 const bool isErr =
out.rfind(
"error:", 0) == 0;
1694 }
catch (
const std::exception& e) {
1696 return makeResult(idJson,
textContentResult(std::string(
"error: ") + e.what(),
true));
1700std::string handleResourcesList(
const std::string& idJson) {
1701 return makeResult(idJson,
1703 "{\"uri\":\"eve://status\",\"name\":\"status\",\"description\":\"Debugger / MCP / DAP "
1704 "status\",\"mimeType\":\"application/json\"},"
1705 "{\"uri\":\"eve://game-world\",\"name\":\"game-world\",\"description\":\"What kind of game "
1706 "world is running at runtime: script publishWorldContext, live domains, and configured "
1707 "/ instantiated modules\",\"mimeType\":\"application/json\"},"
1708 "{\"uri\":\"eve://error-report\",\"name\":\"error-report\",\"description\":\"Last DevTools error "
1709 "slice report\",\"mimeType\":\"text/plain\"},"
1710 "{\"uri\":\"eve://ai-session\",\"name\":\"ai-session\",\"description\":\"AI / MCP session "
1711 "log\",\"mimeType\":\"text/plain\"},"
1712 "{\"uri\":\"eve://callgraph\",\"name\":\"callgraph\",\"description\":\"CallGraph event "
1713 "summary\",\"mimeType\":\"application/json\"},"
1714 "{\"uri\":\"eve://crash-log\",\"name\":\"crash-log\",\"description\":\"Persistent crash/error "
1715 "log (eve.log) that survives a process death\",\"mimeType\":\"text/plain\"}"
1719std::string handleResourcesRead(
const std::string& idJson, Poco::JSON::Object::Ptr
params) {
1720 if (!
params || !
params->has(
"uri"))
return makeError(idJson, -32602,
"resources/read requires params.uri");
1723 uri =
params->get(
"uri").convert<std::string>();
1725 return makeError(idJson, -32602,
"resources/read params.uri must be a string");
1728 std::string mime =
"text/plain";
1729 if (
uri ==
"eve://status") {
1731 mime =
"application/json";
1732 }
else if (
uri ==
"eve://game-world") {
1735 const auto* diag =
snapshot.status().primaryDiagnostic();
1738 diag && !diag->message().empty() ? diag->message() :
std::
string(
"game world snapshot failed"));
1740 auto json =
snapshot.value().toJson();
1742 const auto* diag = json.status().primaryDiagnostic();
1743 return makeError(idJson, -32002,
1744 diag && !diag->message().empty() ? diag->message() :
"game world JSON failed");
1746 text = json.value();
1747 mime =
"application/json";
1748 }
else if (
uri ==
"eve://error-report") {
1750 if (
text.empty())
text =
"(no error report yet)\n";
1751 }
else if (
uri ==
"eve://ai-session") {
1753 if (
text.empty())
text =
"(empty)\n";
1754 }
else if (
uri ==
"eve://callgraph") {
1755 Poco::JSON::Object::Ptr o = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1759 mime =
"application/json";
1760 }
else if (
uri ==
"eve://crash-log") {
1764 constexpr std::streamoff kCrashResourceBytes = 64 * 1024;
1765 text =
"(no crash log yet)\n";
1767 std::error_code
exists = std::error_code();
1769 std::ifstream in(
path, std::ios::binary);
1771 in.seekg(0, std::ios::end);
1772 const std::streamoff
size = in.tellg();
1773 const std::streamoff
start =
size > kCrashResourceBytes ?
size - kCrashResourceBytes : 0;
1775 std::ostringstream
buffer;
1779 const auto newline =
text.find(
'\n');
1780 text.erase(0, newline == std::string::npos ?
text.size() : newline + 1);
1781 text =
"[…truncated; full log at " +
path +
"]\n" +
text;
1783 if (
text.empty())
text =
"(crash log is empty)\n";
1787 return makeError(idJson, -32002,
"Unknown resource: " +
uri);
1790 Poco::JSON::Object::Ptr contentsItem = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1791 contentsItem->set(
"uri",
uri);
1792 contentsItem->set(
"mimeType", mime);
1793 contentsItem->set(
"text",
text);
1794 Poco::JSON::Array::Ptr contents = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
1795 contents->add(contentsItem);
1796 Poco::JSON::Object::Ptr
result = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1797 result->set(
"contents", contents);
1801std::string handlePromptsList(
const std::string& idJson) {
1805 "{\"name\":\"debug_failure\",\"description\":\"Investigate the latest script/render error using MCP tools and "
1806 "the error slice.\"},"
1807 "{\"name\":\"test_scenario\",\"description\":\"Drive a reproducible in-engine test: pause, snapshot, eval "
1808 "assertions, continue.\"},"
1809 "{\"name\":\"ai_game_review\",\"description\":\"Review live game state for AI-generated content issues.\"}"
1813std::string handlePromptsGet(
const std::string& idJson, Poco::JSON::Object::Ptr
params) {
1814 if (!
params || !
params->has(
"name"))
return makeError(idJson, -32602,
"prompts/get requires params.name");
1817 name =
params->get(
"name").convert<std::string>();
1819 return makeError(idJson, -32602,
"prompts/get params.name must be a string");
1822 if (
name ==
"debug_failure") {
1824 "You are debugging an EVEngine game via MCP.\n"
1825 "1) Call eve_status and read resource eve://error-report.\n"
1826 "2) Use eve_stack / eve_locals / eve_eval to inspect state.\n"
1827 "3) Use eve_error_slice to narrow script/render causes.\n"
1828 "4) Propose a minimal fix; verify with eve_run_script or snapshot restore.";
1829 }
else if (
name ==
"test_scenario") {
1831 "Design a short automated test against the live EVEngine session:\n"
1832 "1) Call eve_game_world (or read eve://game-world) to learn genre/systems, then eve_play op=status.\n"
1833 "2) Observe declared script roots from game.agent.json; do not invent observation paths.\n"
1834 "3) Pause, step host frames, capture an engine screenshot, and checkpoint restore with eve_play.\n"
1835 "4) Use eve_gameplay for player-equivalent domain commands when the contract declares a gameplay-domain.\n"
1836 "5) Do not use eve_eval as the official observation path.";
1837 }
else if (
name ==
"ai_game_review") {
1839 "Review this AI-generated or AI-assisted game build:\n"
1840 "1) eve_game_world + eve_status + eve_ai_log to learn the world and recent agent actions.\n"
1841 "2) Spot-check critical roots with eve_play observe (or eve_eval only as a debug escape hatch).\n"
1842 "3) If unstable, pause and capture a snapshot.\n"
1843 "4) Summarize risks and suggested script fixes.";
1845 return makeError(idJson, -32602,
"Unknown prompt: " +
name);
1848 Poco::JSON::Object::Ptr msg = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1849 msg->set(
"role",
"user");
1850 Poco::JSON::Array::Ptr content = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
1851 Poco::JSON::Object::Ptr part = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1852 part->set(
"type",
"text");
1853 part->set(
"text",
text);
1855 msg->set(
"content", content);
1856 Poco::JSON::Array::Ptr messages = Poco::JSON::Array::Ptr(
new Poco::JSON::Array());
1858 Poco::JSON::Object::Ptr
result = Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
1860 result->set(
"messages", messages);
1864std::string callCoreTool(McpServer& server, std::string_view
name, Poco::JSON::Object::Ptr args) {
1865 return callTool(server, std::string(
name), std::move(args));
1879McpServer::McpServer() =
default;
1881McpServer::~McpServer() {
1884 std::lock_guard<std::mutex> lock(ioMu_);
1899 stdioQueue_.clear();
1900 listening_.store(
false);
1901 hasClient_.store(
false);
1907 for (
char&
c :
root) {
1908 if (
c ==
'\\')
c =
'/';
1910 while (!
root.empty() && (
root.back() ==
'/' ||
root.back() ==
'\\'))
root.pop_back();
1911 gameRoot_ = std::move(
root);
1917 Poco::Net::SocketAddress addr(
"127.0.0.1",
port);
1918 server_ = std::make_unique<Poco::Net::ServerSocket>(addr);
1919 server_->setBlocking(
false);
1920 const int bound =
static_cast<int>(server_->address().port());
1922 listening_.store(
true);
1923 initialized_ =
false;
1925 if (gameRoot_.empty())
setGameRoot(std::filesystem::current_path().string());
1935 listening_.store(
false);
1946 std::lock_guard<std::mutex> lock(ioMu_);
1947 stdioQueue_.clear();
1950 listening_.store(
true);
1952 initialized_ =
false;
1953 stdinClosed_.store(
false);
1956 hasClient_.store(
true);
1959 joinReader_ = (&in != &std::cin);
1961 stdioReader_ = std::thread([
this, &in]() {
1963 while (listening_.load() && std::getline(in,
line)) {
1964 if (!line.empty() && line.back() ==
'\r') line.pop_back();
1965 if (line.empty()) continue;
1967 std::lock_guard<std::mutex> lock(ioMu_);
1968 stdioQueue_.push_back(std::move(line));
1971 stdinClosed_.store(
true);
1972 hasClient_.store(
false);
1975 transport_.store(Transport::None);
1976 listening_.store(
false);
1977 hasClient_.store(
false);
1986void McpServer::stop() {
1987 listening_.store(
false);
1988 hasClient_.store(
false);
1989 if (stdioReader_.joinable()) {
1991 stdioReader_.join();
1993 stdioReader_.detach();
1996 std::lock_guard<std::mutex> lock(ioMu_);
2011 stdioQueue_.clear();
2014 transport_.store(Transport::None);
2015 initialized_ =
false;
2017 stdioOut_ =
nullptr;
2018 AiPanel::instance().setMcpPort(0);
2019 AiPanel::instance().setMcpConnected(
false);
2020 AiPanel::instance().setClientName({});
2023void McpServer::poll() {
2024 if (!listening_.load())
return;
2025 if (transport_.load() == Transport::Stdio) {
2026 std::vector<std::string> batch;
2028 std::lock_guard<std::mutex> lock(ioMu_);
2029 batch.swap(stdioQueue_);
2031 for (
const auto&
line : batch) handleMessage(
line);
2032 if (stdinClosed_.load() && batch.empty() && initialized_) {
2035 initialized_ =
false;
2039 runPendingVisionDump();
2042 acceptNonBlocking();
2046 runPendingVisionDump();
2049void McpServer::acceptNonBlocking() {
2050 if (!server_ || client_)
return;
2052 Poco::Net::SocketAddress clientAddr;
2053 Poco::Net::StreamSocket ss = server_->acceptConnection(clientAddr);
2054 ss.setBlocking(
true);
2055 ss.setReceiveTimeout(Poco::Timespan(0, 1000));
2056 client_ = std::make_unique<Poco::Net::StreamSocket>(ss);
2057 hasClient_.store(
true);
2061 initialized_ =
false;
2062 AiPanel::instance().setMcpConnected(
true);
2063 AiPanel::instance().addLog(
"system",
"mcp.accept",
"client connected");
2064 }
catch (
const Poco::TimeoutException&) {
2065 }
catch (
const Poco::Net::NetException&) {
2070bool McpServer::sendLine(
const std::string& json) {
2071 if (transport_.load() == Transport::Stdio) {
2072 std::lock_guard<std::mutex> lock(ioMu_);
2073 if (!stdioOut_)
return false;
2075 const std::string
frame = json +
"\n";
2076 (*stdioOut_) <<
frame;
2083 if (!client_)
return false;
2084 const std::string
frame = json +
"\n";
2086 const int sent = client_->sendBytes(
frame.data(),
static_cast<int>(
frame.size()));
2087 return sent ==
static_cast<int>(
frame.size());
2090 hasClient_.store(
false);
2091 AiPanel::instance().setMcpConnected(
false);
2096void McpServer::readAndDispatch() {
2097 if (!client_)
return;
2100 const int n = client_->receiveBytes(buf,
sizeof(buf));
2104 hasClient_.store(
false);
2105 AiPanel::instance().setMcpConnected(
false);
2106 AiPanel::instance().addLog(
"system",
"mcp.disconnect",
"client closed");
2112 recvBuf_.append(buf,
static_cast<size_t>(
n));
2113 }
catch (
const Poco::TimeoutException&) {
2115 }
catch (
const Poco::Net::NetException&) {
2117 hasClient_.store(
false);
2118 AiPanel::instance().setMcpConnected(
false);
2124 hasClient_.store(
false);
2125 AiPanel::instance().setMcpConnected(
false);
2130 const auto nl = recvBuf_.find(
'\n');
2131 if (nl == std::string::npos)
break;
2132 std::string
line = recvBuf_.substr(0, nl);
2133 recvBuf_.erase(0, nl + 1);
2134 if (!
line.empty() &&
line.back() ==
'\r')
line.pop_back();
2135 if (
line.empty())
continue;
2136 handleMessage(
line);
2140void McpServer::handleMessage(
const std::string& json) {
2142 Poco::JSON::Parser parser;
2143 auto var = parser.parse(json);
2144 auto obj = var.extract<Poco::JSON::Object::Ptr>();
2148 if (obj->has(
"method")) {
2150 method = obj->get(
"method").convert<std::string>();
2151 }
catch (
const Poco::Exception& e) {
2152 sendLine(makeError(
"null", -32600, std::string(
"bad method: ") + e.displayText()));
2156 const bool hasId = obj->has(
"id");
2157 Poco::Dynamic::Var idVar;
2158 if (hasId) idVar = obj->get(
"id");
2159 std::string idJson =
"null";
2161 if (hasId) idJson = idToJson(idVar);
2162 }
catch (
const Poco::Exception& e) {
2163 sendLine(makeError(
"null", -32600, std::string(
"bad id: ") + e.displayText()));
2168 if (
method ==
"notifications/initialized" ||
method ==
"initialized") {
2169 initialized_ =
true;
2170 AiPanel::instance().addLog(
"system",
"mcp.initialized",
"handshake complete");
2175 auto params = [&]() -> Poco::JSON::Object::Ptr {
2176 if (!obj->has(
"params"))
return Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
2178 return obj->getObject(
"params");
2180 return Poco::JSON::Object::Ptr(
new Poco::JSON::Object());
2184 if (
method ==
"initialize") {
2185 sendLine(handleInitialize(*
this, idJson,
params()));
2189 sendLine(makeResult(idJson,
"{}"));
2192 if (
method ==
"tools/list") {
2193 sendLine(handleToolsList(idJson));
2196 if (
method ==
"tools/call") {
2197 sendLine(handleToolsCall(*
this, idJson,
params()));
2200 if (
method ==
"resources/list") {
2201 sendLine(handleResourcesList(idJson));
2204 if (
method ==
"resources/read") {
2205 sendLine(handleResourcesRead(idJson,
params()));
2208 if (
method ==
"prompts/list") {
2209 sendLine(handlePromptsList(idJson));
2212 if (
method ==
"prompts/get") {
2213 sendLine(handlePromptsGet(idJson,
params()));
2217 sendLine(makeError(idJson, -32601,
"Method not found: " +
method));
2218 }
catch (
const Poco::Exception& e) {
2219 sendLine(makeError(
"null", -32700, std::string(
"Parse error: ") + e.displayText()));
2220 }
catch (
const std::exception& e) {
2221 sendLine(makeError(
"null", -32603, e.what()));
2223 sendLine(makeError(
"null", -32603,
"Internal error"));
ActionParameterOperation operation
std::vector< QuestEvent > pending
struct SQVM * HSQUIRRELVM
EnvironmentMetricContract contract
Runtime game-world Discover snapshot for MCP / Play Host.
Versioned JSON facade shared by scripting, MCP and scenario tooling.
const GltfImportRequest & request
wgpu::PopErrorScopeStatus status
std::array< float, 3 > position
Shared helpers for MCP tools that drive the embedded scene_director kit.
std::vector< std::string > mismatches
Named Agent task profiles that narrow the MCP tool surface.
std::unique_ptr< gpgpu::GpuBuffer > buffer
Versioned Play Host protocol for Agent pause / step / observe / capture.
std::weak_ptr< PrimitiveScene > scene
const eve::script::BindingContractRegistry & registry
脚本组件数据的持久化信封(方案文档实施顺序第 4 步 / J-3 的存档通路)。
ScriptProviderHandle provider
const SquirrelValueOptions & options
Audio control surface (provided by the audio module).
Module-neutral bridge from DevTools/MCP to the editor command protocol.
Declarative editor-host control (provided by the ui module).
Particle system query surface (provided by the particles module).
2D physics world query surface (provided by the physics module).
Module-neutral JSON bridge from DevTools/MCP to PixelWorld tooling.
Procedural generation query surface (provided by the procgen module).
Frame capture + camera + visible-entity inspection (graphics).
virtual Result< CaptureImageInfo > savePng(const std::string &path)=0
Capture the last presented frame and write a PNG.
virtual Result< Renderable3DInfo > inspectRenderable3D(std::uint32_t entityId, std::uint32_t generation)=0
Inspect one live Renderable3D using its complete ECS identity.
virtual RenderStatusInfo status() const =0
Status.
Scene graph query/mutation surface (provided by the scene module).
Semantic retained-UI automation provided by the ui module.
void addNote(std::string text)
std::string formatLog(size_t max=64) const
void setMcpPort(int port)
void addLog(std::string kind, std::string title, std::string detail={})
static AiPanel & instance()
void setMcpConnected(bool on)
void setClientName(std::string name)
static DebugAdapter & instance()
static Debugger & instance()
Embedded Model Context Protocol (MCP) server for AI-assisted game development.
void setGameRoot(std::string root)
Game / project directory hint for agents.
int listen(uint16_t port)
Bind TCP listen port (0 = ephemeral). Returns bound port or 0 on failure.
bool listenStdio(std::istream &in=std::cin, std::ostream &out=std::cout)
Switch to stdio transport (MCP stdio server). A reader thread pulls newline-delimited JSON from in in...
static McpServer & instance()
static RenderVision & instance()
void pollPending(eve::IRenderCapture *cap, const std::string &renderDataJson)
McpServer::poll hook: performs one pending dump when safe, clears flag.
std::string describe(eve::IRenderCapture *cap, const std::string &renderDataJson, bool fresh, const std::string &reason={})
Main-thread capture + vision describe. Returns the description text, or a string starting with "error...
std::string currentPoseJson()
当前激活相机位姿 JSON(eye/target/fov/viewport)。
std::string visibleEntitiesJson(const glm::vec3 *eye=nullptr, const glm::vec3 *target=nullptr, float fov=0.f)
生成当前视锥内可见实体的结构化 JSON: { camera, viewport, entities:[ { id, asset, world_aabb:{min,...
InspectCapture capture(const std::string &outDir={}, const std::string &tag="frame", const std::vector< std::string > &buffers={})
锁定当前相机 → 捕获渲染帧 PNG → 立刻导出配套可见实体几何 JSON。 两者共享同一相机位姿,杜绝图片与实体数据错位。 outDir 为空时使用缓存目录。返回文件路径与图像尺寸。 buffers...
static SceneInspect & instance()
bool setCameraPose(const glm::vec3 &eye, const glm::vec3 &rotYawPitch, float fov=0.f)
以 pos + 欧拉角 rot 设置相机位姿。 rot = [yawDeg, pitchDeg](与 firstperson 约定一致,Y-up)。 fov <= 0 时保持当前 FOV。
static std::vector< InspectView > generateViews(const glm::vec3 ¢er, float fov=60.f)
围绕 center 自动生成一组标准化巡检机位:
static Snapshot & instance()
const BindingContract * find(std::string_view key) const noexcept
Finds a binding contract.
std::vector< BindingSearchHit > search(std::string_view query, std::string_view moduleFilter={}, std::string_view classFilter={}, size_t limit=20) const
Ranked substring/token search over keys, classes, methods and documentation ids.
const BindingContract * findMethod(std::string_view method) const noexcept
Finds a uniquely named method.
bool ensureSceneDirectorInstalled(HSQUIRRELVM vm, std::string *err)
Convenience overload: allow heavy install immediately (tests / explicit install tool).
bool getArgBool(Poco::JSON::Object::Ptr args, const char *key, bool def=false)
Boolean argument, or def when absent or not convertible.
int scriptToolCount()
Number of exported tools (for eve_status).
std::size_t mcpCallgraphStackDepth()
float getArgFloat(Poco::JSON::Object::Ptr args, const char *key, float def=0.f)
Floating-point argument, or def when absent or not convertible.
Result< std::string > executePlayJson(std::string_view requestJson)
Parse, execute and serialize one Play JSON request against the live engine.
bool mcpToolAllowed(std::string_view name)
Whether name is visible under the current env filter.
std::string mcpJsonEscape(const std::string &value)
Escape a raw string for embedding inside a JSON string literal.
void resetMcpFrameCapture()
Main-thread disconnect cleanup; workers observe cancellation before publishing files.
Result< std::string > sceneLiteral(const Poco::Dynamic::Var &value, int depth=0)
Encode owning JSON data as a Squirrel literal without losing pointer containers or precision.
Poco::Dynamic::Var getArgVar(Poco::JSON::Object::Ptr args, const char *key)
Raw JSON value of key, or an empty Var when absent.
std::string callScriptTool(const std::string &name, Poco::JSON::Object::Ptr args)
Invoke one exported tool.
std::size_t mcpCallgraphEvents()
void flushPendingSceneDirectorInstall(HSQUIRRELVM vm)
Run a deferred scene_director install on the game/MCP poll thread.
std::string mcpStringify(const Poco::Dynamic::Var &value)
Compact single-line JSON text for a newline-framed MCP payload.
std::string textContentResult(const std::string &text, bool isError=false)
MCP tools/call result object carrying one text content item.
void resetMcpActionGuide()
Clear the process-local guide-pack session used by get/set.
const std::string & mcpLastReport()
Result< Value > liveGameWorldSnapshot()
Build the Discover snapshot against the live engine.
bool mcpDevAttached()
Thin hooks so McpServer.cpp need not include DevTool.hpp (avoids a cycle).
Poco::JSON::Object::Ptr crashLogSummary()
Summary of the persistent crash/error log (eve.log).
std::string sceneDirectorToolError(const std::string &name, const std::string &err)
Format a scene-director tool failure.
bool runMcpVmSnippet(HSQUIRRELVM vm, const std::string &source, std::string *err)
Compile and run a transient MCP snippet (no return value). @thread Game-loop / MCP poll thread with a...
std::string scriptToolSchemas()
Comma-free MCP tool schema fragments for every exported tool.
Poco::JSON::Object::Ptr mcpFailureObject(const std::string &error, const std::string &hint={}, bool retryable=false, const std::vector< std::string > &nextTools={})
Structured tool failure object for agent self-correction.
void pollMcpInputBatches()
Advance pending wait/capture batches once per game-loop poll. @thread MCP poll / game-loop thread onl...
std::string filterMcpToolsBody(std::string_view toolsBody)
Filter a JSON tools array body in place (objects joined by commas).
std::string mcpToolFilteredPayload(std::string_view name)
Human-readable rejection payload fields when a call is filtered out.
void mcpFilterNoteCall(bool allowed, std::size_t resultBytes, bool offeredEscalate)
Record a tools/call attempt for proxy metrics.
int getArgInt(Poco::JSON::Object::Ptr args, const char *key, int def=0)
Integer argument, or def when absent or not convertible.
bool isScriptTool(const std::string &name)
Whether name is exported by the project script registry.
std::string getArgString(Poco::JSON::Object::Ptr args, const char *key, const std::string &def={})
String argument, or def when absent or not convertible.
std::string_view mcpCoreToolSchemas()
Borrow legacy core tool schemas; process lifetime, synchronized first initialization....
const McpToolFamilyCatalog & compiledMcpToolCatalog()
Build the process-immortal compiled catalogue once, then borrow it until exit. @lifetime Survives sta...
@ Snapshot
Script state was restored while the debugger was already paused.
std::string callSceneDirectorReturn(HSQUIRRELVM vm, const std::string &snippet, std::string *err)
Compile+run a snippet that returns a value; serialize it as JSON.
Status invalid(const char *message)
ForceVector add(ForceVector a, ForceVector b)
ShapeState * child(const JPH::Body &body, const JPH::SubShapeID &id)
Resolves a native child record for a synchronous callback or query. @ownership Borrowed from the worl...
Result< int > publish(Heightmap &target, std::vector< float > candidate)
Publish.
const BindingContractRegistry & generatedBindingContracts()
Process-wide generated Binding Contracts for this linked engine build.
EVENGINE_API_FOUNDATION Result< std::string > scriptComponentStatesJson()
引擎侧脚本组件数据的**工具视图**(MCP eve_script_components 与诊断用)。
Result< std::string > executeGameplayControlJson(std::string_view requestJson)
Parse, execute and serialize one gameplay-control JSON request.
Pixel size reported by a successful frame/image capture.
Ray-cast result (value type).
Render surface / frame state snapshot (value type).
Serializable snapshot of one scene node (value type, no scene types).
static T & get()
Returns the process-lifetime instance.
Complete script-facing contract for a native function or method.