16#include <condition_variable>
24#include <unordered_map>
42namespace mcp::client {
44struct HttpAuthChallenge;
45using HttpAuthRefreshHandler =
46 std::function<std::optional<std::string>(
const HttpAuthChallenge&)>;
60struct ClientHandlerInterface;
67 std::function<core::Result<protocol::JsonRpcResponse>(
111 (void)request_handler;
112 (void)notification_handler;
120 virtual void stop() noexcept {}
134#if defined(CXXMCP_ENABLE_HTTP)
137 struct StreamableHttpEndpoint {
146 std::uint16_t port = 80;
148 std::string path =
"/mcp";
150 std::unordered_map<std::string, std::string> headers;
155 std::optional<std::string> auth_header;
159 HttpAuthRefreshHandler auth_refresh_handler;
162 std::chrono::milliseconds timeout{30000};
175 std::unordered_map<std::string, std::string>
env;
184 std::function<void(std::string_view, std::string_view)>;
217 std::function<core::Result<protocol::RootsListResult>()>;
218 using RootsListRequestCancellationHandler =
225 std::function<core::Result<protocol::CreateMessageResult>(
227 using SamplingRequestCancellationHandler =
228 std::function<core::Result<protocol::CreateMessageResult>(
235 std::function<core::Result<protocol::CreateElicitationResult>(
237 using ElicitationRequestCancellationHandler =
238 std::function<core::Result<protocol::CreateElicitationResult>(
246 using CustomRequestCancellationHandler =
247 std::function<core::Result<protocol::Json>(
257#if defined(CXXMCP_ENABLE_HTTP)
261 static Client connect_streamable_http(StreamableHttpEndpoint endpoint);
266 static Client connect_streamable_http(std::string uri);
271 static Client connect_legacy_sse(StreamableHttpEndpoint endpoint);
276 static Client connect_legacy_sse(std::string uri);
287 explicit Client(std::unique_ptr<Transport> transport);
298 std::string client_version =
"0");
306 std::string client_version,
320 std::string reason = {});
329 std::optional<double> total = std::nullopt, std::string message = {});
353 std::string_view name,
372 std::string_view uri);
408 std::string_view name,
420 std::string_view prompt_name, std::string_view argument_name,
421 std::string current_value,
427 std::string_view uri_template, std::string_view argument_name,
428 std::string current_value,
433 std::string_view prompt_name, std::string_view argument_name,
434 std::string current_value,
439 std::string_view uri_template, std::string_view argument_name,
440 std::string current_value,
507 std::string method,
protocol::Json params = protocol::Json::object(),
513 template <
class T,
class Parser>
518 request.params = std::move(params);
519 request.id = next_request_id();
520 if (options.meta.has_value()) {
521 request.meta = std::move(options.meta);
523 request.transport_headers = std::move(options.headers);
524 request.protocol_version_override = std::move(options.protocol_version);
526 const auto request_id =
request.id;
527 ++in_flight_requests_;
528 auto in_flight_mutex = &in_flight_mutex_;
529 auto in_flight_cv = in_flight_cv_;
530 auto in_flight_count = &in_flight_requests_;
532 request_id, options.timeout, options.cancellation_token,
533 [
this, request_id](std::string reason)
mutable {
534 return notify_cancelled(std::move(request_id), std::move(reason));
537 in_flight_mutex, in_flight_cv,
539 auto payload = raw_request(request);
540 core::Result<T> result;
542 result = mcp::core::unexpected(payload.error());
544 result = parser(*payload);
547 std::lock_guard lock(*in_flight_mutex);
548 --(*in_flight_count);
549 in_flight_cv->notify_one();
578 std::string_view name,
592 std::string_view name,
712 Client& on_list_roots_request(RootsListRequestCancellationHandler handler);
716 Client& on_create_message_request(SamplingRequestCancellationHandler handler);
720 CreateElicitationRequestHandler handler);
721 Client& on_create_elicitation_request(
722 ElicitationRequestCancellationHandler handler);
727 Client& on_custom_request(CustomRequestCancellationHandler handler);
731 Client& on_roots_list_request(RootsListRequestCancellationHandler handler);
735 Client& on_sampling_request(SamplingRequestCancellationHandler handler);
739 Client& on_elicitation_request(ElicitationRequestCancellationHandler handler);
788 template <typename Handler>
789 Handler copy_handler(Handler
Client::* slot)
const {
790 std::lock_guard<std::mutex> lock(*handlers_mutex_);
794 template <
typename Handler>
795 void store_handler(Handler
Client::* slot, Handler handler) {
796 std::lock_guard<std::mutex> lock(*handlers_mutex_);
797 this->*slot = std::move(handler);
807 bool server_capabilities_known() const noexcept;
808 bool supports_server_completion() const noexcept;
809 bool supports_server_logging() const noexcept;
810 bool supports_server_resource_subscribe() const noexcept;
811 bool supports_server_task_list() const noexcept;
812 bool supports_server_task_cancel() const noexcept;
813 bool supports_server_tasks() const noexcept;
814 bool supports_server_task_tool_call() const noexcept;
815 std::optional<protocol::ClientCapabilities> capabilities_snapshot() const;
816 std::optional<protocol::ServerCapabilities> server_capabilities_snapshot()
819 const protocol::RequestId& request_id);
820 void end_request_cancellation(const protocol::RequestId& request_id) noexcept;
821 void cancel_request(const protocol::RequestId& request_id) noexcept;
822 std::int64_t next_request_id() noexcept {
823 return next_request_id_.fetch_add(1, std::memory_order_relaxed);
826 std::unique_ptr<Transport> transport_;
827 std::atomic<std::int64_t> next_request_id_{1};
828 bool transport_started_ =
false;
829 std::vector<protocol::Root> roots_;
830 std::optional<protocol::Json> last_initialize_params_;
831 std::optional<protocol::ClientCapabilities> capabilities_;
832 std::optional<protocol::ServerCapabilities> server_capabilities_;
833 InitializedHandler initialized_handler_;
834 CancelledHandler cancelled_handler_;
835 LoggingMessageHandler logging_message_handler_;
836 ListChangedHandler tool_list_changed_handler_;
837 ListChangedHandler prompt_list_changed_handler_;
838 ListChangedHandler resource_list_changed_handler_;
839 ResourceUpdatedHandler resource_updated_handler_;
840 ProgressHandler progress_handler_;
841 ElicitationCompleteHandler elicitation_complete_handler_;
842 TaskStatusHandler task_status_handler_;
843 ListChangedHandler roots_list_changed_handler_;
844 RootsListRequestHandler roots_list_request_handler_;
845 RootsListRequestCancellationHandler roots_list_request_cancellation_handler_;
846 SamplingRequestHandler sampling_request_handler_;
847 SamplingRequestCancellationHandler sampling_request_cancellation_handler_;
848 ElicitationRequestHandler elicitation_request_handler_;
849 ElicitationRequestCancellationHandler
850 elicitation_request_cancellation_handler_;
851 CustomRequestHandler custom_request_handler_;
852 CustomRequestCancellationHandler custom_request_cancellation_handler_;
853 RawNotificationHandler raw_notification_handler_;
854 mutable std::shared_ptr<std::mutex> state_mutex_ =
855 std::make_shared<std::mutex>();
856 mutable std::shared_ptr<std::mutex> handlers_mutex_ =
857 std::make_shared<std::mutex>();
858 std::shared_ptr<std::mutex> active_request_cancellations_mutex_ =
859 std::make_shared<std::mutex>();
860 std::shared_ptr<std::unordered_map<std::string, CancellationSource>>
861 active_request_cancellations_ = std::make_shared<
862 std::unordered_map<std::string, CancellationSource>>();
864 std::atomic<int> in_flight_requests_{0};
865 mutable std::mutex in_flight_mutex_;
866 std::shared_ptr<std::condition_variable> in_flight_cv_ =
867 std::make_shared<std::condition_variable>();
MCP client and server capability declarations.
Copyable token observed by cancellation-aware SDK operations.
Definition cancellation.hpp:104
Definition request.hpp:123
High-level MCP client compatibility API.
Definition client.hpp:132
Client & on_task_status(TaskStatusHandler handler)
Registers a callback for task status notifications.
core::Result< std::vector< protocol::ToolDefinition > > list_tools()
Lists one page of tool definitions advertised by the server.
core::Result< core::Unit > unsubscribe(std::string_view uri)
Unsubscribes from resource update notifications for a URI.
Client & on_logging_message(LoggingMessageHandler handler)
Registers a callback for logging message notifications.
core::Result< protocol::Json > raw_request(const protocol::JsonRpcRequest &request)
Sends a raw JSON-RPC request and returns the raw result JSON.
Client & on_list_roots_request(ListRootsRequestHandler handler)
Registers a handler for server list-roots requests.
RequestHandle< protocol::ToolResult > call_tool_async(std::string_view name, const protocol::Json &arguments=protocol::Json::object(), RequestOptions options={})
Asynchronously calls a tool by name.
core::Result< std::vector< protocol::Resource > > list_all_resources()
Lists all resources, following pagination cursors until exhausted.
core::Result< protocol::PromptsListResult > list_prompts_page(const protocol::PaginatedRequestParams ¶ms={})
Lists one typed page of prompts, preserving pagination metadata.
RequestHandle< std::vector< protocol::Prompt > > list_prompts_async(RequestOptions options={})
Asynchronously lists prompts and parses the typed response.
core::Result< protocol::Task > get_task(std::string_view task_id)
Gets a task by task identifier.
core::Result< protocol::PromptsGetResult > get_prompt(const protocol::PromptsGetParams ¶ms)
Gets a prompt by protocol parameter object.
std::function< void(std::string_view, std::string_view)> LoggingMessageHandler
Receives logging messages from the server.
Definition client.hpp:184
core::Result< std::vector< protocol::ToolDefinition > > list_all_tools()
Lists all tool definitions, following pagination cursors until exhausted.
RequestHandle< T > request_async(std::string method, protocol::Json params, Parser parser, RequestOptions options={})
Sends a cancellable typed request and parses its result payload.
Definition client.hpp:514
std::function< void(const protocol::ProgressNotificationParams &)> ProgressHandler
Receives progress notifications associated with a progress token.
Definition client.hpp:205
core::Result< core::Unit > subscribe(std::string_view uri)
Subscribes to resource update notifications for a URI.
Client & on_initialized(InitializedHandler handler)
Registers a callback for initialized notifications.
std::optional< protocol::ServerCapabilities > server_capabilities() const
Returns server capabilities learned from initialize(), if known.
core::Result< protocol::Json > initialize(std::string client_name="cxxmcp", std::string client_version="0")
Sends the MCP initialize request.
core::Result< core::Unit > notify_roots_list_changed()
Notifies the server that the client's roots list changed.
core::Result< core::Unit > notify(const protocol::JsonRpcNotification ¬ification)
Sends a raw JSON-RPC notification.
core::Result< protocol::CreateElicitationResult > create_elicitation(const protocol::CreateElicitationRequestParam &request)
Sends an elicitation request using typed protocol parameters.
core::Result< core::Unit > notify_progress(protocol::ProgressToken progress_token, double progress, std::optional< double > total=std::nullopt, std::string message={})
Sends a progress notification.
std::function< void(const std::string &)> ResourceUpdatedHandler
Receives resource update notifications.
Definition client.hpp:201
core::Result< protocol::Json > create_elicitation(const protocol::Json &request)
Sends an elicitation request using raw JSON parameters.
core::Result< core::Unit > ping()
Sends an MCP ping request.
Client & on_roots_list_request(RootsListRequestHandler handler)
Compatibility alias for on_list_roots_request().
std::function< core::Result< protocol::RootsListResult >()> RootsListRequestHandler
Handles a server request for the client's current roots.
Definition client.hpp:217
core::Result< std::vector< protocol::Prompt > > list_all_prompts()
Lists all prompts, following pagination cursors until exhausted.
Client & on_cancelled(CancelledHandler handler)
Registers a callback for cancellation notifications.
Client & on_prompt_list_changed(ListChangedHandler handler)
Registers a callback for prompt list change notifications.
Client & on_elicitation_complete(ElicitationCompleteHandler handler)
Registers a callback for elicitation completion notifications.
Client & on_create_elicitation_request(CreateElicitationRequestHandler handler)
Registers a handler for server elicitation requests.
RequestHandle< protocol::Json > task_result_async(const protocol::TaskResultParams &request, RequestOptions options={})
Asynchronously gets a task result using typed protocol parameters.
Client & set_roots(std::vector< protocol::Root > roots)
Replaces the roots advertised by this client.
Client & on_elicitation_request(ElicitationRequestHandler handler)
Compatibility alias for on_create_elicitation_request().
RequestHandle< protocol::Task > cancel_task_async(std::string_view task_id, RequestOptions options={})
Asynchronously cancels a task by identifier.
core::Result< protocol::Json > complete(const protocol::Json &request)
Requests completion using raw JSON parameters.
Client & on_sampling_request(SamplingRequestHandler handler)
Compatibility alias for on_create_message_request().
RequestHandle< protocol::ToolResult > call_tool_async(const protocol::ToolCall &call, RequestOptions options={})
Asynchronously calls a tool and parses the typed response.
core::Result< std::vector< protocol::Task > > list_all_tasks()
Lists all tasks, following pagination cursors until exhausted.
core::Result< std::vector< std::string > > complete_resource_simple(std::string_view uri_template, std::string_view argument_name, std::string current_value, protocol::Json context=protocol::Json::object())
Returns resource completion values only.
Client(std::unique_ptr< Transport > transport)
Constructs a client from a custom transport.
core::Result< core::Unit > start()
Starts the underlying transport receive side if the transport needs explicit startup.
RequestHandle< protocol::Task > cancel_task_async(const protocol::TaskCancelParams &request, RequestOptions options={})
Asynchronously cancels a task using typed protocol parameters.
core::Result< protocol::CompleteResult > complete(const protocol::CompleteParams &request)
Requests completion using typed protocol parameters.
RequestHandle< std::vector< protocol::Resource > > list_resources_async(RequestOptions options={})
Asynchronously lists resources and parses the typed response.
void stop() noexcept
Stops the underlying transport and clears receive-side state.
core::Result< protocol::Json > request(const protocol::JsonRpcRequest &request)
Sends a raw JSON-RPC request and returns its result JSON.
core::Result< core::Unit > notify_initialized()
Sends the initialized notification after a successful initialize exchange.
core::Result< protocol::Task > get_task(const protocol::TaskGetParams &request)
Gets a task using typed protocol parameters.
RequestHandle< std::vector< protocol::ToolDefinition > > list_tools_async(RequestOptions options={})
Asynchronously lists tools and parses the typed response.
RequestHandle< protocol::Json > create_message_async(const protocol::Json &request, RequestOptions options={})
Asynchronously sends a raw sampling request.
Client & on_progress(ProgressHandler handler)
Registers a callback for progress notifications.
core::Result< protocol::ToolResult > call_raw(std::string_view name, const protocol::Json &arguments=protocol::Json::object())
Calls a tool by name with optional JSON arguments.
static Client connect_stdio(StdioEndpoint endpoint)
Creates a client connected to a child process over stdio.
core::Result< protocol::PromptsGetResult > get_prompt(std::string_view name, const protocol::Json &arguments=protocol::Json::object())
Gets a prompt by name and optional JSON arguments.
core::Result< protocol::ResourcesReadResult > read_resource(std::string_view uri)
Reads a resource by URI.
core::Result< std::vector< protocol::ResourceTemplate > > list_resource_templates()
Lists one page of resource templates advertised by the server.
core::Result< protocol::Task > cancel_task(std::string_view task_id)
Cancels a task by task identifier.
std::function< void(const protocol::RequestId &, std::string_view)> CancelledHandler
Receives cancellation notifications for in-flight requests.
Definition client.hpp:193
std::function< core::Result< protocol::Json >(const protocol::JsonRpcRequest &)> CustomRequestHandler
Handles non-built-in server requests.
Definition client.hpp:245
core::Result< std::vector< std::string > > complete_prompt_simple(std::string_view prompt_name, std::string_view argument_name, std::string current_value, protocol::Json context=protocol::Json::object())
Returns prompt completion values only.
core::Result< protocol::Json > initialize(std::string client_name, std::string client_version, RequestOptions options)
Sends the MCP initialize request with per-request options.
RequestHandle< protocol::PromptsGetResult > get_prompt_async(const protocol::PromptsGetParams ¶ms, RequestOptions options={})
Asynchronously gets a prompt and parses the typed response.
Client & set_capabilities(protocol::ClientCapabilities capabilities)
Sets client capabilities used during initialization.
RequestHandle< protocol::Json > request_async(std::string method, protocol::Json params=protocol::Json::object(), RequestOptions options={})
Sends a cancellable raw request with an auto-generated id.
core::Result< protocol::CreateMessageResult > create_message(const protocol::CreateMessageParams &request)
Sends a sampling createMessage request using typed protocol parameters.
Client & on_resource_updated(ResourceUpdatedHandler handler)
Registers a callback for resource update notifications.
Client & on_create_message_request(CreateMessageRequestHandler handler)
Registers a handler for server sampling createMessage requests.
core::Result< protocol::CompletionResult > complete_resource_argument(std::string_view uri_template, std::string_view argument_name, std::string current_value, protocol::Json context=protocol::Json::object())
Completes a resource template argument using RMCP-style helper parameters.
Client & on_custom_request(CustomRequestHandler handler)
Registers a handler for custom server requests not handled by the built-in client dispatcher.
core::Result< protocol::CompletionResult > complete_prompt_argument(std::string_view prompt_name, std::string_view argument_name, std::string current_value, protocol::Json context=protocol::Json::object())
Completes a prompt argument using RMCP-style helper parameters.
RequestHandle< protocol::ResourcesReadResult > read_resource_async(const protocol::ResourcesReadParams ¶ms, RequestOptions options={})
Asynchronously reads a resource and parses the typed response.
std::vector< protocol::Root > list_roots() const
Returns the roots currently advertised by this client.
core::Result< core::Unit > set_level(std::string_view level)
Sets the server logging level by level name.
RequestHandle< protocol::Json > task_result_async(std::string_view task_id, RequestOptions options={})
Asynchronously gets a task result by identifier.
core::Result< protocol::ResourceTemplatesListResult > list_resource_templates_page(const protocol::PaginatedRequestParams ¶ms={})
Lists one typed page of resource templates.
std::function< core::Result< protocol::CreateMessageResult >(const protocol::CreateMessageParams &)> SamplingRequestHandler
Handles a server sampling request.
Definition client.hpp:226
RequestHandle< protocol::CreateTaskResult > call_tool_task_async(const protocol::ToolCall &call, RequestOptions options={})
Asynchronously starts a task-aware tool call.
std::function< void(std::string_view)> ElicitationCompleteHandler
Receives completion notifications for elicitation flows.
Definition client.hpp:209
Client & on_tool_list_changed(ListChangedHandler handler)
Registers a callback for tool list change notifications.
RequestHandle< protocol::PromptsGetResult > get_prompt_async(std::string_view name, const protocol::Json &arguments=protocol::Json::object(), RequestOptions options={})
Asynchronously gets a prompt by name.
RequestHandle< protocol::ResourcesReadResult > read_resource_async(std::string_view uri, RequestOptions options={})
Asynchronously reads a resource by URI.
core::Result< core::Unit > handle_notification(const protocol::JsonRpcNotification ¬ification)
Dispatches an inbound notification through built-in and registered handlers.
core::Result< protocol::ResourcesListResult > list_resources_page(const protocol::PaginatedRequestParams ¶ms={})
Lists one typed page of resources, preserving pagination metadata.
RequestHandle< protocol::CreateElicitationResult > create_elicitation_async(const protocol::CreateElicitationRequestParam &request, RequestOptions options={})
Asynchronously creates an elicitation request.
RequestHandle< protocol::Json > create_elicitation_async(const protocol::Json &request, RequestOptions options={})
Asynchronously sends a raw elicitation request.
std::function< void()> ListChangedHandler
Receives list-change notifications for prompts, resources, tools, or roots.
Definition client.hpp:197
core::Result< std::vector< protocol::Task > > list_tasks()
Lists one page of tasks advertised by the server.
core::Result< protocol::CreateTaskResult > call_tool_task(const protocol::ToolCall &call)
Calls a task-aware tool and returns the created task handle.
core::Result< protocol::ResourcesReadResult > read_resource(const protocol::ResourcesReadParams ¶ms)
Reads a resource by protocol parameter object.
RequestHandle< protocol::Task > get_task_async(const protocol::TaskGetParams &request, RequestOptions options={})
Asynchronously gets a task using typed protocol parameters.
core::Result< protocol::Json > task_result(const protocol::TaskResultParams &request)
Gets a task result using typed protocol parameters.
core::Result< std::vector< protocol::Resource > > list_resources()
Lists one page of resources advertised by the server.
RequestHandle< std::vector< protocol::Task > > list_tasks_async(RequestOptions options={})
Asynchronously lists tasks and parses the typed response.
core::Result< protocol::ToolsListResult > list_tools_page(const protocol::PaginatedRequestParams ¶ms={})
Lists one typed page of tool definitions.
RequestHandle< protocol::CreateMessageResult > create_message_async(const protocol::CreateMessageParams &request, RequestOptions options={})
Asynchronously creates a sampling message.
Client & on_custom_notification(RawNotificationHandler handler)
Compatibility alias for on_raw_notification().
std::function< void()> InitializedHandler
Receives notifications that the peer completed initialization.
Definition client.hpp:187
core::Result< core::Unit > raw_notification(const protocol::JsonRpcNotification ¬ification)
Sends a raw JSON-RPC notification.
std::function< void(const protocol::JsonRpcNotification &)> RawNotificationHandler
Observes every inbound notification after built-in dispatch.
Definition client.hpp:255
std::function< core::Result< protocol::CreateElicitationResult >(const protocol::CreateElicitationRequestParam &)> ElicitationRequestHandler
Handles a server elicitation request.
Definition client.hpp:236
core::Result< protocol::ToolResult > call_tool(const protocol::ToolCall &call)
Calls a tool using a protocol ToolCall object.
core::Result< core::Unit > notify_cancelled(protocol::RequestId request_id, std::string reason={})
Sends a cancellation notification for a request.
RequestHandle< protocol::Json > complete_async(const protocol::Json &request, RequestOptions options={})
Asynchronously sends a raw completion request.
Client & on_roots_list_changed(ListChangedHandler handler)
Registers a callback for roots list change notifications.
RequestHandle< protocol::CompleteResult > complete_async(const protocol::CompleteParams &request, RequestOptions options={})
Asynchronously completes a prompt/resource argument.
core::Result< protocol::Task > cancel_task(const protocol::TaskCancelParams &request)
Cancels a task using typed protocol parameters.
RequestHandle< protocol::Task > get_task_async(std::string_view task_id, RequestOptions options={})
Asynchronously gets a task by identifier.
core::Result< protocol::Json > create_message(const protocol::Json &request)
Sends a sampling createMessage request using raw JSON parameters.
Client & on_resource_list_changed(ListChangedHandler handler)
Registers a callback for resource list change notifications.
std::function< void(const protocol::Task &)> TaskStatusHandler
Receives task status notifications.
Definition client.hpp:212
core::Result< protocol::JsonRpcResponse > handle_request(const protocol::JsonRpcRequest &request)
Dispatches an inbound server request through built-in and custom handlers.
core::Result< protocol::TaskListResult > list_tasks_page(const protocol::TaskListParams &request={})
Lists one typed task page, preserving pagination metadata.
RequestHandle< std::vector< protocol::ResourceTemplate > > list_resource_templates_async(RequestOptions options={})
Asynchronously lists resource templates and parses the typed response.
core::Result< core::Unit > set_level(const protocol::LoggingSetLevelParams ¶ms)
Sets the server logging level using typed protocol parameters.
core::Result< std::vector< protocol::ResourceTemplate > > list_all_resource_templates()
Lists all resource templates, following pagination cursors until exhausted.
core::Result< std::vector< protocol::Prompt > > list_prompts()
Lists one page of prompts advertised by the server.
Client & on_raw_notification(RawNotificationHandler handler)
Registers an observer for raw inbound notifications.
core::Result< protocol::Json > task_result(std::string_view task_id)
Gets a task result by task identifier.
Abstract client transport used by Client to exchange JSON-RPC messages.
Definition client.hpp:83
virtual core::Result< core::Unit > start(TransportRequestHandler request_handler, TransportNotificationHandler notification_handler={})
Starts receiving inbound messages for transports that need an active loop.
Definition client.hpp:108
virtual core::Result< core::Unit > send_notification(const protocol::JsonRpcNotification ¬ification)
Sends a JSON-RPC notification without waiting for a response.
virtual core::Result< protocol::JsonRpcResponse > send(const protocol::JsonRpcRequest &request)=0
Sends a JSON-RPC request and waits for the corresponding response.
virtual void stop() noexcept
Requests transport shutdown.
Definition client.hpp:120
std::function< core::Result< core::Unit >(const protocol::JsonRpcNotification &)> TransportNotificationHandler
Handles JSON-RPC notifications sent by the server to this client.
Definition client.hpp:75
std::function< core::Result< protocol::JsonRpcResponse >(const protocol::JsonRpcRequest &)> TransportRequestHandler
Handles JSON-RPC requests sent by the server to this client.
Definition client.hpp:68
Aggregate callback configuration for mcp::client::Client.
Completion request and result payloads.
Elicitation request, result, and schema payloads.
Logging level and notification payloads.
Prompt discovery and rendering payloads.
Shared JSON, JSON-RPC, error, cancellation, and progress model types.
std::variant< std::int64_t, std::string > ProgressToken
Identifier used to associate progress notifications with a request.
Definition types.hpp:215
nlohmann::json Json
JSON value type used by all protocol DTOs.
Definition types.hpp:28
std::variant< std::int64_t, std::string > RequestId
JSON-RPC request or response identifier.
Definition types.hpp:56
Request lifecycle helpers for cancellable SDK calls.
Resource listing, template, subscription, and read payloads.
Shared result and error primitives used by the public cxxmcp SDK.
std::monostate Unit
Success value for operations that only need to report failure.
Definition result.hpp:55
tl::expected< T, Error > Result
Alias for the SDK result type.
Definition result.hpp:64
Client root discovery payloads.
Client-side model sampling request and response payloads.
JSON-RPC method names and message construction/parsing helpers.
Options for an outbound SDK request.
Definition request.hpp:103
Contract-style client handler interface.
Definition handler.hpp:27
Optional callback bundle for configuring a Client in one call.
Definition handler.hpp:106
Basic options for endpoint-oriented client construction.
Definition client.hpp:49
std::chrono::milliseconds timeout
Per-operation timeout used by transports that support request deadlines.
Definition client.hpp:54
std::string endpoint
Remote endpoint URI or implementation-defined endpoint string.
Definition client.hpp:51
Endpoint options for launching a child process over stdio.
Definition client.hpp:167
std::unordered_map< std::string, std::string > env
Extra environment variables for the child process.
Definition client.hpp:175
std::string cwd
Optional working directory for the child process.
Definition client.hpp:173
std::vector< std::string > args
Command-line arguments passed to the executable.
Definition client.hpp:171
std::string command
Executable to launch.
Definition client.hpp:169
Capabilities advertised by an MCP client during initialization.
Definition capabilities.hpp:296
Parameters for completion/complete.
Definition completion.hpp:98
Parameters for elicitation/create.
Definition elicitation.hpp:335
Parameters for sampling/createMessage.
Definition sampling.hpp:231
JSON-RPC notification envelope for one-way MCP messages.
Definition types.hpp:137
JSON-RPC request envelope carrying an MCP method invocation.
Definition types.hpp:99
std::string method
JSON-RPC method name such as tools/call or initialize.
Definition types.hpp:101
Parameters for logging/setLevel.
Definition logging.hpp:42
Shared pagination params for MCP list requests that use cursor.
Definition types.hpp:43
Parameters for notifications/progress.
Definition types.hpp:226
Parameters for prompts/get.
Definition prompt.hpp:181
Parameters for resources/read.
Definition resource.hpp:227
One client root entry.
Definition roots.hpp:24
Parameters for tasks/cancel.
Definition task.hpp:234
Parameters for tasks/get.
Definition task.hpp:209
Parameters for tasks/list.
Definition task.hpp:187
Snapshot of an asynchronous task.
Definition task.hpp:144