cMCP 0.4.1
Model Context Protocol library in pure C11
Loading...
Searching...
No Matches
cmcp.h
Go to the documentation of this file.
1/**
2 * @file cmcp.h
3 * @brief Umbrella header: package + protocol version macros, library-
4 * wide error codes, and `cmcp_errstr`.
5 *
6 * Every cMCP source file should include this header. The error codes
7 * declared here are returned by every public function whose return
8 * type is `int` (or `cmcp_err_t`) — negative values are errors, zero
9 * is success. See `docs/SEMVER.md` for the policy that governs
10 * additions and removals in this enum.
11 */
12#ifndef CMCP_H
13#define CMCP_H
14
15/** Package version of this cMCP build (e.g. "0.8.0"). Independent of
16 * `CMCP_PROTOCOL_VERSION` — see docs/SEMVER.md. */
17#define CMCP_VERSION "0.10.0"
18
19/** MCP wire-protocol revision this cMCP build speaks (e.g.
20 * "2025-11-25"). Pinned per release; the handshake captures whatever
21 * the peer advertises and the host decides whether to continue. */
22#define CMCP_PROTOCOL_VERSION "2025-11-25"
23
24/**
25 * @brief Library-wide error codes. Negative on failure, zero on success.
26 *
27 * Every public cMCP function returning `int` returns one of these
28 * (negative) on failure. Additions go at the end of the enum (so
29 * existing numeric encodings stay stable across MINOR bumps); see
30 * `docs/SEMVER.md` for the policy.
31 */
32typedef enum {
33 CMCP_OK = 0, /**< Success. */
34 CMCP_EINVAL = -1, /**< Invalid argument from caller. */
35 CMCP_ENOMEM = -2, /**< Allocation failure. */
36 CMCP_EIO = -3, /**< I/O error on transport. */
37 CMCP_EPARSE = -4, /**< Malformed input (JSON or HTTP). */
38 CMCP_ETRANSPORT = -5, /**< Transport-layer failure. */
39 CMCP_EPROTOCOL = -6, /**< Peer violated the MCP spec. */
40 CMCP_ETIMEOUT = -7, /**< Operation timed out. */
41 CMCP_ECANCELLED = -8, /**< Operation cancelled (peer or host). */
42 CMCP_EUNSUPPORTED = -9, /**< Requested feature not implemented. */
43 CMCP_ESCHEMA = -10, /**< Tool input failed schema validation. */
44 CMCP_ENOTFOUND = -11, /**< Named primitive (tool/resource/prompt) not registered. */
45 CMCP_EHANDLER = -12, /**< Handler returned a non-success result. */
46 CMCP_EAGAIN = -13, /**< Capacity/rate cap reached; retry later. */
48
49/**
50 * @brief Return a human-readable label for a `cmcp_err_t` value.
51 *
52 * Unknown values map to "unknown". Returned pointer is to a static
53 * string — never NULL, never needs freeing.
54 *
55 * @param err A value of `cmcp_err_t` (or an `int` carrying one).
56 * @return Borrowed static string.
57 */
58const char *cmcp_errstr(int err);
59
60#endif
cmcp_err_t
Library-wide error codes.
Definition cmcp.h:32
@ CMCP_ESCHEMA
Tool input failed schema validation.
Definition cmcp.h:43
@ CMCP_EPARSE
Malformed input (JSON or HTTP).
Definition cmcp.h:37
@ CMCP_EIO
I/O error on transport.
Definition cmcp.h:36
@ CMCP_EUNSUPPORTED
Requested feature not implemented.
Definition cmcp.h:42
@ CMCP_ETRANSPORT
Transport-layer failure.
Definition cmcp.h:38
@ CMCP_EAGAIN
Capacity/rate cap reached; retry later.
Definition cmcp.h:46
@ CMCP_OK
Success.
Definition cmcp.h:33
@ CMCP_ENOTFOUND
Named primitive (tool/resource/prompt) not registered.
Definition cmcp.h:44
@ CMCP_EPROTOCOL
Peer violated the MCP spec.
Definition cmcp.h:39
@ CMCP_EINVAL
Invalid argument from caller.
Definition cmcp.h:34
@ CMCP_ECANCELLED
Operation cancelled (peer or host).
Definition cmcp.h:41
@ CMCP_ETIMEOUT
Operation timed out.
Definition cmcp.h:40
@ CMCP_ENOMEM
Allocation failure.
Definition cmcp.h:35
@ CMCP_EHANDLER
Handler returned a non-success result.
Definition cmcp.h:45
const char * cmcp_errstr(int err)
Return a human-readable label for a cmcp_err_t value.