Fix JSON-RPC ID type

Change id parameter from string to json& to support JSON-RPC 2.0 spec (id can be string, number, or null)
pull/5310/head
Rahim Kanji 3 months ago
parent a15be695e0
commit 4a858521c9

@ -149,7 +149,7 @@ const std::shared_ptr<http_response> MCP_JSONRPC_Resource::render_OPTIONS(
std::string MCP_JSONRPC_Resource::create_jsonrpc_response(
const std::string& result,
const std::string& id
const json& id
) {
json j;
j["jsonrpc"] = "2.0";
@ -161,7 +161,7 @@ std::string MCP_JSONRPC_Resource::create_jsonrpc_response(
std::string MCP_JSONRPC_Resource::create_jsonrpc_error(
int code,
const std::string& message,
const std::string& id
const json& id
) {
json j;
j["jsonrpc"] = "2.0";
@ -232,13 +232,9 @@ std::shared_ptr<http_response> MCP_JSONRPC_Resource::handle_jsonrpc_request(
}
// Get request ID (optional but recommended)
std::string req_id = "";
json req_id = nullptr;
if (req_json.contains("id")) {
if (req_json["id"].is_string()) {
req_id = req_json["id"].get<std::string>();
} else if (req_json["id"].is_number()) {
req_id = std::to_string(req_json["id"].get<int>());
}
req_id = req_json["id"];
}
// Get method name

Loading…
Cancel
Save