mcp: unify error reporting and use named error codes

This commit is contained in:
Adrià Arrufat
2026-03-01 21:29:59 +09:00
parent e6cc3e8c34
commit 8cbc58d257
5 changed files with 55 additions and 91 deletions

View File

@@ -20,6 +20,14 @@ pub const Error = struct {
data: ?std.json.Value = null,
};
pub const ErrorCode = enum(i64) {
ParseError = -32700,
InvalidRequest = -32600,
MethodNotFound = -32601,
InvalidParams = -32602,
InternalError = -32603,
};
pub const Notification = struct {
jsonrpc: []const u8 = "2.0",
method: []const u8,
@@ -185,7 +193,7 @@ test "protocol error formatting" {
const response = Response{
.id = .{ .string = "abc" },
.@"error" = .{
.code = -32601,
.code = @intFromEnum(ErrorCode.MethodNotFound),
.message = "Method not found",
},
};