Asynchronous MCP client: handshake, list/call/read/subscribe, cancellation, progress, sampling, roots, elicitation.
More...
|
| void | cmcp_tool_result_clear (cmcp_tool_result_t *r) |
| |
| cmcp_client_t * | cmcp_client_new (const char *name, const char *version) |
| |
| void | cmcp_client_free (cmcp_client_t *c) |
| |
| void | cmcp_client_set_capabilities (cmcp_client_t *c, const cmcp_client_capabilities_t *caps) |
| |
| int | cmcp_client_set_description (cmcp_client_t *c, const char *description) |
| |
| void | cmcp_client_set_notification_handler (cmcp_client_t *c, cmcp_notification_fn fn, void *userdata) |
| |
| int | cmcp_client_handshake (cmcp_client_t *c, cmcp_transport_t *t) |
| |
| int | cmcp_client_connect_stdio (cmcp_client_t *c, const char *path, char *const argv[], char *const envp[]) |
| |
| int | cmcp_client_call_async (cmcp_client_t *c, const char *method, cmcp_json_t *params, long long *out_id) |
| |
| int | cmcp_client_wait (cmcp_client_t *c, long long id, cmcp_rpc_message_t *out_response) |
| |
| int | cmcp_client_request (cmcp_client_t *c, const char *method, cmcp_json_t *params, cmcp_rpc_message_t *out_response) |
| |
| int | cmcp_client_notify (cmcp_client_t *c, const char *method, cmcp_json_t *params) |
| |
| int | cmcp_client_cancel (cmcp_client_t *c, long long id, const char *reason) |
| |
| int | cmcp_client_call_async_progress (cmcp_client_t *c, const char *method, cmcp_json_t *params, cmcp_progress_fn fn, void *userdata, long long *out_id) |
| |
| int | cmcp_client_tools_list (cmcp_client_t *c, cmcp_session_tool_t **out_tools, size_t *out_n) |
| |
| int | cmcp_client_resources_list (cmcp_client_t *c, cmcp_session_resource_t **out_resources, size_t *out_n) |
| |
| int | cmcp_client_prompts_list (cmcp_client_t *c, cmcp_session_prompt_t **out_prompts, size_t *out_n) |
| |
| int | cmcp_client_resource_read (cmcp_client_t *c, const char *uri, char **out_text, size_t *out_n) |
| |
| int | cmcp_client_prompt_get (cmcp_client_t *c, const char *name, cmcp_json_t *args, cmcp_json_t **out_messages) |
| |
| cmcp_tool_result_t | cmcp_client_tool_call (cmcp_client_t *c, const char *name, cmcp_json_t *args) |
| |
| cmcp_tool_handle_t | cmcp_client_tool_call_async (cmcp_client_t *c, const char *name, cmcp_json_t *args) |
| |
| cmcp_tool_result_t | cmcp_client_tool_wait (cmcp_tool_handle_t h) |
| |
| int | cmcp_client_tool_call_text (cmcp_client_t *c, const char *name, cmcp_json_t *args, char **out_text, cmcp_rpc_error_t **out_rpc_err) |
| |
| void | cmcp_client_set_sampling_handler (cmcp_client_t *c, cmcp_sampling_handler_fn fn, void *userdata) |
| |
| cmcp_json_t * | cmcp_sampling_text_result (const char *text, const char *model, const char *stop_reason) |
| |
| void | cmcp_client_set_elicitation_handler (cmcp_client_t *c, cmcp_elicitation_handler_fn fn, void *userdata) |
| |
| cmcp_json_t * | cmcp_elicitation_result (const char *action, cmcp_json_t *content) |
| |
| int | cmcp_client_set_roots (cmcp_client_t *c, const cmcp_root_t *roots, size_t n) |
| |
| int | cmcp_client_notify_roots_changed (cmcp_client_t *c) |
| |
| int | cmcp_client_set_log_level (cmcp_client_t *c, cmcp_log_level_t level) |
| |
| const cmcp_server_capabilities_t * | cmcp_client_server_caps (const cmcp_client_t *c) |
| |
| const char * | cmcp_client_server_name (const cmcp_client_t *c) |
| |
| const char * | cmcp_client_server_version (const cmcp_client_t *c) |
| |
| const char * | cmcp_client_server_description (const cmcp_client_t *c) |
| |
| const char * | cmcp_client_server_protocol (const cmcp_client_t *c) |
| |
Asynchronous MCP client: handshake, list/call/read/subscribe, cancellation, progress, sampling, roots, elicitation.
The client owns a transport and a reader thread that demultiplexes responses by id against an in-flight table. Every call is async at the wire level — cmcp_client_call_async returns immediately with a handle, and cmcp_client_wait blocks for completion; many calls can be in flight concurrently and they complete in any order. cmcp_client_request is sync sugar over the async pair.
Client-side handlers (notification routing, sampling, elicitation) run on the reader thread; from inside one, non-blocking calls are fine but the blocking pair (request/wait) deadlocks — see the "Thread-safety contract" section below for the full rules. cmcp_client_set_roots advertises filesystem scope to the server; cmcp_client_cancel issues a notifications/cancelled for an in-flight call.
For multi-server agents see cmcp_session.h, which aggregates several already-handshaken clients under a single primitive surface.
Definition in file cmcp_client.h.