cxxmcp 1.1.6
C++ MCP SDK
Loading...
Searching...
No Matches
mcp::protocol::CustomRequest< Params, Result > Struct Template Reference

Generic typed MCP request for extension methods. More...

#include <custom_methods.hpp>

Public Member Functions

template<class Serializer >
JsonRpcRequest to_json_rpc (Serializer serializer) const
 Creates a JsonRpcRequest envelope from this typed request.
 
template<class Deserializer >
core::Result< Result > parse_response (const JsonRpcResponse &response, Deserializer deserializer) const
 Parses a JsonRpcResponse into a typed Result.
 

Public Attributes

std::string method
 Method name on the wire.
 
Params params
 Typed request parameters.
 
RequestId id
 Request id for JSON-RPC correlation.
 

Detailed Description

template<class Params, class Result>
struct mcp::protocol::CustomRequest< Params, Result >

Generic typed MCP request for extension methods.

Template Parameters
ParamsA struct with a to_json() free function.
ResultA struct with a from_json(const Json&) -> Result<T> free function.

Example:

struct MyParams { int value; };
Json my_params_to_json(const MyParams& p) { return {{"value", p.value}}; }
struct MyResult { int answer; };
Json my_result_to_json(const MyResult& r) {
return {{"answer", r.answer}};
}
core::Result<MyResult> my_result_from_json(const Json& j) { ... }
using MyRequest = CustomRequest<MyParams, MyResult>;
constexpr auto method = MyRequest::method_name("my/extension");
nlohmann::json Json
JSON value type used by all protocol DTOs.
Definition types.hpp:28
std::string method
Method name on the wire.
Definition custom_methods.hpp:45

Member Function Documentation

◆ parse_response()

template<class Params , class Result >
template<class Deserializer >
core::Result< Result > mcp::protocol::CustomRequest< Params, Result >::parse_response ( const JsonRpcResponse response,
Deserializer  deserializer 
) const
inline

Parses a JsonRpcResponse into a typed Result.

Parameters
responseJSON-RPC response to parse.
deserializerFunction that converts JSON to Result.

◆ to_json_rpc()

template<class Params , class Result >
template<class Serializer >
JsonRpcRequest mcp::protocol::CustomRequest< Params, Result >::to_json_rpc ( Serializer  serializer) const
inline

Creates a JsonRpcRequest envelope from this typed request.

Parameters
serializerFunction that converts Params to JSON.

The documentation for this struct was generated from the following file: