cxxmcp 1.1.6
C++ MCP SDK
Loading...
Searching...
No Matches
mcp::server::ClientPeer Class Reference

Non-owning handle for the client associated with a server session. More...

#include <peer.hpp>

Public Member Functions

 ClientPeer (Transport *transport=nullptr, std::string session_id={}, std::weak_ptr< void > transport_lifetime={}) noexcept
 Construct a peer from a borrowed transport pointer.
 
bool available () const noexcept
 Report whether this peer has a transport to send through.
 
bool supports_roots () const noexcept
 Report whether the client advertised roots/list support.
 
bool supports_sampling_tools () const noexcept
 Report whether the client advertised sampling support.
 
bool supports_elicitation_form () const noexcept
 Report whether the client advertised form elicitation support.
 
bool supports_elicitation_url () const noexcept
 Report whether the client advertised URL elicitation support.
 
bool supports_elicitation () const noexcept
 Report whether the client supports any elicitation mode.
 
bool supports_task_list () const noexcept
 Report whether the client advertised task listing support.
 
bool supports_task_cancel () const noexcept
 Report whether the client advertised task cancellation support.
 
bool supports_tasks () const noexcept
 Report whether the client advertised any task support.
 
core::Result< core::Unitnotify_cancelled (protocol::RequestId request_id, std::string reason={}) const
 Notify the client that a request was cancelled.
 
RequestHandle< protocol::Jsonrequest_async (std::string method, protocol::Json params=protocol::Json::object(), RequestOptions options={}) const
 Send a raw JSON-RPC request to the client and return a handle.
 
core::Result< protocol::Jsonrequest (std::string method, protocol::Json params=protocol::Json::object()) const
 Send a raw JSON-RPC request to the client.
 
core::Result< protocol::RootsListResultlist_roots () const
 Request the client's root list.
 
RequestHandle< protocol::RootsListResultlist_roots_async (RequestOptions options={}) const
 Request the client's root list asynchronously.
 
core::Result< protocol::CreateMessageResultcreate_message (const protocol::CreateMessageParams &params) const
 Ask the client to create a sampled message.
 
RequestHandle< protocol::CreateMessageResultcreate_message_async (const protocol::CreateMessageParams &params, RequestOptions options={}) const
 Ask the client to create a sampled message asynchronously.
 
core::Result< protocol::CreateElicitationResultcreate_elicitation (const protocol::CreateElicitationRequestParam &params) const
 Ask the client to perform an elicitation flow.
 
RequestHandle< protocol::CreateElicitationResultcreate_elicitation_async (const protocol::CreateElicitationRequestParam &params, RequestOptions options={}) const
 Ask the client to perform an elicitation flow asynchronously.
 
template<class T >
core::Result< T > elicit (std::string message, RequestOptions options={}) const
 Ask the client for typed form input using SchemaTraits<T>.
 
template<class T >
core::Result< T > elicit (std::string message, protocol::ElicitationSchema schema, RequestOptions options={}) const
 Ask the client for typed form input using an explicit schema.
 
template<class T >
RequestHandle< T > elicit_async (std::string message, RequestOptions options={}) const
 Async typed form elicitation using SchemaTraits<T>.
 
template<class T >
RequestHandle< T > elicit_async (std::string message, protocol::ElicitationSchema schema, RequestOptions options={}) const
 Async typed form elicitation using an explicit schema.
 
core::Result< core::Unitelicit_url (std::string message, std::string elicitation_id, std::string url, RequestOptions options={}) const
 Ask the client to complete a URL-based elicitation flow.
 
RequestHandle< core::Unitelicit_url_async (std::string message, std::string elicitation_id, std::string url, RequestOptions options={}) const
 Async URL elicitation helper.
 
core::Result< std::vector< protocol::Task > > list_tasks () const
 Request one page of tasks from the client.
 
core::Result< std::vector< protocol::Task > > list_all_tasks () const
 Request all client task pages by following cursors.
 
core::Result< protocol::Taskget_task (std::string_view task_id) const
 Request a single task by id.
 
core::Result< protocol::Taskcancel_task (std::string_view task_id) const
 Request cancellation of a client task.
 
core::Result< protocol::Jsontask_result (std::string_view task_id) const
 Request the result payload for a completed client task.
 
core::Result< core::Unitnotify_elicitation_complete (std::string elicitation_id) const
 Notify the client that an elicitation flow has completed.
 

Detailed Description

Non-owning handle for the client associated with a server session.

ClientPeer wraps a borrowed Transport pointer from SessionContext. It is cheap to copy and does not extend the lifetime of either the transport or the underlying MCP session. Use available() before optional peer operations when the context may not have come from a live transport.

New code may prefer the SessionClient or ClientHandle aliases to avoid confusing this session-bound handle with the top-level mcp::ClientPeer.

Methods return core::Result and never throw intentionally. Transport failures, protocol error responses, unsupported client capabilities, and response deserialization failures are propagated as core::Error values.

Constructor & Destructor Documentation

◆ ClientPeer()

mcp::server::ClientPeer::ClientPeer ( Transport transport = nullptr,
std::string  session_id = {},
std::weak_ptr< void >  transport_lifetime = {} 
)
inlineexplicitnoexcept

Construct a peer from a borrowed transport pointer.

Parameters
transportTransport used for outbound messages; may be nullptr.
session_idSession identifier used for capability lookup.
transport_lifetimeLifetime token for the borrowed transport; when expired, the peer reports unavailable instead of using the pointer.

Member Function Documentation

◆ cancel_task()

core::Result< protocol::Task > mcp::server::ClientPeer::cancel_task ( std::string_view  task_id) const
inline

Request cancellation of a client task.

Parameters
task_idClient task identifier.
Returns
Parsed task state returned by the client, or a core::Error.

◆ create_elicitation()

core::Result< protocol::CreateElicitationResult > mcp::server::ClientPeer::create_elicitation ( const protocol::CreateElicitationRequestParam params) const
inline

Ask the client to perform an elicitation flow.

Parameters
paramsElicitation request parameters including mode.
Returns
Parsed elicitation result, or a core::Error when the requested mode is unsupported, delivery fails, the client returns an error, or the response cannot be parsed.

◆ create_message()

core::Result< protocol::CreateMessageResult > mcp::server::ClientPeer::create_message ( const protocol::CreateMessageParams params) const
inline

Ask the client to create a sampled message.

Parameters
paramsSampling request parameters.
Returns
Parsed sampling result, or a core::Error for unsupported capability, transport failure, protocol error, or parse failure.

◆ elicit()

template<class T >
core::Result< T > mcp::server::ClientPeer::elicit ( std::string  message,
RequestOptions  options = {} 
) const
inline

Ask the client for typed form input using SchemaTraits<T>.

Primitive T schemas are wrapped as a required value field. Object schemas generated by SchemaTraits<T> are used directly and decoded from the accepted content object.

◆ get_task()

core::Result< protocol::Task > mcp::server::ClientPeer::get_task ( std::string_view  task_id) const
inline

Request a single task by id.

Parameters
task_idClient task identifier.
Returns
Parsed task, or a core::Error from transport, protocol, or parsing.

◆ list_all_tasks()

core::Result< std::vector< protocol::Task > > mcp::server::ClientPeer::list_all_tasks ( ) const
inline

Request all client task pages by following cursors.

Returns
Aggregated tasks in server-observed page order, or the first core::Error encountered.

◆ list_roots()

core::Result< protocol::RootsListResult > mcp::server::ClientPeer::list_roots ( ) const
inline

Request the client's root list.

Returns
Parsed roots/list result, or a core::Error if the client did not advertise roots support, transport delivery fails, or parsing fails.

◆ list_tasks()

core::Result< std::vector< protocol::Task > > mcp::server::ClientPeer::list_tasks ( ) const
inline

Request one page of tasks from the client.

Returns
Tasks from the first returned page, or a core::Error from transport, protocol, or parsing.

◆ notify_elicitation_complete()

core::Result< core::Unit > mcp::server::ClientPeer::notify_elicitation_complete ( std::string  elicitation_id) const
inline

Notify the client that an elicitation flow has completed.

Parameters
elicitation_idIdentifier of the elicitation flow.
Returns
core::Unit on delivery, or a core::Error when the peer is unavailable or the transport cannot send the notification.

◆ request()

core::Result< protocol::Json > mcp::server::ClientPeer::request ( std::string  method,
protocol::Json  params = protocol::Json::object() 
) const
inline

Send a raw JSON-RPC request to the client.

Parameters
methodJSON-RPC method name.
paramsJSON-RPC params payload. Defaults to an empty object.
Returns
The response result payload, or a core::Error when the peer is unavailable, the transport fails, the response is an error, or the response has no result.
Note
On HTTP transports this may block until the client posts the correlated response. The generated request id is process-global.

◆ request_async()

RequestHandle< protocol::Json > mcp::server::ClientPeer::request_async ( std::string  method,
protocol::Json  params = protocol::Json::object(),
RequestOptions  options = {} 
) const
inline

Send a raw JSON-RPC request to the client and return a handle.

Parameters
methodJSON-RPC method name.
paramsJSON-RPC params payload. Defaults to an empty object.
optionsOptional timeout and metadata.
Returns
A handle that can await the response or send cancellation.

◆ task_result()

core::Result< protocol::Json > mcp::server::ClientPeer::task_result ( std::string_view  task_id) const
inline

Request the result payload for a completed client task.

Parameters
task_idClient task identifier.
Returns
Raw JSON result payload, or a core::Error.

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