diff --git a/src/slic3r/plugin/PythonPluginBridge.cpp b/src/slic3r/plugin/PythonPluginBridge.cpp index 501ffc7b4f..d8430488ce 100644 --- a/src/slic3r/plugin/PythonPluginBridge.cpp +++ b/src/slic3r/plugin/PythonPluginBridge.cpp @@ -754,13 +754,19 @@ not a capability.)pbdoc"); pending.end()); pending.push_back(std::move(op)); }, - py::arg("name"), py::arg("description"), py::arg("schema") = py::none(), py::arg("handler"), py::arg("changes") = true, + // handler is required, and the callable check above refuses a missing one. It defaults to None only so that + // the signature stays one Python can declare while schema keeps its default, which lets a caller pass the + // handler by keyword alone. + py::arg("name"), py::arg("description"), py::arg("schema") = py::none(), py::arg("handler") = py::none(), + py::arg("changes") = true, R"pbdoc(Offer an operation to AI agents and scripts while OrcaSlicer loads your module. The person is asked whether to allow each operation; an allowed one is reached as -"plugin.." through api_call and orca.host.tools.call. handler(args) receives the -arguments as a dict, validated against schema (a JSON Schema object), runs under the plugin's identity -and permissions, and returns a JSON value. changes=False marks an operation that only reads.)pbdoc"); +"plugin.." through api_call and orca.host.tools.call. handler, which is required, is +called as handler(args) with the arguments as a dict, validated against schema (a JSON Schema object, +or None for an operation that takes no arguments); it runs under the plugin's identity and permissions +and returns a JSON value. Pass handler by position after schema, or as handler= on its own. +changes=False marks an operation that only reads.)pbdoc"); m.def( "request_permissions", diff --git a/tests/slic3rutils/test_mcp_tools.cpp b/tests/slic3rutils/test_mcp_tools.cpp index e67bae53aa..4a73a5a2c4 100644 --- a/tests/slic3rutils/test_mcp_tools.cpp +++ b/tests/slic3rutils/test_mcp_tools.cpp @@ -130,6 +130,11 @@ TEST_CASE("python_api's reference covers the orca package with constructors and const json& success = by_name["orca.ExecutionResult.success"]; CHECK(success["signature"].get().rfind("success(message: str", 0) == 0); CHECK(success["doc"].get().find("Success result") != std::string::npos); + // No required parameter follows one with a default, which Python could not declare; the handler may + // still be passed by keyword alone. + REQUIRE(by_name.count("orca.register_operation") == 1); + CHECK(by_name["orca.register_operation"]["signature"].get().find("schema: object = None, handler: object = None") != + std::string::npos); CHECK(rank_python_api(reference, "mesh normals")[0]["name"] == "orca.host.TriangleMesh.face_normals"); }