Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/website-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
-DSOURCEMETA_CORE_JSONPOINTER:BOOL=OFF
-DSOURCEMETA_CORE_YAML:BOOL=OFF
-DSOURCEMETA_CORE_JSONRPC:BOOL=OFF
-DSOURCEMETA_CORE_MCP:BOOL=OFF
-DSOURCEMETA_CORE_SEMVER:BOOL=OFF
-DSOURCEMETA_CORE_GZIP:BOOL=OFF
-DSOURCEMETA_CORE_HTML:BOOL=OFF
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/website-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
-DSOURCEMETA_CORE_JSONPOINTER:BOOL=OFF
-DSOURCEMETA_CORE_YAML:BOOL=OFF
-DSOURCEMETA_CORE_JSONRPC:BOOL=OFF
-DSOURCEMETA_CORE_MCP:BOOL=OFF
-DSOURCEMETA_CORE_SEMVER:BOOL=OFF
-DSOURCEMETA_CORE_GZIP:BOOL=OFF
-DSOURCEMETA_CORE_HTML:BOOL=OFF
Expand Down
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ option(SOURCEMETA_CORE_JSONPOINTER "Build the Sourcemeta Core JSON Pointer libra
option(SOURCEMETA_CORE_JSONL "Build the Sourcemeta Core JSONL library" ON)
option(SOURCEMETA_CORE_YAML "Build the Sourcemeta Core YAML library" ON)
option(SOURCEMETA_CORE_JSONRPC "Build the Sourcemeta Core JSON-RPC library" ON)
option(SOURCEMETA_CORE_MCP "Build the Sourcemeta Core MCP library" ON)
option(SOURCEMETA_CORE_SEMVER "Build the Sourcemeta Core SemVer library" ON)
option(SOURCEMETA_CORE_GZIP "Build the Sourcemeta Core GZIP library" ON)
option(SOURCEMETA_CORE_HTML "Build the Sourcemeta Core HTML library" ON)
Expand Down Expand Up @@ -168,6 +169,10 @@ if(SOURCEMETA_CORE_JSONRPC)
add_subdirectory(src/core/jsonrpc)
endif()

if(SOURCEMETA_CORE_MCP)
add_subdirectory(src/core/mcp)
endif()

if(SOURCEMETA_CORE_SEMVER)
add_subdirectory(src/core/semver)
endif()
Expand Down Expand Up @@ -304,6 +309,10 @@ if(SOURCEMETA_CORE_TESTS)
add_subdirectory(test/jsonrpc)
endif()

if(SOURCEMETA_CORE_MCP)
add_subdirectory(test/mcp)
endif()

if(SOURCEMETA_CORE_SEMVER)
add_subdirectory(test/semver)
endif()
Expand Down
9 changes: 9 additions & 0 deletions config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if(NOT SOURCEMETA_CORE_COMPONENTS)
list(APPEND SOURCEMETA_CORE_COMPONENTS jsonpointer)
list(APPEND SOURCEMETA_CORE_COMPONENTS yaml)
list(APPEND SOURCEMETA_CORE_COMPONENTS jsonrpc)
list(APPEND SOURCEMETA_CORE_COMPONENTS mcp)
list(APPEND SOURCEMETA_CORE_COMPONENTS semver)
list(APPEND SOURCEMETA_CORE_COMPONENTS gzip)
list(APPEND SOURCEMETA_CORE_COMPONENTS html)
Expand Down Expand Up @@ -120,6 +121,14 @@ foreach(component ${SOURCEMETA_CORE_COMPONENTS})
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_unicode.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_json.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_jsonrpc.cmake")
elseif(component STREQUAL "mcp")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_preprocessor.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_numeric.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_io.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_unicode.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_json.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_jsonrpc.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_mcp.cmake")
elseif(component STREQUAL "semver")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_preprocessor.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_semver.cmake")
Expand Down
9 changes: 4 additions & 5 deletions src/core/jsonrpc/include/sourcemeta/core/jsonrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

#include <sourcemeta/core/json.h>

#include <cstdint> // std::int64_t
#include <optional> // std::optional, std::nullopt
#include <string_view> // std::string_view
#include <cstdint> // std::int64_t
#include <optional> // std::optional, std::nullopt

/// @defgroup jsonrpc JSON-RPC
/// @brief An implementation of the JSON-RPC 2.0 specification.
Expand Down Expand Up @@ -118,7 +117,7 @@ auto jsonrpc_is_request(const sourcemeta::core::JSON &request) -> bool;
/// assert(sourcemeta::core::jsonrpc_method(request) == "ping");
/// ```
SOURCEMETA_CORE_JSONRPC_EXPORT
auto jsonrpc_method(const sourcemeta::core::JSON &request) -> std::string_view;
auto jsonrpc_method(const sourcemeta::core::JSON &request) -> JSON::StringView;

/// @ingroup jsonrpc
/// Extract the params from a JSON-RPC 2.0 envelope, or `nullptr` when the
Expand Down Expand Up @@ -218,7 +217,7 @@ auto jsonrpc_make_success_empty(const sourcemeta::core::JSON &identifier)
/// ```
SOURCEMETA_CORE_JSONRPC_EXPORT
auto jsonrpc_make_error(const sourcemeta::core::JSON *identifier,
const std::int64_t code, const std::string_view message,
const std::int64_t code, const JSON::StringView message,
std::optional<sourcemeta::core::JSON> data =
std::nullopt) -> sourcemeta::core::JSON;

Expand Down
38 changes: 15 additions & 23 deletions src/core/jsonrpc/jsonrpc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

#include <sourcemeta/core/json.h>

#include <cstdint> // std::int64_t
#include <optional> // std::optional, std::nullopt
#include <string> // std::string
#include <string_view> // std::string_view
#include <utility> // std::move
#include <cstdint> // std::int64_t
#include <optional> // std::optional, std::nullopt
#include <utility> // std::move

namespace {

Expand Down Expand Up @@ -66,7 +64,7 @@ auto jsonrpc_is_request(const sourcemeta::core::JSON &request) -> bool {
return method_field != nullptr && method_field->is_string();
}

auto jsonrpc_method(const sourcemeta::core::JSON &request) -> std::string_view {
auto jsonrpc_method(const sourcemeta::core::JSON &request) -> JSON::StringView {
if (!request.is_object()) {
return {};
}
Expand Down Expand Up @@ -113,13 +111,11 @@ auto jsonrpc_make_success(const sourcemeta::core::JSON &identifier,
sourcemeta::core::JSON result)
-> sourcemeta::core::JSON {
auto envelope{sourcemeta::core::JSON::make_object()};
envelope.assign_assume_new(std::string{"jsonrpc"},
sourcemeta::core::JSON{"2.0"},
envelope.assign_assume_new("jsonrpc", sourcemeta::core::JSON{"2.0"},
JSONRPC_HASH_JSONRPC);
envelope.assign_assume_new(
std::string{"id"}, sourcemeta::core::JSON{identifier}, JSONRPC_HASH_ID);
envelope.assign_assume_new(std::string{"result"}, std::move(result),
JSONRPC_HASH_RESULT);
envelope.assign_assume_new("id", sourcemeta::core::JSON{identifier},
JSONRPC_HASH_ID);
envelope.assign_assume_new("result", std::move(result), JSONRPC_HASH_RESULT);
return envelope;
}

Expand All @@ -130,30 +126,26 @@ auto jsonrpc_make_success_empty(const sourcemeta::core::JSON &identifier)
}

auto jsonrpc_make_error(const sourcemeta::core::JSON *identifier,
const std::int64_t code, const std::string_view message,
const std::int64_t code, const JSON::StringView message,
std::optional<sourcemeta::core::JSON> data)
-> sourcemeta::core::JSON {
auto envelope{sourcemeta::core::JSON::make_object()};
envelope.assign_assume_new(std::string{"jsonrpc"},
sourcemeta::core::JSON{"2.0"},
envelope.assign_assume_new("jsonrpc", sourcemeta::core::JSON{"2.0"},
JSONRPC_HASH_JSONRPC);
envelope.assign_assume_new(std::string{"id"},
envelope.assign_assume_new("id",
identifier != nullptr
? sourcemeta::core::JSON{*identifier}
: sourcemeta::core::JSON{nullptr},
JSONRPC_HASH_ID);
auto error{sourcemeta::core::JSON::make_object()};
error.assign_assume_new(std::string{"code"}, sourcemeta::core::JSON{code},
error.assign_assume_new("code", sourcemeta::core::JSON{code},
JSONRPC_HASH_CODE);
error.assign_assume_new(std::string{"message"},
sourcemeta::core::JSON{message},
error.assign_assume_new("message", sourcemeta::core::JSON{message},
JSONRPC_HASH_MESSAGE);
if (data.has_value()) {
error.assign_assume_new(std::string{"data"}, std::move(data.value()),
JSONRPC_HASH_DATA);
error.assign_assume_new("data", std::move(data.value()), JSONRPC_HASH_DATA);
}
envelope.assign_assume_new(std::string{"error"}, std::move(error),
JSONRPC_HASH_ERROR);
envelope.assign_assume_new("error", std::move(error), JSONRPC_HASH_ERROR);
return envelope;
}

Expand Down
9 changes: 9 additions & 0 deletions src/core/mcp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME mcp
SOURCES mcp.cc)

target_link_libraries(sourcemeta_core_mcp PUBLIC sourcemeta::core::json)
target_link_libraries(sourcemeta_core_mcp PUBLIC sourcemeta::core::jsonrpc)

if(SOURCEMETA_CORE_INSTALL)
sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME mcp)
endif()
Loading
Loading