OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-cogserver commits / ff1c437

Inline header function; avoid include of jsoncpp
ff1c43704def42ebede468931def0891da25d5a0
by Linas Vepstas <linasvepstas@gmail.com> · 2025-12-17T09:27:11.000Z

Changed files (3) +14 -44

opencog/cogserver/mcp-eval/McpEval.cc +7 -13
……@@ -25,11 +25,7 @@
2525#include <ctime>
2626#include <algorithm>
2727#include <fstream>
28
29#if HAVE_MCP
3028#include <json/json.h>
31#include <sstream>
32#endif // HAVE_MCP
3329
3430#include <opencog/util/Logger.h>
3531#include <opencog/cogserver/mcp-tools/McpPlugin.h>
……@@ -47,6 +43,13 @@ McpEval::McpEval(const AtomSpacePtr& asp)
4743 _done = false;
4844}
4945
46// Helper function to convert Json::Value to compact string
47static std::string json_to_string(const Json::Value& value) {
48 Json::StreamWriterBuilder builder;
49 builder["indentation"] = "";
50 return Json::writeString(builder, value);
51}
52
5053// Helper function to publish a resource file as MCP resource response
5154static bool publish_resource(const std::string& doc_base,
5255 const std::string& uri,
……@@ -87,7 +90,6 @@ void McpEval::eval_expr(const std::string &expr)
8790 if (0 == expr.size()) return;
8891 if (0 == expr.compare("\n")) return;
8992
90#if HAVE_MCP
9193 logger().debug("[McpEval] received %s", expr.c_str());
9294 try
9395 {
……@@ -395,10 +397,6 @@ void McpEval::eval_expr(const std::string &expr)
395397 _result = json_to_string(error_response) + "\n";
396398 _done = true;
397399 }
398#else
399 _result = "MCP support not compiled in\n";
400 _done = true;
401#endif //HAVE_MCP
402400}
403401
404402std::string McpEval::poll_result()
……@@ -435,7 +433,6 @@ void McpEval::interrupt(void)
435433 */
436434void McpEval::register_plugin(std::shared_ptr<McpPlugin> plugin)
437435{
438#if HAVE_MCP
439436 if (!plugin) return;
440437
441438 _plugins.push_back(plugin);
……@@ -453,7 +450,6 @@ void McpEval::register_plugin(std::shared_ptr<McpPlugin> plugin)
453450 _tool_to_plugin[tool_name] = plugin;
454451 }
455452 }
456#endif // HAVE_MCP
457453}
458454
459455/**
……@@ -461,7 +457,6 @@ void McpEval::register_plugin(std::shared_ptr<McpPlugin> plugin)
461457 */
462458void McpEval::unregister_plugin(std::shared_ptr<McpPlugin> plugin)
463459{
464#if HAVE_MCP
465460 if (!plugin) return;
466461
467462 // Remove from plugins list
……@@ -479,7 +474,6 @@ void McpEval::unregister_plugin(std::shared_ptr<McpPlugin> plugin)
479474 ++it;
480475 }
481476 }
482#endif // HAVE_MCP
483477}
484478
485479/* ============================================================== */
opencog/cogserver/mcp-tools/McpPlugEcho.cc +7 -12
……@@ -22,19 +22,21 @@
2222
2323#include <chrono>
2424#include <ctime>
25
26#if HAVE_MCP
2725#include <json/json.h>
28#include <sstream>
29#endif
3026
3127#include "McpPlugEcho.h"
3228
3329using namespace opencog;
3430
31// Helper function to convert Json::Value to compact string
32static std::string json_to_string(const Json::Value& value) {
33 Json::StreamWriterBuilder builder;
34 builder["indentation"] = "";
35 return Json::writeString(builder, value);
36}
37
3538std::string McpPlugEcho::get_tool_descriptions() const
3639{
37#if HAVE_MCP
3840 Json::Value tools(Json::arrayValue);
3941
4042 // Echo tool description
……@@ -56,15 +58,11 @@ std::string McpPlugEcho::get_tool_descriptions() const
5658 tools.append(time_tool);
5759
5860 return json_to_string(tools);
59#else
60 return "[]";
61#endif
6261}
6362
6463std::string McpPlugEcho::invoke_tool(const std::string& tool_name,
6564 const std::string& arguments) const
6665{
67#if HAVE_MCP
6866 Json::Value response;
6967
7068 try {
……@@ -102,7 +100,4 @@ std::string McpPlugEcho::invoke_tool(const std::string& tool_name,
102100 }
103101
104102 return json_to_string(response);
105#else
106 return "{\"error\":{\"code\":-32601,\"message\":\"MCP not compiled\"}}";
107#endif
108103}
opencog/cogserver/mcp-tools/McpPlugEcho.h +0 -19
……@@ -56,23 +56,4 @@ public:
5656
5757} // namespace opencog
5858
59#if HAVE_MCP
60#include <json/json.h>
61#include <sstream>
62#include <memory>
63
64// Helper function to convert Json::Value to string
65static inline std::string json_to_string(const Json::Value& value) {
66 static Json::StreamWriterBuilder builder = []() {
67 Json::StreamWriterBuilder b;
68 b["indentation"] = ""; // Compact output (no newlines/indentation)
69 return b;
70 }();
71 std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
72 std::ostringstream oss;
73 writer->write(value, &oss);
74 return oss.str();
75}
76#endif // HAVE_MCP
77
7859#endif // _OPENCOG_MCP_PLUG_ECHO_H