mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 12:44:43 +00:00
mcp: unify error reporting and use named error codes
This commit is contained in:
@@ -64,28 +64,10 @@ fn handleMessage(server: *Server, arena: std.mem.Allocator, msg: []const u8) !vo
|
||||
} else if (std.mem.eql(u8, parsed.method, "tools/call")) {
|
||||
try tools.handleCall(server, arena, parsed);
|
||||
} else {
|
||||
try server.sendResponse(protocol.Response{
|
||||
.id = parsed.id.?,
|
||||
.@"error" = protocol.Error{
|
||||
.code = -32601,
|
||||
.message = "Method not found",
|
||||
},
|
||||
});
|
||||
try server.sendError(parsed.id.?, .MethodNotFound, "Method not found");
|
||||
}
|
||||
}
|
||||
|
||||
fn sendResponseGeneric(server: *Server, id: std.json.Value, result: anytype) !void {
|
||||
const GenericResponse = struct {
|
||||
jsonrpc: []const u8 = "2.0",
|
||||
id: std.json.Value,
|
||||
result: @TypeOf(result),
|
||||
};
|
||||
try server.sendResponse(GenericResponse{
|
||||
.id = id,
|
||||
.result = result,
|
||||
});
|
||||
}
|
||||
|
||||
fn handleInitialize(server: *Server, req: protocol.Request) !void {
|
||||
const result = protocol.InitializeResult{
|
||||
.protocolVersion = "2024-11-05",
|
||||
@@ -100,5 +82,5 @@ fn handleInitialize(server: *Server, req: protocol.Request) !void {
|
||||
},
|
||||
};
|
||||
|
||||
try sendResponseGeneric(server, req.id.?, result);
|
||||
try server.sendResult(req.id.?, result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user