Skip to content

Commit 1c88585

Browse files
more serialized classes
1 parent d2039b1 commit 1c88585

File tree

4 files changed

+147
-2
lines changed

4 files changed

+147
-2
lines changed

basic_test.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class basic_test : public CppUnit::TestFixture {
1717
CPPUNIT_TEST( testEmpty );
1818
CPPUNIT_TEST( testJsonWithVariant );
1919
CPPUNIT_TEST( testModelSerialization );
20+
CPPUNIT_TEST( toolSerializationTest );
2021
CPPUNIT_TEST_SUITE_END();
2122
public:
2223
void testEmpty () { int i=5; CPPUNIT_ASSERT(i==5); }
@@ -26,7 +27,7 @@ class basic_test : public CppUnit::TestFixture {
2627
ns::ComplexStruct comp{ "x" };
2728
json r = comp;
2829
std::cout << r.dump() << std::endl;
29-
ns::ComplexStruct p2 = r.template get<ns::ComplexStruct>();
30+
ns::ComplexStruct p2 = r.template get<ns::ComplexStruct>();r.template get<ns::ComplexStruct>();
3031

3132
CPPUNIT_ASSERT("x" == std::get<std::string> (p2.id) );
3233
CPPUNIT_ASSERT(r.at("id") == "x");
@@ -65,9 +66,25 @@ class basic_test : public CppUnit::TestFixture {
6566
a3a::request_json_params p2 = j.template get<a3a::request_json_params>();
6667
std::cout << "params " << p2.params << std::endl;
6768
std::cout << "ddf " << p2.jsonrpc.value() << std::endl;
68-
//std::cout << p2.params << std::endl;
6969
}
70+
}
7071

72+
void toolSerializationTest(){
73+
using json = nlohmann::json;
74+
a3a::tool t;
75+
t = json::parse(R"({"name": "calculate_sum",
76+
"description": "Add two numbers together",
77+
"inputSchema": {
78+
"type": "object",
79+
"properties": {
80+
"a": { "type": "number" },
81+
"b": { "type": "number" }
82+
},
83+
"required": ["a", "b"]
84+
}
85+
})");
86+
CPPUNIT_ASSERT(t.name == "calculate_sum");
87+
std::cout << t.inputSchema.properties << std::endl;
7188
}
7289
};
7390
CPPUNIT_TEST_SUITE_REGISTRATION( basic_test );

mcpplusplus.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <vector>
22
#include "request.h"
3+
#include "mcppp.hpp"
34
#include <seastar/core/seastar.hh>
45
#include <seastar/core/future-util.hh>
56
#include <seastar/core/app-template.hh>
@@ -22,13 +23,25 @@ using namespace seastar::httpd;
2223
using namespace std;
2324
using namespace a3a;
2425

26+
27+
2528
vector<a3a::resource> list_resources(){
2629
a3a::resource r1 = { "file:///hobbies.txt", "my-hobbies", "a list of my hobbies one per line."};
2730
vector<a3a::resource> result;
2831
result.push_back(r1);
2932
return result;
3033
}
3134

