19namespace mcp::errors {
21inline core::Error make(protocol::ErrorCode code, std::string message,
22 std::string detail = {}, std::string category = {}) {
23 return core::Error{
static_cast<int>(code), std::move(message),
24 std::move(detail), std::move(category)};
27inline core::Error parse(std::string detail = {}) {
28 return make(protocol::ErrorCode::ParseError,
"parse error", std::move(detail),
32inline core::Error invalid_request(std::string detail = {}) {
33 return make(protocol::ErrorCode::InvalidRequest,
"invalid request",
34 std::move(detail),
"protocol");
37inline core::Error invalid_params(std::string detail = {}) {
38 return make(protocol::ErrorCode::InvalidParams,
"invalid params",
39 std::move(detail),
"protocol");
42inline core::Error method_not_found(std::string detail = {}) {
43 return make(protocol::ErrorCode::MethodNotFound,
"method not found",
44 std::move(detail),
"protocol");
47inline core::Error tool_not_found(std::string detail = {}) {
48 return make(protocol::ErrorCode::ToolNotFound,
"tool not found",
49 std::move(detail),
"tool");
52inline core::Error resource_not_found(std::string detail = {}) {
53 return make(protocol::ErrorCode::ResourceNotFound,
"resource not found",
54 std::move(detail),
"resource");
57inline core::Error permission_denied(std::string detail = {}) {
58 return make(protocol::ErrorCode::PermissionDenied,
"permission denied",
59 std::move(detail),
"permission");
62inline core::Error rate_limited(std::string detail = {}) {
63 return make(protocol::ErrorCode::RateLimited,
"rate limited",
64 std::move(detail),
"rate_limit");
67inline core::Error url_elicitation_required(std::string detail = {}) {
68 return make(protocol::ErrorCode::UrlElicitationRequired,
69 "url elicitation required", std::move(detail),
"elicitation");
72inline core::Error handler_failed(std::string detail = {}) {
73 return make(protocol::ErrorCode::InternalError,
"handler failed",
74 std::move(detail),
"handler");
77inline core::Error handler_unknown_exception() {
78 return make(protocol::ErrorCode::InternalError,
79 "handler threw an unknown exception", {},
"handler");
82inline core::Error transport_failed(std::string detail = {}) {
83 return make(protocol::ErrorCode::InternalError,
"transport failed",
84 std::move(detail),
"transport");
87inline core::Error transport_closed(std::string detail = {}) {
88 return make(protocol::ErrorCode::InternalError,
"transport closed",
89 std::move(detail),
"transport");
92inline core::Error transport_unexpected_response(std::string detail = {}) {
93 return make(protocol::ErrorCode::InternalError,
"unexpected response",
94 std::move(detail),
"transport");
97inline core::Error transport_duplicate_request(std::string detail = {}) {
98 return make(protocol::ErrorCode::InternalError,
"duplicate request id",
99 std::move(detail),
"transport");
102inline core::Error request_cancelled() {
103 return make(protocol::ErrorCode::InternalError,
"request cancelled", {},
107inline core::Error request_timed_out(std::chrono::milliseconds timeout) {
108 return make(protocol::ErrorCode::InternalError,
"request timed out",
109 std::to_string(timeout.count()) +
"ms",
"timeout");
112inline core::Error request_task_missing() {
113 return make(protocol::ErrorCode::InternalError,
114 "request task is not configured", {},
"request");
117inline core::Error request_state_missing() {
118 return make(protocol::ErrorCode::InternalError,
119 "request handle has no response state", {},
"request");
122inline core::Error request_worker_exception(std::string detail = {}) {
123 return make(protocol::ErrorCode::InternalError,
124 "request worker threw an exception", std::move(detail),
128inline core::Error request_worker_unknown_exception() {
129 return make(protocol::ErrorCode::InternalError,
130 "request worker threw an unknown exception", {},
"request");
133inline protocol::ErrorObject to_json_rpc_error(
const core::Error& error) {
134 protocol::ErrorObject object;
135 object.
code = error.code;
136 object.message = error.message;
137 if (!error.detail.empty()) {
138 object.data = error.detail;
Shared JSON, JSON-RPC, error, cancellation, and progress model types.
Shared result and error primitives used by the public cxxmcp SDK.
int code
Numeric JSON-RPC error code.
Definition types.hpp:91