35+
a3a::resource_read_response read_resource(){
36+
a3a::resource_read r1;
37+
r1.uri = "file:///hobbies.txt";
38+
r1.text = "java\nc++\nkarate";
39+
a3a::resource_read_response resp;
40+
resp.contents = std::vector<a3a::resource_read>();
41+
resp.contents.push_back(r1);
42+
return resp;
43+
}
44+
3245
void set_routes(routes& r) {
3346
function_handler* h3 = new function_handler([](const_req req) {
3447
using json = nlohmann::json;
@@ -41,6 +54,7 @@ void set_routes(routes& r) {
4154
int main(int argc, char** argv) {
4255
app_template app;
4356
return app.run(argc, argv, [] () -> future<int> {
57+
//nice example here https://github.com/scylladb/seastar/blob/master/apps/httpd/main.cc
4458
auto server = new http_server("mcpplusplus");
4559
set_routes(server->_routes);
4660
co_await server->listen(seastar::make_ipv4_address({1235}));

mcppp.hpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef a3a_mcppp_hpp
2+
#define a3a_mcppp_hpp
3+
4+
#include <seastar/core/seastar.hh>
5+
#include <seastar/core/future-util.hh>
6+
#include <seastar/core/app-template.hh>
7+
#include <seastar/http/routes.hh>
8+
#include <seastar/http/request.hh>
9+
#include <seastar/http/function_handlers.hh>
10+
#include <seastar/http/httpd.hh>
11+
#include <seastar/core/sleep.hh>
12+
#include <seastar/coroutine/all.hh>
13+
14+
namespace a3a {
15+
16+
using namespace std;
17+
using namespace seastar;
18+
19+
class mcppp_session{
20+
public:
21+
string id;
22+
};
23+
class mcppp {
24+
private:
25+
std::map<string, mcppp_session> data;
26+
};
27+
28+
class sharded_mcppp {
29+
public:
30+
sharded_mcppp(seastar::distributed<mcppp>& peers) :
31+
_peers(peers) {
32+
33+
}
34+
private:
35+
seastar::distributed<mcppp>& _peers;
36+
};
37+
38+
}
39+
#endif

request.h

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,75 @@
33
#include <string>
44
#include "jsonifyext.hpp"
55

6+
67
namespace a3a {
8+
79
using namespace std;
810
using namespace nlohmann;
911

12+
string TOOLS_LIST = "tools/list";
13+
string TOOLS_CALL = "tools/call";
14+
15+
class annotations_item {
16+
public:
17+
optional<string> title;
18+
optional<bool> readOnlyHint;
19+
optional<bool> destructiveHint;
20+
optional<bool> idempotentHint;
21+
optional<bool> openWorldHint;
22+
};
23+
NLOHMANN_JSONIFY_ALL_THINGS(annotations_item, readOnlyHint, destructiveHint, idempotentHint, openWorldHint);
24+
25+
26+
class input_schema {
27+
public:
28+
string type;
29+
json properties;
30+
vector<string> required;
31+
};
32+
NLOHMANN_JSONIFY_ALL_THINGS(input_schema, type, properties, required);
33+
34+
35+
class tool {
36+
public:
37+
string name;
38+
optional<string> description;
39+
input_schema inputSchema;
40+
optional<annotations_item> annotations;
41+
};
42+
NLOHMANN_JSONIFY_ALL_THINGS(tool, name, description, inputSchema, annotations);
43+
44+
class call_tool_result {
45+
46+
bool isError;
47+
};
48+
49+
class implementation {
50+
public:
51+
string name;
52+
string version;
53+
};
54+
//changed class name to not clash with propert
55+
class sampling_item{
56+
public:
57+
};
58+
class root_capabilities {
59+
public:
60+
bool listChanged;
61+
};
62+
class client_capabilities{
63+
public:
64+
nlohmann::json experimental;
65+
root_capabilities roots;
66+
sampling_item sampling;
67+
};
68+
class initialize_reqest {
69+
public:
70+
string protocolVersion;
71+
client_capabilities capabilities;
72+
implementation clientInfo;
73+
};
74+
1075
class request{
1176
public:
1277
std::optional<string> jsonrpc;
@@ -38,6 +103,7 @@ namespace a3a {
38103
};
39104
NLOHMANN_JSONIFY_ALL_THINGS(resource, uri, name, description, mimeType);
40105

106+
41107
class resource_read {
42108
public:
43109
string uri;
@@ -46,5 +112,14 @@ namespace a3a {
46112
optional<string> blob; // For binary resources (base64 encoded)
47113
};
48114
NLOHMANN_JSONIFY_ALL_THINGS(resource_read, uri, mimeType, text, blob);
115+
116+
117+
class resource_read_response {
118+
public:
119+
std::vector<resource_read> contents;
120+
121+
};
122+
NLOHMANN_JSONIFY_ALL_THINGS(resource_read_response, contents);
123+
49124
}
50125
#endif

0 commit comments

Comments
 (0)